Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Add Bigtable module #1046

Merged
merged 9 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -188,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
Expand Down Expand Up @@ -336,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
Expand Down Expand Up @@ -500,6 +512,7 @@ Global
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}
Expand Down Expand Up @@ -537,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}
Expand Down
1 change: 1 addition & 0 deletions docs/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: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) |
Expand Down
1 change: 1 addition & 0 deletions src/Testcontainers.Bigtable/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
68 changes: 68 additions & 0 deletions src/Testcontainers.Bigtable/BigtableBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace Testcontainers.Bigtable;

/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
[PublicAPI]
public sealed class BigtableBuilder : ContainerBuilder<BigtableBuilder, BigtableContainer, BigtableConfiguration>
{
public const string GoogleCloudCliImage = "gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators";

public const ushort BigtablePort = 9000;

/// <summary>
/// Initializes a new instance of the <see cref="BigtableBuilder" /> class.
/// </summary>
public BigtableBuilder()
: this(new BigtableConfiguration())
{
DockerResourceConfiguration = Init().DockerResourceConfiguration;
}

/// <summary>
/// Initializes a new instance of the <see cref="BigtableBuilder" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
private BigtableBuilder(BigtableConfiguration resourceConfiguration)
: base(resourceConfiguration)
{
DockerResourceConfiguration = resourceConfiguration;
}

/// <inheritdoc />
protected override BigtableConfiguration DockerResourceConfiguration { get; }

/// <inheritdoc />
public override BigtableContainer Build()
{
Validate();
return new BigtableContainer(DockerResourceConfiguration, TestcontainersSettings.Logger);
}

/// <inheritdoc />
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.*$"));
}

/// <inheritdoc />
protected override BigtableBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new BigtableConfiguration(resourceConfiguration));
}

/// <inheritdoc />
protected override BigtableBuilder Clone(IContainerConfiguration resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new BigtableConfiguration(resourceConfiguration));
}

/// <inheritdoc />
protected override BigtableBuilder Merge(BigtableConfiguration oldValue, BigtableConfiguration newValue)
{
return new BigtableBuilder(new BigtableConfiguration(oldValue, newValue));
}
}
53 changes: 53 additions & 0 deletions src/Testcontainers.Bigtable/BigtableConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace Testcontainers.Bigtable;

/// <inheritdoc cref="ContainerConfiguration"/>
[PublicAPI]
public sealed class BigtableConfiguration : ContainerConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="BigtableConfiguration" /> class.
/// </summary>
public BigtableConfiguration()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BigtableConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public BigtableConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
: base(resourceConfiguration)
{
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
}

/// <summary>
/// Initializes a new instance of the <see cref="BigtableConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public BigtableConfiguration(IContainerConfiguration resourceConfiguration)
: base(resourceConfiguration)
{
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
}

/// <summary>
/// Initializes a new instance of the <see cref="BigtableConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
public BigtableConfiguration(BigtableConfiguration resourceConfiguration)
: this(new BigtableConfiguration(), resourceConfiguration)
{
// Passes the configuration upwards to the base implementations to create an updated immutable copy.
}

/// <summary>
/// Initializes a new instance of the <see cref="BigtableConfiguration" /> class.
/// </summary>
/// <param name="oldValue">The old Docker resource configuration.</param>
/// <param name="newValue">The new Docker resource configuration.</param>
public BigtableConfiguration(BigtableConfiguration oldValue, BigtableConfiguration newValue)
: base(oldValue, newValue)
{
}
}
25 changes: 25 additions & 0 deletions src/Testcontainers.Bigtable/BigtableContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Testcontainers.Bigtable;

/// <inheritdoc cref="DockerContainer"/>
[PublicAPI]
public sealed class BigtableContainer : DockerContainer
{
/// <summary>
/// Initializes a new instance of the <see cref="BigtableContainer" /> class.
/// </summary>
/// <param name="configuration">The container configuration.</param>
/// <param name="logger">The logger.</param>
public BigtableContainer(IContainerConfiguration configuration, ILogger logger)
: base(configuration, logger)
{
}

/// <summary>
/// Gets the Bigtable emulator endpoint.
/// </summary>
/// <returns>The Bigtable emulator endpoint.</returns>
public string GetEmulatorEndpoint()
{
return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(BigtableBuilder.BigtablePort)).ToString();
}
}
13 changes: 13 additions & 0 deletions src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj"/>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions src/Testcontainers.Bigtable/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
global using System;
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;
7 changes: 4 additions & 3 deletions src/Testcontainers.WebDriver/WebDriverConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public WebDriverConfiguration(IResourceConfiguration<CreateContainerParameters>
/// Initializes a new instance of the <see cref="WebDriverConfiguration" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
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.
}
Expand All @@ -47,8 +48,8 @@ public WebDriverConfiguration(WebDriverConfiguration resourceConfiguration)
/// </summary>
/// <param name="oldValue">The old Docker resource configuration.</param>
/// <param name="newValue">The new Docker resource configuration.</param>
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);
}
Expand Down
1 change: 1 addition & 0 deletions tests/Testcontainers.Bigtable.Tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
60 changes: 60 additions & 0 deletions tests/Testcontainers.Bigtable.Tests/BigtableContainerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace Testcontainers.Bigtable;

public sealed class BigtableContainerTest : IAsyncLifetime
{
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()
{
// 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0"/>
<PackageReference Include="xunit" Version="2.5.0"/>
<PackageReference Include="Google.Cloud.Bigtable.Admin.V2" Version="3.7.0"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers.Bigtable/Testcontainers.Bigtable.csproj"/>
<ProjectReference Include="$(SolutionDir)tests/Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions tests/Testcontainers.Bigtable.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
global using System;
global using System.Threading.Tasks;
global using DotNet.Testcontainers.Commons;
global using Google.Cloud.Bigtable.Admin.V2;
global using Google.Cloud.Bigtable.Common.V2;
global using Grpc.Core;
global using Xunit;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected TarOutputMemoryStreamTest()
public void TestFileExistsInTarFile()
{
// Given
IList<string> actual = new List<string>();
var actual = new List<string>();

_tarOutputMemoryStream.Close();
_tarOutputMemoryStream.Seek(0, SeekOrigin.Begin);
Expand Down Expand Up @@ -97,7 +97,7 @@ public async Task TestFileExistsInContainer()

var targetDirectoryPath4 = string.Join("/", string.Empty, "tmp", Guid.NewGuid());

IList<string> targetFilePaths = new List<string>();
var targetFilePaths = new List<string>();
targetFilePaths.Add(targetFilePath1);
targetFilePaths.Add(targetFilePath2);
targetFilePaths.Add(string.Join("/", targetDirectoryPath1, _testFile.Name));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Testcontainers.PubSub;

public sealed class PubSubContainerTests : IAsyncLifetime
public sealed class PubSubContainerTest : IAsyncLifetime
{
private readonly PubSubContainer _pubSubContainer = new PubSubBuilder().Build();

Expand Down