diff --git a/.github/WorkflowGen/Program.cs b/.github/WorkflowGen/Program.cs index 729f39ab..096392ba 100644 --- a/.github/WorkflowGen/Program.cs +++ b/.github/WorkflowGen/Program.cs @@ -20,7 +20,6 @@ void GenerateWorkflowsForLibs() "little-forker", "pulumi", "system-extensions", - "testing", "webhook-relay" }; diff --git a/.github/workflows/testing-ci.yml b/.github/workflows/testing-ci.yml deleted file mode 100644 index c462f6a9..00000000 --- a/.github/workflows/testing-ci.yml +++ /dev/null @@ -1,63 +0,0 @@ -# This was generated by tool. Edits will be overwritten. - -name: testing-ci -on: - pull_request: - paths: - - .github/workflows/testing-** - - libs/testing** - - build/** - push: - branches: - - main - paths: - - .github/workflows/testing-** - - libs/testing** - - build/** - tags: - - testing-** -jobs: - build: - runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${secrets.GITHUB_TOKEN} - LOGICALITY_NUGET_ORG: ${secrets.LOGICALITY_NUGET_ORG} - WEBHOOKRELAYTOKENKEY: ${secrets.WEBHOOKRELAYTOKENKEY} - WEBHOOKRELAYTOKENSECRET: ${secrets.WEBHOOKRELAYTOKENSECRET} - WEBHOOKURL: ${secrets.WEBHOOKURL} - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Log into GitHub Container Registry - run: echo "${{secrets.GITHUB_TOKEN}}" | docker login ghcr.io -u ${{github.actor}} --password-stdin - - name: Setup Dotnet - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 8.0.x - - name: Print Env - run: printenv - shell: bash - - name: Test - timeout-minutes: 5 - run: ./build.ps1 testing-test - shell: pwsh - - name: Pack - run: ./build.ps1 testing-pack - shell: pwsh - - name: Push to GitHub - if: github.event_name == 'push' - continue-on-error: true - run: ./build.ps1 push-github - shell: pwsh - - name: Push to Nuget.org (on tag) - if: startsWith(github.ref, 'refs/tags/testing') - continue-on-error: true - run: ./build.ps1 push-nugetorg - shell: pwsh - - name: Upload Artifacts - uses: actions/upload-artifact@v3 - with: - name: artifacts - path: artifacts diff --git a/PlatformLibs.sln b/PlatformLibs.sln index 6d105db1..88e767dc 100644 --- a/PlatformLibs.sln +++ b/PlatformLibs.sln @@ -109,22 +109,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemExtensions", "libs\sy EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SystemExtensions.Tests", "libs\system-extensions\tests\SystemExtensions.Tests\SystemExtensions.Tests.csproj", "{723D27AE-E5E7-4ABC-802C-F67299C63257}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testing", "testing", "{E49DE013-4C18-4A9B-A541-842FC38E5E93}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0CB2B190-89C7-49A1-A380-53F862237F24}" - ProjectSection(SolutionItems) = preProject - libs\testing\src\Directory.Build.props = libs\testing\src\Directory.Build.props - EndProjectSection -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{6ED4DFF8-FAC8-402A-92EA-72DE7F5BFF93}" - ProjectSection(SolutionItems) = preProject - libs\testing\tests\Directory.Build.props = libs\testing\tests\Directory.Build.props - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testing.Fixtures", "libs\testing\src\Testing.Fixtures\Testing.Fixtures.csproj", "{7943D27C-1268-43F0-85D0-5879F1E734F0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testing.Fixtures.Tests", "libs\testing\tests\Testing.Fixtures.Tests\Testing.Fixtures.Tests.csproj", "{FC5B745A-6E38-4B1B-ACDF-F6293BA30244}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "pulumi", "pulumi", "{CA1CB8E3-8811-4407-BA8E-952C2206D716}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2209C4A6-1E2A-4F12-A707-22DEBBFEC78A}" @@ -325,14 +309,6 @@ Global {723D27AE-E5E7-4ABC-802C-F67299C63257}.Debug|Any CPU.Build.0 = Debug|Any CPU {723D27AE-E5E7-4ABC-802C-F67299C63257}.Release|Any CPU.ActiveCfg = Release|Any CPU {723D27AE-E5E7-4ABC-802C-F67299C63257}.Release|Any CPU.Build.0 = Release|Any CPU - {7943D27C-1268-43F0-85D0-5879F1E734F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7943D27C-1268-43F0-85D0-5879F1E734F0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7943D27C-1268-43F0-85D0-5879F1E734F0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7943D27C-1268-43F0-85D0-5879F1E734F0}.Release|Any CPU.Build.0 = Release|Any CPU - {FC5B745A-6E38-4B1B-ACDF-F6293BA30244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FC5B745A-6E38-4B1B-ACDF-F6293BA30244}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FC5B745A-6E38-4B1B-ACDF-F6293BA30244}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FC5B745A-6E38-4B1B-ACDF-F6293BA30244}.Release|Any CPU.Build.0 = Release|Any CPU {2F3CB9B8-8A2A-4709-B73B-6A1B043D52A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2F3CB9B8-8A2A-4709-B73B-6A1B043D52A2}.Debug|Any CPU.Build.0 = Debug|Any CPU {2F3CB9B8-8A2A-4709-B73B-6A1B043D52A2}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -469,11 +445,6 @@ Global {F70F25F9-FBBF-46B2-8BD4-C84FB24D998E} = {F01A2FEE-A5E4-4649-AE63-C150E1345340} {55E08F6C-7F5D-4D15-BAF0-B0CB10170C1B} = {784169CC-99B9-4FF6-8F2D-45CC232CEDFB} {723D27AE-E5E7-4ABC-802C-F67299C63257} = {BAF61FF9-F641-4929-AC36-3314F03930DC} - {E49DE013-4C18-4A9B-A541-842FC38E5E93} = {5038BE98-AAF8-4FB1-B683-C03B760C36A7} - {0CB2B190-89C7-49A1-A380-53F862237F24} = {E49DE013-4C18-4A9B-A541-842FC38E5E93} - {6ED4DFF8-FAC8-402A-92EA-72DE7F5BFF93} = {E49DE013-4C18-4A9B-A541-842FC38E5E93} - {7943D27C-1268-43F0-85D0-5879F1E734F0} = {0CB2B190-89C7-49A1-A380-53F862237F24} - {FC5B745A-6E38-4B1B-ACDF-F6293BA30244} = {6ED4DFF8-FAC8-402A-92EA-72DE7F5BFF93} {CA1CB8E3-8811-4407-BA8E-952C2206D716} = {5038BE98-AAF8-4FB1-B683-C03B760C36A7} {2209C4A6-1E2A-4F12-A707-22DEBBFEC78A} = {CA1CB8E3-8811-4407-BA8E-952C2206D716} {2F3CB9B8-8A2A-4709-B73B-6A1B043D52A2} = {2209C4A6-1E2A-4F12-A707-22DEBBFEC78A} diff --git a/libs/testing/src/Directory.Build.props b/libs/testing/src/Directory.Build.props deleted file mode 100644 index 16276eca..00000000 --- a/libs/testing/src/Directory.Build.props +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - testing- - 0.1 - - - diff --git a/libs/testing/src/Testing.Fixtures/DynamoDBFixture.cs b/libs/testing/src/Testing.Fixtures/DynamoDBFixture.cs deleted file mode 100644 index 750532cf..00000000 --- a/libs/testing/src/Testing.Fixtures/DynamoDBFixture.cs +++ /dev/null @@ -1,94 +0,0 @@ -using Ductus.FluentDocker.Builders; -using Ductus.FluentDocker.Common; -using Ductus.FluentDocker.Services; -using Ductus.FluentDocker.Services.Extensions; -using Polly; - -namespace Logicality.Testing.Fixtures; - -public class DynamoDBFixture : IDisposable -{ - private const int ContainerPort = 8000; - private readonly IContainerService _containerService; - - private DynamoDBFixture(IContainerService containerService, Uri serviceUrl) - { - _containerService = containerService; - ServiceUrl = serviceUrl; - } - - public static Task Create(string containerNamePrefix, string imageTag = "latest", int port = 0) - { - return Task.Run(() => - { - IContainerService containerService; - var name = $"{containerNamePrefix}-dynamodb"; - try - { - containerService = new Builder() - .UseContainer() - .WithName(name) - .UseImage($"amazon/dynamodb-local:{imageTag}") - .ReuseIfExists() - .Command("", "-jar", "DynamoDBLocal.jar", "-inMemory", "-sharedDb") - .ExposePort(port, ContainerPort) - .WaitForPort($"{ContainerPort}/tcp", TimeSpan.FromSeconds(5)) - .Build(); - containerService.Start(); - } - catch (FluentDockerException ex) when (ex.Message.Contains("Error response from daemon: Conflict")) - { - // This can happen in a container startup race condition and parallel tests. - // Assume the container is already running. - - var hosts = new Hosts().Discover(); - var docker = hosts.FirstOrDefault(x => x.IsNative) - ?? hosts.FirstOrDefault(x => x.Name == "default"); - - var waitAndRetry = Polly.Policy.Handle() - .WaitAndRetry(10, _ => TimeSpan.FromMilliseconds(500)); - - containerService = waitAndRetry.Execute(() => - { - var containers = docker!.GetContainers(); - var container = containers.Single(c => c.Name == name); - container.WaitForPort($"{ContainerPort}/tcp", 5000); - return container; - }); - } - - var config = containerService.GetConfiguration(); - var networkSettings = config.NetworkSettings; - var exposedPort = networkSettings.Ports.First(); - var hostPort = exposedPort.Value.First().HostPort; - - var serviceUrl = new UriBuilder($"http://localhost:{hostPort}"); - - if (FixtureUtils.IsRunningInContainer) - { - // When tests are running in container, the networking setup is different. - // Instead of host -> container, we have container -> container so - // localhost won't work as host networking does not apply - var host = containerService - .GetConfiguration() - .NetworkSettings - .IPAddress; - - serviceUrl.Host = host; - serviceUrl.Port = ContainerPort; - } - - return new DynamoDBFixture(containerService, serviceUrl.Uri); - }); - } - - public Uri ServiceUrl { get; } - - /// - /// Disposes and shuts down the container. - /// - public void Dispose() - { - _containerService.Dispose(); - } -} \ No newline at end of file diff --git a/libs/testing/src/Testing.Fixtures/FixtureUtils.cs b/libs/testing/src/Testing.Fixtures/FixtureUtils.cs deleted file mode 100644 index 479a570b..00000000 --- a/libs/testing/src/Testing.Fixtures/FixtureUtils.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Net; -using System.Net.Sockets; - -namespace Logicality.Testing.Fixtures; - -public static class FixtureUtils -{ - static FixtureUtils() - { - var env = Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"); - IsRunningInContainer = env != null && env.Equals("true", StringComparison.OrdinalIgnoreCase); - } - - public static bool IsRunningInContainer { get; } - - public static string GetLocalIPAddress() - { - var host = Dns.GetHostEntry(Dns.GetHostName()); - foreach (var ip in host.AddressList) - { - if (ip.AddressFamily == AddressFamily.InterNetwork) - { - return ip.ToString(); - } - } - throw new Exception("No network adapters with an IPv4 address in the system!"); - } -} \ No newline at end of file diff --git a/libs/testing/src/Testing.Fixtures/LocalStackFixture.cs b/libs/testing/src/Testing.Fixtures/LocalStackFixture.cs deleted file mode 100644 index 5f2957cf..00000000 --- a/libs/testing/src/Testing.Fixtures/LocalStackFixture.cs +++ /dev/null @@ -1,115 +0,0 @@ -using Ductus.FluentDocker.Builders; -using Ductus.FluentDocker.Common; -using Ductus.FluentDocker.Services; -using Ductus.FluentDocker.Services.Extensions; -using Polly; - -namespace Logicality.Testing.Fixtures; - -public class LocalstackFixture : IDisposable -{ - private const int ContainerPort = 4566; - private readonly IContainerService _containerService; - - private LocalstackFixture(IContainerService containerService, Uri serviceUrl) - { - _containerService = containerService; - ServiceUrl = serviceUrl; - } - - /// - /// Create an instance of - /// - /// - /// A prefix for the container name. - /// Use to isolate between multiple local stack instances running concurrently. - /// - /// The collection os services to run. See LocalStack documentation. - /// LocalStack image tag. Default is 'latest'. - /// LocalStack Pro API key - /// - /// Default is '0' which will bind to a random free port. Useful when - /// running multiple container instances and not having port conflicts on the host. - /// - /// - public static Task Create( - string containerNamePrefix, - string services, - string imageTag = "latest", - string proApiKey = "", - int port = 0) - { - return Task.Run(() => - { - IContainerService containerService; - var name = $"{containerNamePrefix}-localstack"; - try - { - containerService = new Builder() - .UseContainer() - .WithName(name) - .UseImage($"localstack/localstack:{imageTag}") - .ReuseIfExists() - .ExposePort(port, ContainerPort) - .WithEnvironment("LS_LOG=debug") - .WithEnvironment($"LOCALSTACK_API_KEY={proApiKey}") - .WithEnvironment($"SERVICES={services}") - .WaitForPort($"{ContainerPort}/tcp", TimeSpan.FromSeconds(10)) - .Build(); - containerService.Start(); - } - catch (FluentDockerException ex) when (ex.Message.Contains("Error response from daemon: Conflict")) - { - // This can happen in a container startup race condition and parallel tests. - // Assume the container is already running. - - var hosts = new Hosts().Discover(); - var docker = hosts.FirstOrDefault(x => x.IsNative) ?? hosts.FirstOrDefault(x => x.Name == "default"); - - var waitAndRetry = Policy.Handle() - .WaitAndRetry(30, _ => TimeSpan.FromMilliseconds(1000)); - - containerService = waitAndRetry.Execute(() => - { - var containers = docker!.GetContainers(); - var container = containers.Single(c => c.Name == name); - container.WaitForPort($"{ContainerPort}/tcp", 5000); - return container; - }); - } - - var config = containerService.GetConfiguration(); - var networkSettings = config.NetworkSettings; - var exposedPort = networkSettings.Ports.First(); - var hostPort = exposedPort.Key.Split("/").First(); - - var serviceUrl = new UriBuilder($"http://localhost:{hostPort}"); - - if (FixtureUtils.IsRunningInContainer) - { - // When tests are running in container, the networking setup is different. - // Instead of host -> container, we have container -> container so - // localhost won't work as host networking does not apply - var host = containerService - .GetConfiguration() - .NetworkSettings - .IPAddress; - - serviceUrl.Host = host; - serviceUrl.Port = ContainerPort; - } - - return new LocalstackFixture(containerService, serviceUrl.Uri); - }); - } - - public Uri ServiceUrl { get; } - - /// - /// Disposes and shuts down the container. - /// - public void Dispose() - { - _containerService.Dispose(); - } -} \ No newline at end of file diff --git a/libs/testing/src/Testing.Fixtures/Testing.Fixtures.csproj b/libs/testing/src/Testing.Fixtures/Testing.Fixtures.csproj deleted file mode 100644 index c71dbc04..00000000 --- a/libs/testing/src/Testing.Fixtures/Testing.Fixtures.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/libs/testing/tests/Directory.Build.props b/libs/testing/tests/Directory.Build.props deleted file mode 100644 index d6cc951a..00000000 --- a/libs/testing/tests/Directory.Build.props +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/libs/testing/tests/Testing.Fixtures.Tests/DynamoDBFixtureTests.cs b/libs/testing/tests/Testing.Fixtures.Tests/DynamoDBFixtureTests.cs deleted file mode 100644 index a159c39e..00000000 --- a/libs/testing/tests/Testing.Fixtures.Tests/DynamoDBFixtureTests.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Threading.Tasks; -using Shouldly; -using Xunit; - -namespace Logicality.Testing.Fixtures; - -public class DynamoDBFixtureTests -{ - [Fact] - public async Task Can_run() - { - using var dynamoDBFixture = await DynamoDBFixture.Create("testing-fixtures-1"); - - dynamoDBFixture.ServiceUrl.ShouldNotBeNull(); - - dynamoDBFixture.ServiceUrl.Port.ShouldNotBe(0); - } - - [Fact] - public async Task Can_run_in_parallel() - { - var fixtures = new ConcurrentBag(); - - var tasks = new List(); - for (var i = 0; i < 10; i++) - { - var task = Task.Run(async () => - { - var fixture = await DynamoDBFixture.Create("testing-fixtures-2"); - fixtures.Add(fixture); - }); - - tasks.Add(task); - } - - await Task.WhenAll(tasks); - foreach (var fixture in fixtures.ToArray()) - { - fixture.Dispose(); - } - } -} \ No newline at end of file diff --git a/libs/testing/tests/Testing.Fixtures.Tests/LocalStackFixtureTests.cs b/libs/testing/tests/Testing.Fixtures.Tests/LocalStackFixtureTests.cs deleted file mode 100644 index 9b534002..00000000 --- a/libs/testing/tests/Testing.Fixtures.Tests/LocalStackFixtureTests.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Threading.Tasks; -using Shouldly; -using Xunit; - -namespace Logicality.Testing.Fixtures; - -public class LocalStackFixtureTests -{ - [Fact] - public async Task Can_run() - { - using var fixture = await LocalstackFixture.Create("testing-fixtures-1", "s3"); - - fixture.ServiceUrl.ShouldNotBeNull(); - fixture.ServiceUrl.Port.ShouldNotBe(0); - } - - [Fact] - public async Task Can_run_in_parallel() - { - var fixtures = new ConcurrentBag(); - - var tasks = new List(); - for (var i = 0; i < 10; i++) - { - var task = Task.Run(async () => - { - var fixture = await LocalstackFixture.Create("testing-fixtures-2", "s3"); - fixtures.Add(fixture); - }); - - tasks.Add(task); - } - - await Task.WhenAll(tasks); - - foreach (var fixture in fixtures.ToArray()) - { - fixture.Dispose(); - } - } -} \ No newline at end of file diff --git a/libs/testing/tests/Testing.Fixtures.Tests/Testing.Fixtures.Tests.csproj b/libs/testing/tests/Testing.Fixtures.Tests/Testing.Fixtures.Tests.csproj deleted file mode 100644 index 9f149474..00000000 --- a/libs/testing/tests/Testing.Fixtures.Tests/Testing.Fixtures.Tests.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - Logicality.Testing.Fixtures.Tests - Logicality.Testing.Fixtures - false - - - - - - -