Skip to content

Commit

Permalink
move integration tests into a reusable action to simplify testing the…
Browse files Browse the repository at this point in the history
…m, introduce setup-python to install python v2 in the runner.

add taskfile for testing github actions
  • Loading branch information
hahn-kev committed Jul 11, 2023
1 parent 0077534 commit 426ee7c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 45 deletions.
5 changes: 5 additions & 0 deletions .github/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 3
tasks:
integration-test:
cmds:
- act -j integration-test -r
30 changes: 30 additions & 0 deletions .github/actions/integration/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Run integration tests"

inputs:
hostname:
description: "Target host to run the integration tests against"
required: true

runs:
using: composite
steps:
# standard github setup python does not support version 2 anymore :(
- uses: MatteoH2O1999/setup-python@v1
with:
python-version: '2.x'
- name: Build dotnet
run: dotnet build
- name: Ensure browsers are installed
run: pwsh ./backend/Testing/bin/Debug/net7.0/playwright.ps1 install --with-deps
- name: Integration Test
env:
TEST_SERVER_HOSTNAME: ${{ inputs.hostname }}
TEST_STANDARD_HG_HOSTNAME: hg-${{ inputs.hostname }}
TEST_RESUMABLE_HG_HOSTNAME: resumable-${{ inputs.hostname }}
run: dotnet test --logger trx --results-directory ./testresults --filter "Category=Integration"
- name: Upload test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always() && !env.act
with:
check_name: Integration Test
files: ./testresults/*.trx
11 changes: 11 additions & 0 deletions .github/workflows/action-testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on:
workflow_call:

jobs:
integration-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/integration
with:
hostname: staging.languagedepot.org
17 changes: 2 additions & 15 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,7 @@ jobs:
echo "Version $versionHeader is still incorrect after waiting"
exit 1
- uses: actions/checkout@v3
- name: Build dotnet
run: dotnet build
- name: Ensure browsers are installed
run: pwsh ./backend/Testing/bin/Debug/net7.0/playwright.ps1 install --with-deps
- name: Integration Test
env:
TEST_SERVER_HOSTNAME: staging.languagedepot.org
TEST_STANDARD_HG_HOSTNAME: hg-staging.languagedepot.org
TEST_RESUMABLE_HG_HOSTNAME: resumable-staging.languagedepot.org
run: dotnet test --logger trx --results-directory ./testresults --filter "Category=Integration"
- name: Upload test results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
- uses: ./github/actions/integration
with:
check_name: Integration Test
files: ./testresults/*.trx
hostname: staging.languagedepot.org

2 changes: 2 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ includes:
k8s:
taskfile: ./deployment/Taskfile.yml
dir: ./deployment
gh:
taskfile: ./.github/Taskfile.yml

tasks:
setup:
Expand Down
8 changes: 6 additions & 2 deletions backend/Testing/Services/SendReceiveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ public async Task<string> GetHgVersion()
string output = "";
using (Process hg = new()) {
string hgFilename = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "hg.exe" : "hg";
hg.StartInfo.FileName = System.IO.Path.Join("Mercurial", hgFilename);
hg.StartInfo.FileName = Path.Join("Mercurial", hgFilename);
if (!File.Exists(hg.StartInfo.FileName))
{
throw new FileNotFoundException("unable to find HG executable", hg.StartInfo.FileName);
}
hg.StartInfo.Arguments = "version";
hg.StartInfo.RedirectStandardOutput = true;

hg.Start();
output = hg.StandardOutput.ReadToEnd();
output = await hg.StandardOutput.ReadToEndAsync();
await hg.WaitForExitAsync();
}
return output;
Expand Down
52 changes: 24 additions & 28 deletions backend/Testing/SyncReverseProxy/SendReceiveServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Chorus.VcsDrivers.Mercurial;
using Microsoft.Extensions.Hosting;
using Shouldly;
using SIL.Progress;
Expand All @@ -8,7 +9,7 @@
namespace Testing.SyncReverseProxy;

[Trait("Category", "Integration")]
public class SendReceiveServiceTests
public class SendReceiveServiceTests : IAsyncLifetime
{
private string _basePath = Path.Join(Path.GetTempPath(), "SendReceiveTests");
private IProgress _progress;
Expand All @@ -20,6 +21,16 @@ public SendReceiveServiceTests(ITestOutputHelper output)
CleanUpTempDir();
}

public async Task InitializeAsync()
{
await VerifyHgWorking();
}

public Task DisposeAsync()
{
return Task.CompletedTask;
}

private void CleanUpTempDir()
{
var dirInfo = new DirectoryInfo(_basePath);
Expand Down Expand Up @@ -84,49 +95,34 @@ public void CloneProjectAndSendReceive(SendReceiveTestData data)
string projectDir = Path.Join(_basePath, data.HostType, data.ProjectCode);
string fwdataFile = Path.Join(projectDir, $"{data.ProjectCode}.fwdata");
long oldLength = 0;
var fileInfo = new FileInfo(fwdataFile);
try
{
string result = srService.CloneProject(data.ProjectCode, projectDir, data.Username, data.Password);
if (data.ShouldPass)
{
result.ShouldNotContain("abort");
result.ShouldNotContain("error");
fileInfo.Directory?.Exists.ShouldBeTrue("directory " + fileInfo.DirectoryName + " not found. Clone response: " + result);
fileInfo.Directory!.EnumerateFiles().ShouldContain(child => child.Name == fileInfo.Name);
fwdataFile.ShouldSatisfyAllConditions(
() => new FileInfo(fwdataFile).Exists.ShouldBeTrue(),
() => new FileInfo(fwdataFile).Length.ShouldBeGreaterThan(0)
() => fileInfo.Exists.ShouldBeTrue(),
() => fileInfo.Length.ShouldBeGreaterThan(0)
);
oldLength = new FileInfo(fwdataFile).Length;
oldLength = fileInfo.Length;
}
else
{
result.ShouldMatch("abort: authorization failed|Server Response 'Unauthorized'");
}
}
catch (Chorus.VcsDrivers.Mercurial.RepositoryAuthorizationException)
catch (RepositoryAuthorizationException) when (!data.ShouldPass)
{
if (data.ShouldPass)
{
throw;
}
else
{
// This is a successful test, because the repo rejected the invalid password as it should
}

;
// This is a successful test, because the repo rejected the invalid password as it should
}
catch (System.UnauthorizedAccessException)
catch (UnauthorizedAccessException) when (!data.ShouldPass)
{
if (data.ShouldPass)
{
throw;
}
else
{
// This is a successful test, because the repo rejected the invalid password as it should
}

;
// This is a successful test, because the repo rejected the invalid password as it should
}

// Now do a Send/Receive which should get no changes
Expand All @@ -140,8 +136,8 @@ public void CloneProjectAndSendReceive(SendReceiveTestData data)
result2.ShouldNotContain("error");
result2.ShouldContain("no changes from others");
fwdataFile.ShouldSatisfyAllConditions(
() => new FileInfo(fwdataFile).Exists.ShouldBeTrue(),
() => new FileInfo(fwdataFile).Length.ShouldBe(oldLength)
() => fileInfo.Exists.ShouldBeTrue(),
() => fileInfo.Length.ShouldBe(oldLength)
);
}
else
Expand Down

0 comments on commit 426ee7c

Please sign in to comment.