From 0f152ea1ec4621dc8a334a8821845ff291a5039d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20H=C3=A5velsrud?= Date: Thu, 9 Nov 2023 07:53:20 +0100 Subject: [PATCH 1/7] Add Bigtable emulator and tests. --- Testcontainers.sln | 14 +++++ .../BigtableEmulatorBuilder.cs | 61 +++++++++++++++++++ .../BigtableEmulatorConfiguration.cs | 53 ++++++++++++++++ .../BigtableEmulatorContainer.cs | 15 +++++ .../Testcontainers.Bigtable.csproj | 13 ++++ src/Testcontainers.Bigtable/Usings.cs | 9 +++ .../BigtableEmulatorContainerTest.cs | 37 +++++++++++ .../Testcontainers.Bigtable.Tests.csproj | 19 ++++++ tests/Testcontainers.Bigtable.Tests/Usings.cs | 8 +++ 9 files changed, 229 insertions(+) create mode 100644 src/Testcontainers.Bigtable/BigtableEmulatorBuilder.cs create mode 100644 src/Testcontainers.Bigtable/BigtableEmulatorConfiguration.cs create mode 100644 src/Testcontainers.Bigtable/BigtableEmulatorContainer.cs create mode 100644 src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj create mode 100644 src/Testcontainers.Bigtable/Usings.cs create mode 100644 tests/Testcontainers.Bigtable.Tests/BigtableEmulatorContainerTest.cs create mode 100644 tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj create mode 100644 tests/Testcontainers.Bigtable.Tests/Usings.cs diff --git a/Testcontainers.sln b/Testcontainers.sln index ac471c14e..29b0ff3d9 100644 --- a/Testcontainers.sln +++ b/Testcontainers.sln @@ -159,6 +159,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Bigtable", "src\Testcontainers.Bigtable\Testcontainers.Bigtable.csproj", "{302EC1E0-AE75-4E99-A6BF-524F35338BC8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Bigtable.Tests", "tests\Testcontainers.Bigtable.Tests\Testcontainers.Bigtable.Tests.csproj", "{2E7B92E3-8526-4706-90F3-00F0F5C47C37}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -460,6 +464,14 @@ Global {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU + {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Release|Any CPU.Build.0 = Release|Any CPU + {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {3F2E254F-C203-43FD-A078-DC3E2CBC0F9F} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} @@ -535,5 +547,7 @@ Global {1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} + {302EC1E0-AE75-4E99-A6BF-524F35338BC8} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} + {2E7B92E3-8526-4706-90F3-00F0F5C47C37} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} EndGlobalSection EndGlobal diff --git a/src/Testcontainers.Bigtable/BigtableEmulatorBuilder.cs b/src/Testcontainers.Bigtable/BigtableEmulatorBuilder.cs new file mode 100644 index 000000000..815131910 --- /dev/null +++ b/src/Testcontainers.Bigtable/BigtableEmulatorBuilder.cs @@ -0,0 +1,61 @@ +namespace Testcontainers.Bigtable; + +/// +[PublicAPI] +public class BigtableEmulatorBuilder: ContainerBuilder +{ + public const string GCloudCliDockerImage = "gcr.io/google.com/cloudsdktool/google-cloud-cli"; + + public const ushort BigtablePort = 9000; + + public const string CMD = "gcloud beta emulators bigtable start --host-port 0.0.0.0:9000"; + + /// + /// Initializes a new instance of the class. + /// + public BigtableEmulatorBuilder() : this(new BigtableEmulatorConfiguration()) + { + DockerResourceConfiguration = Init().DockerResourceConfiguration; + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + private BigtableEmulatorBuilder(BigtableEmulatorConfiguration resourceConfiguration) : base(resourceConfiguration) + { + DockerResourceConfiguration = resourceConfiguration; + } + + protected override BigtableEmulatorConfiguration DockerResourceConfiguration { get; } + + public override BigtableEmulatorContainer Build() + { + Validate(); + return new BigtableEmulatorContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); + } + + protected override BigtableEmulatorBuilder Init() + { + return base.Init() + .WithImage(GCloudCliDockerImage) + .WithPortBinding(BigtablePort, true) + .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("(?s).*running.*$").UntilPortIsAvailable(BigtablePort)) + .WithCommand("/bin/sh", "-c", CMD); + } + + protected override BigtableEmulatorBuilder Clone(IResourceConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new BigtableEmulatorConfiguration(resourceConfiguration)); + } + + protected override BigtableEmulatorBuilder Clone(IContainerConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new BigtableEmulatorConfiguration(resourceConfiguration)); + } + + protected override BigtableEmulatorBuilder Merge(BigtableEmulatorConfiguration oldValue, BigtableEmulatorConfiguration newValue) + { + return new BigtableEmulatorBuilder(new BigtableEmulatorConfiguration(oldValue, newValue)); + } +} diff --git a/src/Testcontainers.Bigtable/BigtableEmulatorConfiguration.cs b/src/Testcontainers.Bigtable/BigtableEmulatorConfiguration.cs new file mode 100644 index 000000000..61eaaec55 --- /dev/null +++ b/src/Testcontainers.Bigtable/BigtableEmulatorConfiguration.cs @@ -0,0 +1,53 @@ +namespace Testcontainers.Bigtable; + +/// +[PublicAPI] +public class BigtableEmulatorConfiguration: ContainerConfiguration +{ + /// + /// Initializes a new instance of the class. + /// + public BigtableEmulatorConfiguration() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public BigtableEmulatorConfiguration(IResourceConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public BigtableEmulatorConfiguration(IContainerConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public BigtableEmulatorConfiguration(BigtableEmulatorConfiguration resourceConfiguration) + : this(new BigtableEmulatorConfiguration(), resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } + + /// + /// Initializes a new instance of the class. + /// + /// The old Docker resource configuration. + /// The new Docker resource configuration. + public BigtableEmulatorConfiguration(BigtableEmulatorConfiguration oldValue, BigtableEmulatorConfiguration newValue) + : base(oldValue, newValue) + { + } +} diff --git a/src/Testcontainers.Bigtable/BigtableEmulatorContainer.cs b/src/Testcontainers.Bigtable/BigtableEmulatorContainer.cs new file mode 100644 index 000000000..66bfdbe81 --- /dev/null +++ b/src/Testcontainers.Bigtable/BigtableEmulatorContainer.cs @@ -0,0 +1,15 @@ +namespace Testcontainers.Bigtable; + +/// +[PublicAPI] +public class BigtableEmulatorContainer: DockerContainer +{ + public readonly string ProjectId = "project-id"; + + public readonly string InstanceId = "instance-id"; + public BigtableEmulatorContainer(IContainerConfiguration configuration, ILogger logger) : base(configuration, logger) + { + } + + public string GetEndpoint() => $"127.0.0.1:{GetMappedPublicPort(9000)}"; +} diff --git a/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj b/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj new file mode 100644 index 000000000..830628dda --- /dev/null +++ b/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj @@ -0,0 +1,13 @@ + + + netstandard2.0;netstandard2.1 + latest + + + + + + + + + diff --git a/src/Testcontainers.Bigtable/Usings.cs b/src/Testcontainers.Bigtable/Usings.cs new file mode 100644 index 000000000..f7923b008 --- /dev/null +++ b/src/Testcontainers.Bigtable/Usings.cs @@ -0,0 +1,9 @@ +global using System; +global using System.Collections.Generic; +global using System.Linq; +global using Docker.DotNet.Models; +global using DotNet.Testcontainers.Builders; +global using DotNet.Testcontainers.Configurations; +global using DotNet.Testcontainers.Containers; +global using JetBrains.Annotations; +global using Microsoft.Extensions.Logging; diff --git a/tests/Testcontainers.Bigtable.Tests/BigtableEmulatorContainerTest.cs b/tests/Testcontainers.Bigtable.Tests/BigtableEmulatorContainerTest.cs new file mode 100644 index 000000000..eaef49203 --- /dev/null +++ b/tests/Testcontainers.Bigtable.Tests/BigtableEmulatorContainerTest.cs @@ -0,0 +1,37 @@ +namespace Testcontainers.Bigtable.Tests; + +public class BigtableContainerTest : IAsyncLifetime +{ + private readonly BigtableEmulatorContainer _bigtableEmulatorContainer = new BigtableEmulatorBuilder().Build(); + + public Task InitializeAsync() + { + return _bigtableEmulatorContainer.StartAsync(); + } + + public Task DisposeAsync() + { + return _bigtableEmulatorContainer.StopAsync(); + } + + [Fact] + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public void AdminClientCanConnectAndCreateTable() + { + // Given + var adminClient = new BigtableTableAdminClientBuilder { ChannelCredentials = ChannelCredentials.Insecure, Endpoint = _bigtableEmulatorContainer.GetEndpoint() }.Build(); + var instanceName = new InstanceName(_bigtableEmulatorContainer.ProjectId, _bigtableEmulatorContainer.InstanceId); + var createTable = new Table + { + Granularity = Table.Types.TimestampGranularity.Unspecified, + ColumnFamilies = { { "test", new ColumnFamily { GcRule = new GcRule { MaxNumVersions = 1 } } } } + }; + var tableName = new TableName(_bigtableEmulatorContainer.ProjectId, _bigtableEmulatorContainer.InstanceId, "test-table"); + // When + adminClient.CreateTable(instanceName, "test-table", createTable, CallSettings.FromCancellationToken(CancellationToken.None)); + var tableCreated = adminClient.GetTable(tableName); + + // Then + Assert.NotNull(tableCreated); + } +} diff --git a/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj b/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj new file mode 100644 index 000000000..e6fa1b8ba --- /dev/null +++ b/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj @@ -0,0 +1,19 @@ + + + net6.0 + false + false + + + + + + + + + + + + + + diff --git a/tests/Testcontainers.Bigtable.Tests/Usings.cs b/tests/Testcontainers.Bigtable.Tests/Usings.cs new file mode 100644 index 000000000..eac6e2708 --- /dev/null +++ b/tests/Testcontainers.Bigtable.Tests/Usings.cs @@ -0,0 +1,8 @@ +global using System.Threading; +global using System.Threading.Tasks; +global using Xunit; +global using DotNet.Testcontainers.Commons; +global using Google.Api.Gax.Grpc; +global using Google.Cloud.Bigtable.Admin.V2; +global using Google.Cloud.Bigtable.Common.V2; +global using Grpc.Core; From dcc5d5a10c773607b8afeb7eebdd04b4ef559770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20H=C3=A5velsrud?= Date: Thu, 9 Nov 2023 09:15:39 +0100 Subject: [PATCH 2/7] Add .editorconfig file that was missing, and remove unnecesarry whitespace in solution and project files. --- src/Testcontainers.Bigtable/.editorconfig | 1 + src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj | 2 +- src/Testcontainers.Bigtable/Usings.cs | 5 +---- 3 files changed, 3 insertions(+), 5 deletions(-) create mode 100644 src/Testcontainers.Bigtable/.editorconfig diff --git a/src/Testcontainers.Bigtable/.editorconfig b/src/Testcontainers.Bigtable/.editorconfig new file mode 100644 index 000000000..6f066619d --- /dev/null +++ b/src/Testcontainers.Bigtable/.editorconfig @@ -0,0 +1 @@ +root = true \ No newline at end of file diff --git a/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj b/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj index 830628dda..4c05d521f 100644 --- a/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj +++ b/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj @@ -10,4 +10,4 @@ - + \ No newline at end of file diff --git a/src/Testcontainers.Bigtable/Usings.cs b/src/Testcontainers.Bigtable/Usings.cs index f7923b008..238dcb1c1 100644 --- a/src/Testcontainers.Bigtable/Usings.cs +++ b/src/Testcontainers.Bigtable/Usings.cs @@ -1,9 +1,6 @@ -global using System; -global using System.Collections.Generic; -global using System.Linq; global using Docker.DotNet.Models; global using DotNet.Testcontainers.Builders; global using DotNet.Testcontainers.Configurations; global using DotNet.Testcontainers.Containers; global using JetBrains.Annotations; -global using Microsoft.Extensions.Logging; +global using Microsoft.Extensions.Logging; \ No newline at end of file From 9bfa3060e369715050de12a76aa2a460073c5e30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20H=C3=A5velsrud?= Date: Thu, 9 Nov 2023 12:29:55 +0100 Subject: [PATCH 3/7] Fix naming to coencide with module specifications. --- .../BigtableBuilder.cs | 61 +++++++++++++++++++ ...figuration.cs => BigtableConfiguration.cs} | 14 ++--- ...latorContainer.cs => BigtableContainer.cs} | 4 +- .../BigtableEmulatorBuilder.cs | 61 ------------------- ...tainerTest.cs => BigtableContainerTest.cs} | 12 ++-- 5 files changed, 76 insertions(+), 76 deletions(-) create mode 100644 src/Testcontainers.Bigtable/BigtableBuilder.cs rename src/Testcontainers.Bigtable/{BigtableEmulatorConfiguration.cs => BigtableConfiguration.cs} (72%) rename src/Testcontainers.Bigtable/{BigtableEmulatorContainer.cs => BigtableContainer.cs} (61%) delete mode 100644 src/Testcontainers.Bigtable/BigtableEmulatorBuilder.cs rename tests/Testcontainers.Bigtable.Tests/{BigtableEmulatorContainerTest.cs => BigtableContainerTest.cs} (64%) diff --git a/src/Testcontainers.Bigtable/BigtableBuilder.cs b/src/Testcontainers.Bigtable/BigtableBuilder.cs new file mode 100644 index 000000000..f50466244 --- /dev/null +++ b/src/Testcontainers.Bigtable/BigtableBuilder.cs @@ -0,0 +1,61 @@ +namespace Testcontainers.Bigtable; + +/// +[PublicAPI] +public class BigtableBuilder: ContainerBuilder +{ + public const string GCloudCliDockerImage = "gcr.io/google.com/cloudsdktool/google-cloud-cli"; + + public const ushort BigtablePort = 9000; + + public const string CMD = "gcloud beta emulators bigtable start --host-port 0.0.0.0:9000"; + + /// + /// Initializes a new instance of the class. + /// + public BigtableBuilder() : this(new BigtableConfiguration()) + { + DockerResourceConfiguration = Init().DockerResourceConfiguration; + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + private BigtableBuilder(BigtableConfiguration resourceConfiguration) : base(resourceConfiguration) + { + DockerResourceConfiguration = resourceConfiguration; + } + + protected override BigtableConfiguration DockerResourceConfiguration { get; } + + public override BigtableContainer Build() + { + Validate(); + return new BigtableContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); + } + + protected override BigtableBuilder Init() + { + return base.Init() + .WithImage(GCloudCliDockerImage) + .WithPortBinding(BigtablePort, true) + .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("(?s).*running.*$").UntilPortIsAvailable(BigtablePort)) + .WithCommand("/bin/sh", "-c", CMD); + } + + protected override BigtableBuilder Clone(IResourceConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new BigtableConfiguration(resourceConfiguration)); + } + + protected override BigtableBuilder Clone(IContainerConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new BigtableConfiguration(resourceConfiguration)); + } + + protected override BigtableBuilder Merge(BigtableConfiguration oldValue, BigtableConfiguration newValue) + { + return new BigtableBuilder(new BigtableConfiguration(oldValue, newValue)); + } +} diff --git a/src/Testcontainers.Bigtable/BigtableEmulatorConfiguration.cs b/src/Testcontainers.Bigtable/BigtableConfiguration.cs similarity index 72% rename from src/Testcontainers.Bigtable/BigtableEmulatorConfiguration.cs rename to src/Testcontainers.Bigtable/BigtableConfiguration.cs index 61eaaec55..2ac3818ef 100644 --- a/src/Testcontainers.Bigtable/BigtableEmulatorConfiguration.cs +++ b/src/Testcontainers.Bigtable/BigtableConfiguration.cs @@ -2,12 +2,12 @@ namespace Testcontainers.Bigtable; /// [PublicAPI] -public class BigtableEmulatorConfiguration: ContainerConfiguration +public class BigtableConfiguration: ContainerConfiguration { /// /// Initializes a new instance of the class. /// - public BigtableEmulatorConfiguration() + public BigtableConfiguration() { } @@ -15,7 +15,7 @@ public BigtableEmulatorConfiguration() /// Initializes a new instance of the class. /// /// The Docker resource configuration. - public BigtableEmulatorConfiguration(IResourceConfiguration resourceConfiguration) + public BigtableConfiguration(IResourceConfiguration resourceConfiguration) : base(resourceConfiguration) { // Passes the configuration upwards to the base implementations to create an updated immutable copy. @@ -25,7 +25,7 @@ public BigtableEmulatorConfiguration(IResourceConfiguration class. /// /// The Docker resource configuration. - public BigtableEmulatorConfiguration(IContainerConfiguration resourceConfiguration) + public BigtableConfiguration(IContainerConfiguration resourceConfiguration) : base(resourceConfiguration) { // Passes the configuration upwards to the base implementations to create an updated immutable copy. @@ -35,8 +35,8 @@ public BigtableEmulatorConfiguration(IContainerConfiguration resourceConfigurati /// Initializes a new instance of the class. /// /// The Docker resource configuration. - public BigtableEmulatorConfiguration(BigtableEmulatorConfiguration resourceConfiguration) - : this(new BigtableEmulatorConfiguration(), resourceConfiguration) + public BigtableConfiguration(BigtableConfiguration resourceConfiguration) + : this(new BigtableConfiguration(), resourceConfiguration) { // Passes the configuration upwards to the base implementations to create an updated immutable copy. } @@ -46,7 +46,7 @@ public BigtableEmulatorConfiguration(BigtableEmulatorConfiguration resourceConfi /// /// The old Docker resource configuration. /// The new Docker resource configuration. - public BigtableEmulatorConfiguration(BigtableEmulatorConfiguration oldValue, BigtableEmulatorConfiguration newValue) + public BigtableConfiguration(BigtableConfiguration oldValue, BigtableConfiguration newValue) : base(oldValue, newValue) { } diff --git a/src/Testcontainers.Bigtable/BigtableEmulatorContainer.cs b/src/Testcontainers.Bigtable/BigtableContainer.cs similarity index 61% rename from src/Testcontainers.Bigtable/BigtableEmulatorContainer.cs rename to src/Testcontainers.Bigtable/BigtableContainer.cs index 66bfdbe81..b5d1842f3 100644 --- a/src/Testcontainers.Bigtable/BigtableEmulatorContainer.cs +++ b/src/Testcontainers.Bigtable/BigtableContainer.cs @@ -2,12 +2,12 @@ namespace Testcontainers.Bigtable; /// [PublicAPI] -public class BigtableEmulatorContainer: DockerContainer +public class BigtableContainer: DockerContainer { public readonly string ProjectId = "project-id"; public readonly string InstanceId = "instance-id"; - public BigtableEmulatorContainer(IContainerConfiguration configuration, ILogger logger) : base(configuration, logger) + public BigtableContainer(IContainerConfiguration configuration, ILogger logger) : base(configuration, logger) { } diff --git a/src/Testcontainers.Bigtable/BigtableEmulatorBuilder.cs b/src/Testcontainers.Bigtable/BigtableEmulatorBuilder.cs deleted file mode 100644 index 815131910..000000000 --- a/src/Testcontainers.Bigtable/BigtableEmulatorBuilder.cs +++ /dev/null @@ -1,61 +0,0 @@ -namespace Testcontainers.Bigtable; - -/// -[PublicAPI] -public class BigtableEmulatorBuilder: ContainerBuilder -{ - public const string GCloudCliDockerImage = "gcr.io/google.com/cloudsdktool/google-cloud-cli"; - - public const ushort BigtablePort = 9000; - - public const string CMD = "gcloud beta emulators bigtable start --host-port 0.0.0.0:9000"; - - /// - /// Initializes a new instance of the class. - /// - public BigtableEmulatorBuilder() : this(new BigtableEmulatorConfiguration()) - { - DockerResourceConfiguration = Init().DockerResourceConfiguration; - } - - /// - /// Initializes a new instance of the class. - /// - /// The Docker resource configuration. - private BigtableEmulatorBuilder(BigtableEmulatorConfiguration resourceConfiguration) : base(resourceConfiguration) - { - DockerResourceConfiguration = resourceConfiguration; - } - - protected override BigtableEmulatorConfiguration DockerResourceConfiguration { get; } - - public override BigtableEmulatorContainer Build() - { - Validate(); - return new BigtableEmulatorContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); - } - - protected override BigtableEmulatorBuilder Init() - { - return base.Init() - .WithImage(GCloudCliDockerImage) - .WithPortBinding(BigtablePort, true) - .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("(?s).*running.*$").UntilPortIsAvailable(BigtablePort)) - .WithCommand("/bin/sh", "-c", CMD); - } - - protected override BigtableEmulatorBuilder Clone(IResourceConfiguration resourceConfiguration) - { - return Merge(DockerResourceConfiguration, new BigtableEmulatorConfiguration(resourceConfiguration)); - } - - protected override BigtableEmulatorBuilder Clone(IContainerConfiguration resourceConfiguration) - { - return Merge(DockerResourceConfiguration, new BigtableEmulatorConfiguration(resourceConfiguration)); - } - - protected override BigtableEmulatorBuilder Merge(BigtableEmulatorConfiguration oldValue, BigtableEmulatorConfiguration newValue) - { - return new BigtableEmulatorBuilder(new BigtableEmulatorConfiguration(oldValue, newValue)); - } -} diff --git a/tests/Testcontainers.Bigtable.Tests/BigtableEmulatorContainerTest.cs b/tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs similarity index 64% rename from tests/Testcontainers.Bigtable.Tests/BigtableEmulatorContainerTest.cs rename to tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs index eaef49203..d60d9a453 100644 --- a/tests/Testcontainers.Bigtable.Tests/BigtableEmulatorContainerTest.cs +++ b/tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs @@ -2,16 +2,16 @@ namespace Testcontainers.Bigtable.Tests; public class BigtableContainerTest : IAsyncLifetime { - private readonly BigtableEmulatorContainer _bigtableEmulatorContainer = new BigtableEmulatorBuilder().Build(); + private readonly BigtableContainer _bigtableContainer = new BigtableBuilder().Build(); public Task InitializeAsync() { - return _bigtableEmulatorContainer.StartAsync(); + return _bigtableContainer.StartAsync(); } public Task DisposeAsync() { - return _bigtableEmulatorContainer.StopAsync(); + return _bigtableContainer.StopAsync(); } [Fact] @@ -19,14 +19,14 @@ public Task DisposeAsync() public void AdminClientCanConnectAndCreateTable() { // Given - var adminClient = new BigtableTableAdminClientBuilder { ChannelCredentials = ChannelCredentials.Insecure, Endpoint = _bigtableEmulatorContainer.GetEndpoint() }.Build(); - var instanceName = new InstanceName(_bigtableEmulatorContainer.ProjectId, _bigtableEmulatorContainer.InstanceId); + var adminClient = new BigtableTableAdminClientBuilder { ChannelCredentials = ChannelCredentials.Insecure, Endpoint = _bigtableContainer.GetEndpoint() }.Build(); + var instanceName = new InstanceName(_bigtableContainer.ProjectId, _bigtableContainer.InstanceId); var createTable = new Table { Granularity = Table.Types.TimestampGranularity.Unspecified, ColumnFamilies = { { "test", new ColumnFamily { GcRule = new GcRule { MaxNumVersions = 1 } } } } }; - var tableName = new TableName(_bigtableEmulatorContainer.ProjectId, _bigtableEmulatorContainer.InstanceId, "test-table"); + var tableName = new TableName(_bigtableContainer.ProjectId, _bigtableContainer.InstanceId, "test-table"); // When adminClient.CreateTable(instanceName, "test-table", createTable, CallSettings.FromCancellationToken(CancellationToken.None)); var tableCreated = adminClient.GetTable(tableName); From 7d9252c60d9f073ca19c560b784ef9911982411b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20H=C3=A5velsrud?= Date: Thu, 9 Nov 2023 12:33:29 +0100 Subject: [PATCH 4/7] Add Bigtable to list of modules. --- docs/modules/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/modules/index.md b/docs/modules/index.md index 50c6b065a..389ae5597 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -24,6 +24,7 @@ await moduleNameContainer.StartAsync(); | Azure Cosmos DB | `mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.CosmosDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CosmosDb) | | Azure SQL Edge | `mcr.microsoft.com/azure-sql-edge:1.0.7` | [NuGet](https://www.nuget.org/packages/Testcontainers.SqlEdge) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.SqlEdge) | | Azurite | `mcr.microsoft.com/azure-storage/azurite:3.24.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Azurite) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Azurite) | +| Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | | ClickHouse | `clickhouse/clickhouse-server:23.6-alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.ClickHouse) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ClickHouse) | | Consul | `consul:1.15` | [NuGet](https://www.nuget.org/packages/Testcontainers.Consul) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Consul) | | Couchbase | `couchbase:community-7.0.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.Couchbase) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Couchbase) | From 97b0b1643ae92dc5d160883dfc2d8499244d0b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20H=C3=A5velsrud?= Date: Thu, 9 Nov 2023 12:35:55 +0100 Subject: [PATCH 5/7] Remove some more whitespace. --- .../Testcontainers.Bigtable.Tests.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj b/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj index e6fa1b8ba..50907d536 100644 --- a/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj +++ b/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj @@ -15,5 +15,4 @@ - From 9a3b5a34e36dbc559de3eb405c0048021b4431c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20H=C3=A5velsrud?= Date: Thu, 16 Nov 2023 13:36:00 +0100 Subject: [PATCH 6/7] Address feedback on PR. --- docs/modules/index.md | 2 +- src/Testcontainers.Bigtable/BigtableBuilder.cs | 7 +++---- src/Testcontainers.Bigtable/BigtableContainer.cs | 3 --- .../BigtableContainerTest.cs | 9 ++++++--- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/modules/index.md b/docs/modules/index.md index 389ae5597..76b764126 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -24,7 +24,7 @@ await moduleNameContainer.StartAsync(); | Azure Cosmos DB | `mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.CosmosDb) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.CosmosDb) | | Azure SQL Edge | `mcr.microsoft.com/azure-sql-edge:1.0.7` | [NuGet](https://www.nuget.org/packages/Testcontainers.SqlEdge) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.SqlEdge) | | Azurite | `mcr.microsoft.com/azure-storage/azurite:3.24.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Azurite) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Azurite) | -| Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:latest` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | +| Bigtable | `gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators` | [NuGet](https://www.nuget.org/packages/Testcontainers.Bigtable) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Bigtable) | | ClickHouse | `clickhouse/clickhouse-server:23.6-alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.ClickHouse) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.ClickHouse) | | Consul | `consul:1.15` | [NuGet](https://www.nuget.org/packages/Testcontainers.Consul) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Consul) | | Couchbase | `couchbase:community-7.0.2` | [NuGet](https://www.nuget.org/packages/Testcontainers.Couchbase) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Couchbase) | diff --git a/src/Testcontainers.Bigtable/BigtableBuilder.cs b/src/Testcontainers.Bigtable/BigtableBuilder.cs index f50466244..b119cc69c 100644 --- a/src/Testcontainers.Bigtable/BigtableBuilder.cs +++ b/src/Testcontainers.Bigtable/BigtableBuilder.cs @@ -4,12 +4,10 @@ namespace Testcontainers.Bigtable; [PublicAPI] public class BigtableBuilder: ContainerBuilder { - public const string GCloudCliDockerImage = "gcr.io/google.com/cloudsdktool/google-cloud-cli"; + public const string GCloudCliDockerImage = "gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators"; public const ushort BigtablePort = 9000; - public const string CMD = "gcloud beta emulators bigtable start --host-port 0.0.0.0:9000"; - /// /// Initializes a new instance of the class. /// @@ -41,7 +39,8 @@ protected override BigtableBuilder Init() .WithImage(GCloudCliDockerImage) .WithPortBinding(BigtablePort, true) .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("(?s).*running.*$").UntilPortIsAvailable(BigtablePort)) - .WithCommand("/bin/sh", "-c", CMD); + .WithEntrypoint("gcloud") + .WithCommand("beta", "emulators", "bigtable", "start", "--host-port", "0.0.0.0:" + BigtablePort); } protected override BigtableBuilder Clone(IResourceConfiguration resourceConfiguration) diff --git a/src/Testcontainers.Bigtable/BigtableContainer.cs b/src/Testcontainers.Bigtable/BigtableContainer.cs index b5d1842f3..9cd452a4d 100644 --- a/src/Testcontainers.Bigtable/BigtableContainer.cs +++ b/src/Testcontainers.Bigtable/BigtableContainer.cs @@ -4,9 +4,6 @@ namespace Testcontainers.Bigtable; [PublicAPI] public class BigtableContainer: DockerContainer { - public readonly string ProjectId = "project-id"; - - public readonly string InstanceId = "instance-id"; public BigtableContainer(IContainerConfiguration configuration, ILogger logger) : base(configuration, logger) { } diff --git a/tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs b/tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs index d60d9a453..7cb823abf 100644 --- a/tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs +++ b/tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs @@ -2,6 +2,9 @@ namespace Testcontainers.Bigtable.Tests; public class BigtableContainerTest : IAsyncLifetime { + private const string InstanceId = "instance-id"; + private const string ProjectId = "project-id"; + private const string TestTable = "test-table"; private readonly BigtableContainer _bigtableContainer = new BigtableBuilder().Build(); public Task InitializeAsync() @@ -20,15 +23,15 @@ public void AdminClientCanConnectAndCreateTable() { // Given var adminClient = new BigtableTableAdminClientBuilder { ChannelCredentials = ChannelCredentials.Insecure, Endpoint = _bigtableContainer.GetEndpoint() }.Build(); - var instanceName = new InstanceName(_bigtableContainer.ProjectId, _bigtableContainer.InstanceId); + var instanceName = new InstanceName(ProjectId, InstanceId); var createTable = new Table { Granularity = Table.Types.TimestampGranularity.Unspecified, ColumnFamilies = { { "test", new ColumnFamily { GcRule = new GcRule { MaxNumVersions = 1 } } } } }; - var tableName = new TableName(_bigtableContainer.ProjectId, _bigtableContainer.InstanceId, "test-table"); + var tableName = new TableName(ProjectId, InstanceId, TestTable); // When - adminClient.CreateTable(instanceName, "test-table", createTable, CallSettings.FromCancellationToken(CancellationToken.None)); + adminClient.CreateTable(instanceName, TestTable, createTable, CallSettings.FromCancellationToken(CancellationToken.None)); var tableCreated = adminClient.GetTable(tableName); // Then From 5396fd61a8f133edce634f6badde2c92e98b913d Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Fri, 24 Nov 2023 21:47:34 +0100 Subject: [PATCH 7/7] chore: Align with other TC modules --- Testcontainers.sln | 28 ++--- .../BigtableBuilder.cs | 118 ++++++++++-------- .../BigtableConfiguration.cs | 88 ++++++------- .../BigtableContainer.cs | 25 +++- .../Testcontainers.Bigtable.csproj | 4 +- src/Testcontainers.Bigtable/Usings.cs | 1 + .../WebDriverConfiguration.cs | 7 +- .../.editorconfig | 1 + .../BigtableContainerTest.cs | 94 ++++++++------ .../Testcontainers.Bigtable.Tests.csproj | 18 +-- tests/Testcontainers.Bigtable.Tests/Usings.cs | 5 +- ...ainerTests.cs => InfluxDbContainerTest.cs} | 0 ...nerTests.cs => LocalStackContainerTest.cs} | 0 .../TarOutputMemoryStreamTest.cs | 4 +- ...ntainerTests.cs => PubSubContainerTest.cs} | 2 +- 15 files changed, 219 insertions(+), 176 deletions(-) create mode 100644 tests/Testcontainers.Bigtable.Tests/.editorconfig rename tests/Testcontainers.InfluxDb.Tests/{InfluxDbContainerTests.cs => InfluxDbContainerTest.cs} (100%) rename tests/Testcontainers.LocalStack.Tests/{LocalStackContainerTests.cs => LocalStackContainerTest.cs} (100%) rename tests/Testcontainers.PubSub.Tests/{PubSubContainerTests.cs => PubSubContainerTest.cs} (97%) diff --git a/Testcontainers.sln b/Testcontainers.sln index 3ada9e281..bd9e5c022 100644 --- a/Testcontainers.sln +++ b/Testcontainers.sln @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Azurite", "s EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.BigQuery", "src\Testcontainers.BigQuery\Testcontainers.BigQuery.csproj", "{A9FF9C7F-BBA0-4B44-90B7-48A60F9E00F3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Bigtable", "src\Testcontainers.Bigtable\Testcontainers.Bigtable.csproj", "{302EC1E0-AE75-4E99-A6BF-524F35338BC8}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ClickHouse", "src\Testcontainers.ClickHouse\Testcontainers.ClickHouse.csproj", "{B061A78E-536E-4CA1-8401-234D5FBFBAB7}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Consul", "src\Testcontainers.Consul\Testcontainers.Consul.csproj", "{51ED33B9-B688-401E-85F2-329D3C935BD1}" @@ -91,6 +93,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Azurite.Test EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.BigQuery.Tests", "tests\Testcontainers.BigQuery.Tests\Testcontainers.BigQuery.Tests.csproj", "{03E60673-078A-4508-99AD-8537CE6F78F1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Bigtable.Tests", "tests\Testcontainers.Bigtable.Tests\Testcontainers.Bigtable.Tests.csproj", "{2E7B92E3-8526-4706-90F3-00F0F5C47C37}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ClickHouse.Tests", "tests\Testcontainers.ClickHouse.Tests\Testcontainers.ClickHouse.Tests.csproj", "{9D0A0B32-4921-400C-99CB-8650677E3E44}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Commons", "tests\Testcontainers.Commons\Testcontainers.Commons.csproj", "{2478673C-B063-469D-ABD1-0C3E0A25541B}" @@ -171,10 +175,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tes EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Bigtable", "src\Testcontainers.Bigtable\Testcontainers.Bigtable.csproj", "{302EC1E0-AE75-4E99-A6BF-524F35338BC8}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Bigtable.Tests", "tests\Testcontainers.Bigtable.Tests\Testcontainers.Bigtable.Tests.csproj", "{2E7B92E3-8526-4706-90F3-00F0F5C47C37}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -192,6 +192,10 @@ Global {A9FF9C7F-BBA0-4B44-90B7-48A60F9E00F3}.Debug|Any CPU.Build.0 = Debug|Any CPU {A9FF9C7F-BBA0-4B44-90B7-48A60F9E00F3}.Release|Any CPU.ActiveCfg = Release|Any CPU {A9FF9C7F-BBA0-4B44-90B7-48A60F9E00F3}.Release|Any CPU.Build.0 = Release|Any CPU + {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Release|Any CPU.Build.0 = Release|Any CPU {B061A78E-536E-4CA1-8401-234D5FBFBAB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B061A78E-536E-4CA1-8401-234D5FBFBAB7}.Debug|Any CPU.Build.0 = Debug|Any CPU {B061A78E-536E-4CA1-8401-234D5FBFBAB7}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -340,6 +344,10 @@ Global {03E60673-078A-4508-99AD-8537CE6F78F1}.Debug|Any CPU.Build.0 = Debug|Any CPU {03E60673-078A-4508-99AD-8537CE6F78F1}.Release|Any CPU.ActiveCfg = Release|Any CPU {03E60673-078A-4508-99AD-8537CE6F78F1}.Release|Any CPU.Build.0 = Release|Any CPU + {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Release|Any CPU.Build.0 = Release|Any CPU {9D0A0B32-4921-400C-99CB-8650677E3E44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9D0A0B32-4921-400C-99CB-8650677E3E44}.Debug|Any CPU.Build.0 = Debug|Any CPU {9D0A0B32-4921-400C-99CB-8650677E3E44}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -500,18 +508,11 @@ Global {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}.Release|Any CPU.Build.0 = Release|Any CPU - {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {302EC1E0-AE75-4E99-A6BF-524F35338BC8}.Release|Any CPU.Build.0 = Release|Any CPU - {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2E7B92E3-8526-4706-90F3-00F0F5C47C37}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {3F2E254F-C203-43FD-A078-DC3E2CBC0F9F} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {A9FF9C7F-BBA0-4B44-90B7-48A60F9E00F3} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} + {302EC1E0-AE75-4E99-A6BF-524F35338BC8} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {B061A78E-536E-4CA1-8401-234D5FBFBAB7} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {51ED33B9-B688-401E-85F2-329D3C935BD1} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {A724806F-8C94-4438-8011-04A9A1575318} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} @@ -549,6 +550,7 @@ Global {EC76857B-A3B8-4B7A-A1B0-8D867A4D1733} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} {B272FDDE-5E01-425D-B9E1-10FF883DDAAA} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {03E60673-078A-4508-99AD-8537CE6F78F1} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} + {2E7B92E3-8526-4706-90F3-00F0F5C47C37} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {9D0A0B32-4921-400C-99CB-8650677E3E44} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {2478673C-B063-469D-ABD1-0C3E0A25541B} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {91B23679-A2A5-4132-8AFA-740CE40A88B6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} @@ -589,7 +591,5 @@ Global {1A1983E6-5297-435F-B467-E8E1F11277D6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} {EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} - {302EC1E0-AE75-4E99-A6BF-524F35338BC8} = {673F23AE-7694-4BB9-ABD4-136D6C13634E} - {2E7B92E3-8526-4706-90F3-00F0F5C47C37} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF} EndGlobalSection EndGlobal diff --git a/src/Testcontainers.Bigtable/BigtableBuilder.cs b/src/Testcontainers.Bigtable/BigtableBuilder.cs index b119cc69c..0a51140af 100644 --- a/src/Testcontainers.Bigtable/BigtableBuilder.cs +++ b/src/Testcontainers.Bigtable/BigtableBuilder.cs @@ -2,59 +2,67 @@ namespace Testcontainers.Bigtable; /// [PublicAPI] -public class BigtableBuilder: ContainerBuilder +public sealed class BigtableBuilder : ContainerBuilder { - public const string GCloudCliDockerImage = "gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators"; - - public const ushort BigtablePort = 9000; - - /// - /// Initializes a new instance of the class. - /// - public BigtableBuilder() : this(new BigtableConfiguration()) - { - DockerResourceConfiguration = Init().DockerResourceConfiguration; - } - - /// - /// Initializes a new instance of the class. - /// - /// The Docker resource configuration. - private BigtableBuilder(BigtableConfiguration resourceConfiguration) : base(resourceConfiguration) - { - DockerResourceConfiguration = resourceConfiguration; - } - - protected override BigtableConfiguration DockerResourceConfiguration { get; } - - public override BigtableContainer Build() - { - Validate(); - return new BigtableContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); - } - - protected override BigtableBuilder Init() - { - return base.Init() - .WithImage(GCloudCliDockerImage) - .WithPortBinding(BigtablePort, true) - .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("(?s).*running.*$").UntilPortIsAvailable(BigtablePort)) - .WithEntrypoint("gcloud") - .WithCommand("beta", "emulators", "bigtable", "start", "--host-port", "0.0.0.0:" + BigtablePort); - } - - protected override BigtableBuilder Clone(IResourceConfiguration resourceConfiguration) - { - return Merge(DockerResourceConfiguration, new BigtableConfiguration(resourceConfiguration)); - } - - protected override BigtableBuilder Clone(IContainerConfiguration resourceConfiguration) - { - return Merge(DockerResourceConfiguration, new BigtableConfiguration(resourceConfiguration)); - } - - protected override BigtableBuilder Merge(BigtableConfiguration oldValue, BigtableConfiguration newValue) - { - return new BigtableBuilder(new BigtableConfiguration(oldValue, newValue)); - } -} + public const string GoogleCloudCliImage = "gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators"; + + public const ushort BigtablePort = 9000; + + /// + /// Initializes a new instance of the class. + /// + public BigtableBuilder() + : this(new BigtableConfiguration()) + { + DockerResourceConfiguration = Init().DockerResourceConfiguration; + } + + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + private BigtableBuilder(BigtableConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + DockerResourceConfiguration = resourceConfiguration; + } + + /// + protected override BigtableConfiguration DockerResourceConfiguration { get; } + + /// + public override BigtableContainer Build() + { + Validate(); + return new BigtableContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); + } + + /// + protected override BigtableBuilder Init() + { + return base.Init() + .WithImage(GoogleCloudCliImage) + .WithPortBinding(BigtablePort, true) + .WithEntrypoint("gcloud") + .WithCommand("beta", "emulators", "bigtable", "start", "--host-port", "0.0.0.0:" + BigtablePort) + .WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("(?s).*running.*$")); + } + + /// + protected override BigtableBuilder Clone(IResourceConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new BigtableConfiguration(resourceConfiguration)); + } + + /// + protected override BigtableBuilder Clone(IContainerConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new BigtableConfiguration(resourceConfiguration)); + } + + /// + protected override BigtableBuilder Merge(BigtableConfiguration oldValue, BigtableConfiguration newValue) + { + return new BigtableBuilder(new BigtableConfiguration(oldValue, newValue)); + } +} \ No newline at end of file diff --git a/src/Testcontainers.Bigtable/BigtableConfiguration.cs b/src/Testcontainers.Bigtable/BigtableConfiguration.cs index 2ac3818ef..bf936ef60 100644 --- a/src/Testcontainers.Bigtable/BigtableConfiguration.cs +++ b/src/Testcontainers.Bigtable/BigtableConfiguration.cs @@ -2,52 +2,52 @@ namespace Testcontainers.Bigtable; /// [PublicAPI] -public class BigtableConfiguration: ContainerConfiguration +public sealed class BigtableConfiguration : ContainerConfiguration { - /// - /// Initializes a new instance of the class. - /// - public BigtableConfiguration() - { - } + /// + /// Initializes a new instance of the class. + /// + public BigtableConfiguration() + { + } - /// - /// Initializes a new instance of the class. - /// - /// The Docker resource configuration. - public BigtableConfiguration(IResourceConfiguration resourceConfiguration) - : base(resourceConfiguration) - { - // Passes the configuration upwards to the base implementations to create an updated immutable copy. - } + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public BigtableConfiguration(IResourceConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } - /// - /// Initializes a new instance of the class. - /// - /// The Docker resource configuration. - public BigtableConfiguration(IContainerConfiguration resourceConfiguration) - : base(resourceConfiguration) - { - // Passes the configuration upwards to the base implementations to create an updated immutable copy. - } + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public BigtableConfiguration(IContainerConfiguration resourceConfiguration) + : base(resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } - /// - /// Initializes a new instance of the class. - /// - /// The Docker resource configuration. - public BigtableConfiguration(BigtableConfiguration resourceConfiguration) - : this(new BigtableConfiguration(), resourceConfiguration) - { - // Passes the configuration upwards to the base implementations to create an updated immutable copy. - } + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + public BigtableConfiguration(BigtableConfiguration resourceConfiguration) + : this(new BigtableConfiguration(), resourceConfiguration) + { + // Passes the configuration upwards to the base implementations to create an updated immutable copy. + } - /// - /// Initializes a new instance of the class. - /// - /// The old Docker resource configuration. - /// The new Docker resource configuration. - public BigtableConfiguration(BigtableConfiguration oldValue, BigtableConfiguration newValue) - : base(oldValue, newValue) - { - } -} + /// + /// Initializes a new instance of the class. + /// + /// The old Docker resource configuration. + /// The new Docker resource configuration. + public BigtableConfiguration(BigtableConfiguration oldValue, BigtableConfiguration newValue) + : base(oldValue, newValue) + { + } +} \ No newline at end of file diff --git a/src/Testcontainers.Bigtable/BigtableContainer.cs b/src/Testcontainers.Bigtable/BigtableContainer.cs index 9cd452a4d..d0bde283d 100644 --- a/src/Testcontainers.Bigtable/BigtableContainer.cs +++ b/src/Testcontainers.Bigtable/BigtableContainer.cs @@ -2,11 +2,24 @@ namespace Testcontainers.Bigtable; /// [PublicAPI] -public class BigtableContainer: DockerContainer +public sealed class BigtableContainer : DockerContainer { - public BigtableContainer(IContainerConfiguration configuration, ILogger logger) : base(configuration, logger) - { - } + /// + /// Initializes a new instance of the class. + /// + /// The container configuration. + /// The logger. + public BigtableContainer(IContainerConfiguration configuration, ILogger logger) + : base(configuration, logger) + { + } - public string GetEndpoint() => $"127.0.0.1:{GetMappedPublicPort(9000)}"; -} + /// + /// Gets the Bigtable emulator endpoint. + /// + /// The Bigtable emulator endpoint. + public string GetEmulatorEndpoint() + { + return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(BigtableBuilder.BigtablePort)).ToString(); + } +} \ No newline at end of file diff --git a/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj b/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj index 4c05d521f..4ddb0b8fa 100644 --- a/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj +++ b/src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj @@ -4,8 +4,8 @@ latest - - + + diff --git a/src/Testcontainers.Bigtable/Usings.cs b/src/Testcontainers.Bigtable/Usings.cs index 238dcb1c1..bf2829a65 100644 --- a/src/Testcontainers.Bigtable/Usings.cs +++ b/src/Testcontainers.Bigtable/Usings.cs @@ -1,3 +1,4 @@ +global using System; global using Docker.DotNet.Models; global using DotNet.Testcontainers.Builders; global using DotNet.Testcontainers.Configurations; diff --git a/src/Testcontainers.WebDriver/WebDriverConfiguration.cs b/src/Testcontainers.WebDriver/WebDriverConfiguration.cs index 45f1101ea..cd5f2fc01 100644 --- a/src/Testcontainers.WebDriver/WebDriverConfiguration.cs +++ b/src/Testcontainers.WebDriver/WebDriverConfiguration.cs @@ -27,7 +27,8 @@ public WebDriverConfiguration(IResourceConfiguration /// Initializes a new instance of the class. /// /// The Docker resource configuration. - public WebDriverConfiguration(IContainerConfiguration resourceConfiguration) : base(resourceConfiguration) + public WebDriverConfiguration(IContainerConfiguration resourceConfiguration) + : base(resourceConfiguration) { // Passes the configuration upwards to the base implementations to create an updated immutable copy. } @@ -47,8 +48,8 @@ public WebDriverConfiguration(WebDriverConfiguration resourceConfiguration) /// /// The old Docker resource configuration. /// The new Docker resource configuration. - public WebDriverConfiguration(WebDriverConfiguration oldValue, WebDriverConfiguration newValue) : base(oldValue, - newValue) + public WebDriverConfiguration(WebDriverConfiguration oldValue, WebDriverConfiguration newValue) + : base(oldValue, newValue) { FFmpegContainer = BuildConfiguration.Combine(oldValue.FFmpegContainer, newValue.FFmpegContainer); } diff --git a/tests/Testcontainers.Bigtable.Tests/.editorconfig b/tests/Testcontainers.Bigtable.Tests/.editorconfig new file mode 100644 index 000000000..6f066619d --- /dev/null +++ b/tests/Testcontainers.Bigtable.Tests/.editorconfig @@ -0,0 +1 @@ +root = true \ No newline at end of file diff --git a/tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs b/tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs index 7cb823abf..d3034d1a9 100644 --- a/tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs +++ b/tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs @@ -1,40 +1,60 @@ -namespace Testcontainers.Bigtable.Tests; +namespace Testcontainers.Bigtable; -public class BigtableContainerTest : IAsyncLifetime +public sealed class BigtableContainerTest : IAsyncLifetime { - private const string InstanceId = "instance-id"; - private const string ProjectId = "project-id"; - private const string TestTable = "test-table"; - private readonly BigtableContainer _bigtableContainer = new BigtableBuilder().Build(); - - public Task InitializeAsync() - { - return _bigtableContainer.StartAsync(); - } - - public Task DisposeAsync() - { - return _bigtableContainer.StopAsync(); - } - - [Fact] - [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] - public void AdminClientCanConnectAndCreateTable() - { - // Given - var adminClient = new BigtableTableAdminClientBuilder { ChannelCredentials = ChannelCredentials.Insecure, Endpoint = _bigtableContainer.GetEndpoint() }.Build(); - var instanceName = new InstanceName(ProjectId, InstanceId); - var createTable = new Table + private readonly BigtableContainer _bigtableContainer = new BigtableBuilder().Build(); + + public Task InitializeAsync() + { + return _bigtableContainer.StartAsync(); + } + + public Task DisposeAsync() + { + return _bigtableContainer.DisposeAsync().AsTask(); + } + + [Fact] + [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] + public async Task GetTableReturnsCreateTable() { - Granularity = Table.Types.TimestampGranularity.Unspecified, - ColumnFamilies = { { "test", new ColumnFamily { GcRule = new GcRule { MaxNumVersions = 1 } } } } - }; - var tableName = new TableName(ProjectId, InstanceId, TestTable); - // When - adminClient.CreateTable(instanceName, TestTable, createTable, CallSettings.FromCancellationToken(CancellationToken.None)); - var tableCreated = adminClient.GetTable(tableName); - - // Then - Assert.NotNull(tableCreated); - } -} + // Given + var projectId = Guid.NewGuid().ToString("D"); + + var instanceId = Guid.NewGuid().ToString("D"); + + var tableId = Guid.NewGuid().ToString("D"); + + var instanceName = new InstanceName(projectId, instanceId); + + var tableName = new TableName(projectId, instanceId, tableId); + + var columnFamily = new ColumnFamily(); + columnFamily.GcRule = new GcRule(); + columnFamily.GcRule.MaxNumVersions = 1; + + var table = new Table(); + table.Granularity = Table.Types.TimestampGranularity.Unspecified; + table.ColumnFamilies.Add(nameof(columnFamily), columnFamily); + + var bigtableClientBuilder = new BigtableTableAdminClientBuilder(); + bigtableClientBuilder.Endpoint = _bigtableContainer.GetEmulatorEndpoint(); + bigtableClientBuilder.ChannelCredentials = ChannelCredentials.Insecure; + + // When + var bigtableClient = await bigtableClientBuilder.BuildAsync() + .ConfigureAwait(false); + + _ = await bigtableClient.CreateTableAsync(instanceName, tableName.TableId, table) + .ConfigureAwait(false); + + var actualTable = await bigtableClient.GetTableAsync(tableName) + .ConfigureAwait(false); + + // Then + Assert.NotNull(actualTable); + Assert.Equal(projectId, actualTable.TableName.ProjectId); + Assert.Equal(instanceId, actualTable.TableName.InstanceId); + Assert.Equal(tableId, actualTable.TableName.TableId); + } +} \ No newline at end of file diff --git a/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj b/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj index 50907d536..d7b5c827c 100644 --- a/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj +++ b/tests/Testcontainers.Bigtable.Tests/Testcontainers.Bigtable.Tests.csproj @@ -1,18 +1,18 @@ - net6.0 + net8.0 false false - - - - - + + + + + - - + + - + \ No newline at end of file diff --git a/tests/Testcontainers.Bigtable.Tests/Usings.cs b/tests/Testcontainers.Bigtable.Tests/Usings.cs index eac6e2708..17af3445c 100644 --- a/tests/Testcontainers.Bigtable.Tests/Usings.cs +++ b/tests/Testcontainers.Bigtable.Tests/Usings.cs @@ -1,8 +1,7 @@ -global using System.Threading; +global using System; global using System.Threading.Tasks; -global using Xunit; global using DotNet.Testcontainers.Commons; -global using Google.Api.Gax.Grpc; global using Google.Cloud.Bigtable.Admin.V2; global using Google.Cloud.Bigtable.Common.V2; global using Grpc.Core; +global using Xunit; \ No newline at end of file diff --git a/tests/Testcontainers.InfluxDb.Tests/InfluxDbContainerTests.cs b/tests/Testcontainers.InfluxDb.Tests/InfluxDbContainerTest.cs similarity index 100% rename from tests/Testcontainers.InfluxDb.Tests/InfluxDbContainerTests.cs rename to tests/Testcontainers.InfluxDb.Tests/InfluxDbContainerTest.cs diff --git a/tests/Testcontainers.LocalStack.Tests/LocalStackContainerTests.cs b/tests/Testcontainers.LocalStack.Tests/LocalStackContainerTest.cs similarity index 100% rename from tests/Testcontainers.LocalStack.Tests/LocalStackContainerTests.cs rename to tests/Testcontainers.LocalStack.Tests/LocalStackContainerTest.cs diff --git a/tests/Testcontainers.Platform.Linux.Tests/TarOutputMemoryStreamTest.cs b/tests/Testcontainers.Platform.Linux.Tests/TarOutputMemoryStreamTest.cs index d27090463..ff5ea321e 100644 --- a/tests/Testcontainers.Platform.Linux.Tests/TarOutputMemoryStreamTest.cs +++ b/tests/Testcontainers.Platform.Linux.Tests/TarOutputMemoryStreamTest.cs @@ -18,7 +18,7 @@ protected TarOutputMemoryStreamTest() public void TestFileExistsInTarFile() { // Given - IList actual = new List(); + var actual = new List(); _tarOutputMemoryStream.Close(); _tarOutputMemoryStream.Seek(0, SeekOrigin.Begin); @@ -97,7 +97,7 @@ public async Task TestFileExistsInContainer() var targetDirectoryPath4 = string.Join("/", string.Empty, "tmp", Guid.NewGuid()); - IList targetFilePaths = new List(); + var targetFilePaths = new List(); targetFilePaths.Add(targetFilePath1); targetFilePaths.Add(targetFilePath2); targetFilePaths.Add(string.Join("/", targetDirectoryPath1, _testFile.Name)); diff --git a/tests/Testcontainers.PubSub.Tests/PubSubContainerTests.cs b/tests/Testcontainers.PubSub.Tests/PubSubContainerTest.cs similarity index 97% rename from tests/Testcontainers.PubSub.Tests/PubSubContainerTests.cs rename to tests/Testcontainers.PubSub.Tests/PubSubContainerTest.cs index 03d0ae641..928b5b074 100644 --- a/tests/Testcontainers.PubSub.Tests/PubSubContainerTests.cs +++ b/tests/Testcontainers.PubSub.Tests/PubSubContainerTest.cs @@ -1,6 +1,6 @@ namespace Testcontainers.PubSub; -public sealed class PubSubContainerTests : IAsyncLifetime +public sealed class PubSubContainerTest : IAsyncLifetime { private readonly PubSubContainer _pubSubContainer = new PubSubBuilder().Build();