Skip to content

Commit

Permalink
Increase test coverage (#234)
Browse files Browse the repository at this point in the history
* Adding missing integration test and new features to tests

* Fix mocking

* Add memory repository tests

* Add new tests to sln file

* More tests

* Export code coverage from what's visible in E2E tests (not perfect but still a gain)

* PlatformService tests

* Add 403s to translation integration tests

* Add 403sto webhooks tests

* Remove unused code
  • Loading branch information
Enkidu93 authored Dec 6, 2023
1 parent 7ea2794 commit 9168d5a
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 191 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ jobs:
run: sudo mkdir -p /var/lib/serval && sudo chmod 777 /var/lib/serval

- name: Test
run: dotnet test --no-build --verbosity normal --filter "TestCategory!=slow&TestCategory=E2E"
run: dotnet test --no-build --verbosity normal --filter "TestCategory!=slow&TestCategory=E2E" --collect:"Xplat Code Coverage"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Debug network (Post test)
if: ${{ failure() }}
Expand Down
18 changes: 12 additions & 6 deletions .github/workflows/missing-services-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ jobs:

#Mongo
- name: Test Working Mongo
run: dotnet test --no-build --verbosity normal --filter "TestCategory=MongoWorking"
run: dotnet test --no-build --verbosity normal --filter "TestCategory=MongoWorking" --collect:"Xplat Code Coverage"

- name: Kill Mongo
run: docker stop serval-mongo-1

- name: Test Not Working Mongo
run: dotnet test --no-build --verbosity normal --filter "TestCategory=MongoNotWorking"
run: dotnet test --no-build --verbosity normal --filter "TestCategory=MongoNotWorking" --collect:"Xplat Code Coverage"

- name: Restart Mongo
run: docker start serval-mongo-1 && sleep 20

#Engine Server
- name: Test Working Engine Server
run: dotnet test --no-build --verbosity normal --filter "TestCategory=EngineServerWorking"
run: dotnet test --no-build --verbosity normal --filter "TestCategory=EngineServerWorking" --collect:"Xplat Code Coverage"

- name: Kill Engine Server
run: docker stop machine-engine-cntr

- name: Test Not Working EngineServer
run: dotnet test --no-build --verbosity normal --filter "TestCategory=EngineServerNotWorking"
run: dotnet test --no-build --verbosity normal --filter "TestCategory=EngineServerNotWorking" --collect:"Xplat Code Coverage"

- name: Restart Engine Server
run: docker start machine-engine-cntr && sleep 5
Expand All @@ -81,7 +81,7 @@ jobs:
ClearML_SecretKey: "not_the_right_key"

- name: Test Not Working ClearML
run: dotnet test --no-build --verbosity normal --filter "TestCategory=ClearMLNotWorking"
run: dotnet test --no-build --verbosity normal --filter "TestCategory=ClearMLNotWorking" --collect:"Xplat Code Coverage"
env:
ClearML_SecretKey: "not_the_right_key"

Expand All @@ -92,10 +92,16 @@ jobs:
AWS_SECRET_ACCESS_KEY: "not_the_right_key"

- name: Test Not Working AWS
run: dotnet test --no-build --verbosity normal --filter "TestCategory=AWSNotWorking"
run: dotnet test --no-build --verbosity normal --filter "TestCategory=AWSNotWorking" --collect:"Xplat Code Coverage"
env:
AWS_SECRET_ACCESS_KEY: "not_the_right_key"

#Coverage export
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

#Clean up
- name: Debug network (Post test)
if: ${{ failure() }}
Expand Down
7 changes: 7 additions & 0 deletions Serval.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serval.E2ETests", "tests\Se
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serval.DataFiles.Tests", "tests\Serval.DataFiles.Tests\Serval.DataFiles.Tests.csproj", "{63E4D71B-11BE-4D68-A876-5B1B5F0A4C88}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SIL.DataAccess.Tests", "tests\SIL.DataAccess.Tests\SIL.DataAccess.Tests.csproj", "{71151518-8774-44D0-8E69-D77FA447BEFA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -114,6 +116,10 @@ Global
{63E4D71B-11BE-4D68-A876-5B1B5F0A4C88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63E4D71B-11BE-4D68-A876-5B1B5F0A4C88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63E4D71B-11BE-4D68-A876-5B1B5F0A4C88}.Release|Any CPU.Build.0 = Release|Any CPU
{71151518-8774-44D0-8E69-D77FA447BEFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71151518-8774-44D0-8E69-D77FA447BEFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71151518-8774-44D0-8E69-D77FA447BEFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71151518-8774-44D0-8E69-D77FA447BEFA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -133,6 +139,7 @@ Global
{0C3DF75B-B022-4EFC-882C-F276F1EC8435} = {66246A1C-8D45-40FB-A660-C58577122CA7}
{1F020042-D7B8-4541-9691-26ECFD1FFC73} = {66246A1C-8D45-40FB-A660-C58577122CA7}
{63E4D71B-11BE-4D68-A876-5B1B5F0A4C88} = {66246A1C-8D45-40FB-A660-C58577122CA7}
{71151518-8774-44D0-8E69-D77FA447BEFA} = {66246A1C-8D45-40FB-A660-C58577122CA7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F18C25E-E140-43C3-B177-D562E1628370}
Expand Down
160 changes: 0 additions & 160 deletions src/SIL.DataAccess/CustomEnumConverterFactory.cs

This file was deleted.

8 changes: 0 additions & 8 deletions src/Serval.Core/FileFormat.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/Serval.Core/Serval.Core.csproj

This file was deleted.

76 changes: 76 additions & 0 deletions tests/SIL.DataAccess.Tests/MemoryRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
namespace SIL.DataAccess;

[TestFixture]
public class MemoryRepositoryTests
{
[Test]
public async Task AddAndRemove()
{
var mr = new MemoryRepository<IntegerEntity>();
mr.Init();
mr.Add(new IntegerEntity(1) { Id = "1" });
var entityToRemove = new IntegerEntity(2) { Id = "2" };
mr.Add(entityToRemove);
mr.Remove(entityToRemove);
Assert.That((await mr.GetAllAsync(_ => true)).Count, Is.EqualTo(1));
IntegerEntity entity = mr.Get("1");
Assert.That(entity.Value, Is.EqualTo(1));
mr.Add(
new IntegerEntity[]
{
new IntegerEntity(1) { Id = "3" },
new IntegerEntity(2) { Id = "4" }
}
);
Assert.That((await mr.GetAllAsync(_ => true)).Count, Is.EqualTo(3));
Assert.That(await mr.ExistsAsync(entity => entity.Value == 2));
}

[Test]
public async Task InsertAndUpdate()
{
var mr = new MemoryRepository<IntegerEntity>();
mr.Init();
await mr.InsertAllAsync(
new IntegerEntity[]
{
new IntegerEntity(1) { Id = "1" },
new IntegerEntity(2) { Id = "2" }
}
);
Assert.ThrowsAsync<DuplicateKeyException>(async () =>
{
await mr.InsertAllAsync(
new IntegerEntity[]
{
new IntegerEntity(1) { Id = "1" },
new IntegerEntity(2) { Id = "2" }
}
);
});
Assert.That((await mr.GetAllAsync(_ => true)).Count, Is.EqualTo(2));
await mr.UpdateAsync(e => e.Id == "0", e => e.Set(r => r.Value, 0), upsert: true);
Assert.That((await mr.GetAllAsync(_ => true)).Count, Is.EqualTo(3));
await mr.UpdateAsync(e => e.Id == "0", e => e.Set(r => r.Value, 100));
Assert.That((await mr.GetAllAsync(_ => true)).Count, Is.EqualTo(3));
Assert.That(mr.Get("0").Value, Is.EqualTo(100));
await mr.UpdateAsync(e => e.Id == "1", e => e.Set(r => r.Value, 100));
await mr.UpdateAllAsync(e => e.Value == 100, e => e.Set(r => r.Value, -100));
Assert.That(mr.Get("0").Value, Is.EqualTo(-100));
Assert.That(mr.Get("1").Value, Is.EqualTo(-100));
}

private class IntegerEntity : IEntity
{
public string Id { get; set; } = default!;
public int Revision { get; set; } = 1;
public int Value { get; set; }

public IntegerEntity(int value)
{
Value = value;
}

public IntegerEntity() { }
}
}
34 changes: 34 additions & 0 deletions tests/SIL.DataAccess.Tests/SIL.DataAccess.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<RootNamespace>SIL.DataAccess</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\SIL.DataAccess\SIL.DataAccess.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 9168d5a

Please sign in to comment.