Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests workflow #285

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/copilot-build-backend.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: copilot-build-backend

on:
workflow_dispatch:
glahaye marked this conversation as resolved.
Show resolved Hide resolved
pull_request:
branches: ["main"]
paths:
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/copilot-deploy-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ on:
required: true
AZURE_SUBSCRIPTION_ID:
required: true
outputs:
backend-host:
description: "Host to which backend is deployed"
value: ${{jobs.webapi.outputs.backend-host}}

permissions:
contents: read
Expand All @@ -33,13 +37,12 @@ jobs:
matrix:
include:
- { dotnet: "6.0", configuration: Release, os: ubuntu-latest }
# Map the job output to step output
outputs:
backend-host: ${{steps.app-name.outputs.backend-host}}

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
glahaye marked this conversation as resolved.
Show resolved Hide resolved
with:
clean: true

- uses: actions/download-artifact@v3
with:
name: ${{inputs.ARTIFACT_NAME}}
Expand All @@ -58,9 +61,11 @@ jobs:
enable-AzPSSession: false

- name: Get app name
id: app-name
run: |
WEB_APP_NAME=$(az deployment group show --name ${{inputs.DEPLOYMENT_NAME}} --resource-group ${{vars.CC_DEPLOYMENT_GROUP_NAME}} --output json | jq -r '.properties.outputs.webapiName.value')
echo "AZURE_WEBAPP_NAME=$WEB_APP_NAME" >> $GITHUB_ENV
echo "backend-host=$WEB_APP_NAME" >> $GITHUB_OUTPUT

- name: Enable Run From Package
uses: azure/CLI@v1
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/copilot-deploy-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ on:
required: true
AZURE_OPENAI_ENDPOINT:
required: true
outputs:
backend-host:
description: "Host on which backend runs"
value: ${{jobs.deploy-backend.outputs.backend-host}}

permissions:
contents: read
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/copilot-deploy-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ jobs:
AZURE_SUBSCRIPTION_ID: ${{secrets.AZURE_SUBSCRIPTION_ID}}
AZURE_OPENAI_ENDPOINT: ${{secrets.AZURE_OPENAI_ENDPOINT}}

int-tests:
uses: ./.github/workflows/copilot-run-integration-tests.yml
needs: int
with:
ENVIRONMENT: int
BACKEND_HOST: ${{needs.int.outputs.backend-host}}

stable:
uses: ./.github/workflows/copilot-deploy-environment.yml
needs: [build, int]
needs: int-tests
with:
ENVIRONMENT: stable
ARTIFACT_NAME: ${{needs.build.outputs.artifact}}
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/copilot-run-integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: copilot-run-integration-tests

on:
workflow_call:
inputs:
ENVIRONMENT:
required: true
type: string
BACKEND_HOST:
required: true
type: string

permissions:
contents: read

jobs:
tests:
environment: ${{inputs.ENVIRONMENT}}
name: Integration Testing
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- name: Run integration tests
run: dotnet test --environment BaseUrl="https://${{inputs.BACKEND_HOST}}.azurewebsites.net/" --logger trx
10 changes: 5 additions & 5 deletions integration-tests/ChatCopilotIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ChatCopilotIntegrationTests;
/// </summary>
public abstract class ChatCopilotIntegrationTest : IDisposable
{
protected const string BaseAddressSettingName = "BaseAddress";
glahaye marked this conversation as resolved.
Show resolved Hide resolved
protected const string BaseUrlSettingName = "BaseUrl";

protected readonly HttpClient _httpClient;

Expand All @@ -26,12 +26,12 @@ protected ChatCopilotIntegrationTest()
.AddUserSecrets<HealthzTests>()
.Build();

string? baseAddress = configuration[BaseAddressSettingName];
Assert.False(string.IsNullOrEmpty(baseAddress));
Assert.True(baseAddress.EndsWith('/'));
string? baseUrl = configuration[BaseUrlSettingName];
Assert.False(string.IsNullOrEmpty(baseUrl));
Assert.True(baseUrl.EndsWith('/'));

this._httpClient = new HttpClient();
this._httpClient.BaseAddress = new Uri(baseAddress);
this._httpClient.BaseAddress = new Uri(baseUrl);
}

public void Dispose()
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To set your secrets with Secret Manager:
cd integration-tests

dotnet user-secrets init
dotnet user-secrets set "BaseAddress" "https://your-backend-address/"
dotnet user-secrets set "BaseUrl" "https://your-backend-address/"
```

### Option 2: Use a Configuration File
Expand All @@ -35,7 +35,7 @@ For example:

```json
{
"BaseAddress": "https://localhost:40443/"
"BaseUrl": "https://localhost:40443/"
}
```

Expand All @@ -45,11 +45,11 @@ You may also set the test settings in your environment variables. The environmen
- bash:

```bash
export BaseAddress="https://localhost:40443/"
export BaseUrl="https://localhost:40443/"
```

- PowerShell:

```ps
$env:BaseAddress = "https://localhost:40443/"
$env:BaseUrl = "https://localhost:40443/"
```
2 changes: 1 addition & 1 deletion integration-tests/testsettings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"BaseAddress": "https://localhost:40443/"
"BaseUrl": "https://localhost:40443/"
}