Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ jobs:
{ name: "Testcontainers.Redpanda", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.ServiceBus", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Sftp", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Typesense", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Weaviate", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.WebDriver", runs-on: "ubuntu-22.04" },
{ name: "Testcontainers.Xunit", runs-on: "ubuntu-22.04" },
Expand Down
14 changes: 14 additions & 0 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ServiceBus",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Sftp", "src\Testcontainers.Sftp\Testcontainers.Sftp.csproj", "{7D5C6816-0DD2-4E13-A585-033B5D3C80D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Typesense", "src\Testcontainers.Typesense\Testcontainers.Typesense.csproj", "{E044A94A-3081-4EE4-8DC6-81601F96DA14}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Weaviate", "src\Testcontainers.Weaviate\Testcontainers.Weaviate.csproj", "{68F8600D-24E9-4E03-9E25-5F6EB338EAC1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver", "src\Testcontainers.WebDriver\Testcontainers.WebDriver.csproj", "{64A87DE5-29B0-4A54-9E74-560484D8C7C0}"
Expand Down Expand Up @@ -241,6 +243,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Sftp.Tests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tests\Testcontainers.Tests\Testcontainers.Tests.csproj", "{27CDB869-A150-4593-958F-6F26E5391E7C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Typesense.Tests", "tests\Testcontainers.Typesense.Tests\Testcontainers.Typesense.Tests.csproj", "{73CC8E45-5608-1398-4029-0802428B5565}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Weaviate.Tests", "tests\Testcontainers.Weaviate.Tests\Testcontainers.Weaviate.Tests.csproj", "{DDB41BC8-5826-4D97-9C5F-001151E3FFD6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.WebDriver.Tests", "tests\Testcontainers.WebDriver.Tests\Testcontainers.WebDriver.Tests.csproj", "{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2}"
Expand Down Expand Up @@ -455,6 +459,10 @@ Global
{7D5C6816-0DD2-4E13-A585-033B5D3C80D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D5C6816-0DD2-4E13-A585-033B5D3C80D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D5C6816-0DD2-4E13-A585-033B5D3C80D5}.Release|Any CPU.Build.0 = Release|Any CPU
{E044A94A-3081-4EE4-8DC6-81601F96DA14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E044A94A-3081-4EE4-8DC6-81601F96DA14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E044A94A-3081-4EE4-8DC6-81601F96DA14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E044A94A-3081-4EE4-8DC6-81601F96DA14}.Release|Any CPU.Build.0 = Release|Any CPU
{68F8600D-24E9-4E03-9E25-5F6EB338EAC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68F8600D-24E9-4E03-9E25-5F6EB338EAC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68F8600D-24E9-4E03-9E25-5F6EB338EAC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -711,6 +719,10 @@ Global
{27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.Build.0 = Release|Any CPU
{73CC8E45-5608-1398-4029-0802428B5565}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{73CC8E45-5608-1398-4029-0802428B5565}.Debug|Any CPU.Build.0 = Debug|Any CPU
{73CC8E45-5608-1398-4029-0802428B5565}.Release|Any CPU.ActiveCfg = Release|Any CPU
{73CC8E45-5608-1398-4029-0802428B5565}.Release|Any CPU.Build.0 = Release|Any CPU
{DDB41BC8-5826-4D97-9C5F-001151E3FFD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DDB41BC8-5826-4D97-9C5F-001151E3FFD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DDB41BC8-5826-4D97-9C5F-001151E3FFD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -782,6 +794,7 @@ Global
{45D6F69C-4D87-4130-AA90-0DB2F7460DAE} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{2E39E532-B81E-4B48-A004-FAE18EDF9E79} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{7D5C6816-0DD2-4E13-A585-033B5D3C80D5} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{E044A94A-3081-4EE4-8DC6-81601F96DA14} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{68F8600D-24E9-4E03-9E25-5F6EB338EAC1} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{64A87DE5-29B0-4A54-9E74-560484D8C7C0} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{380BB29B-F556-404D-B13B-CA250599C565} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand Down Expand Up @@ -846,6 +859,7 @@ Global
{232DD918-46ED-4BA8-B383-1A9146D83064} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{B73C3CC0-9F16-4B34-92BE-6EC0853912C5} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{73CC8E45-5608-1398-4029-0802428B5565} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{DDB41BC8-5826-4D97-9C5F-001151E3FFD6} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{EBA72C3B-57D5-43FF-A5B4-3D55B3B6D4C2} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{E901DF14-6F05-4FC2-825A-3055FAD33561} = {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 @@ -69,6 +69,7 @@ await moduleNameContainer.StartAsync();
| Redpanda | `docker.redpanda.com/redpandadata/redpanda:v22.2.1` | [NuGet](https://www.nuget.org/packages/Testcontainers.Redpanda) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Redpanda) |
| Sftp | `atmoz/sftp:alpine` | [NuGet](https://www.nuget.org/packages/Testcontainers.Sftp) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Sftp) |
| SQL Server | `mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04` | [NuGet](https://www.nuget.org/packages/Testcontainers.MsSql) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.MsSql) |
| Typesense | `typesense/typesense:28.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.Typesense) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Typesense) |
| Weaviate | `semitechnologies/weaviate:1.26.14` | [NuGet](https://www.nuget.org/packages/Testcontainers.Weaviate) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.Weaviate) |
| WebDriver | `selenium/standalone-chrome:110.0` | [NuGet](https://www.nuget.org/packages/Testcontainers.WebDriver) | [Source](https://github.com/testcontainers/testcontainers-dotnet/tree/develop/src/Testcontainers.WebDriver) |

Expand Down
1 change: 1 addition & 0 deletions src/Testcontainers.Typesense/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
12 changes: 12 additions & 0 deletions src/Testcontainers.Typesense/Testcontainers.Typesense.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" VersionOverride="2023.3.0" PrivateAssets="All"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Testcontainers/Testcontainers.csproj"/>
</ItemGroup>
</Project>
115 changes: 115 additions & 0 deletions src/Testcontainers.Typesense/TypesenseBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
namespace Testcontainers.Typesense;

/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
[PublicAPI]
public sealed class TypesenseBuilder : ContainerBuilder<TypesenseBuilder, TypesenseContainer, TypesenseConfiguration>
{
public const string TypesenseImage = "typesense/typesense:28.0";

public const ushort TypesensePort = 8108;

public const string DefaultDataDirectory = "/tmp";

public const string DefaultApiKey = "testcontainers";

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

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

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

/// <summary>
/// Sets the data directory.
/// </summary>
/// <param name="dataDirectoryPath">The data directory path.</param>
/// <returns>A configured instance of <see cref="TypesenseBuilder" />.</returns>
public TypesenseBuilder WithDataDirectory(string dataDirectoryPath)
{
return WithEnvironment("TYPESENSE_DATA_DIR", dataDirectoryPath);
}

/// <summary>
/// Sets the API key.
/// </summary>
/// <param name="apiKey">The API key.</param>
/// <returns>A configured instance of <see cref="TypesenseBuilder" />.</returns>
public TypesenseBuilder WithApiKey(string apiKey)
{
return WithEnvironment("TYPESENSE_API_KEY", apiKey);
}

/// <inheritdoc />
public override TypesenseContainer Build()
{
Validate();
return new TypesenseContainer(DockerResourceConfiguration);
}

/// <inheritdoc />
protected override TypesenseBuilder Init()
{
return base.Init()
.WithImage(TypesenseImage)
.WithPortBinding(TypesensePort, true)
.WithDataDirectory(DefaultDataDirectory)
.WithApiKey(DefaultApiKey)
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request =>
request.ForPort(TypesensePort).ForPath("/health").ForResponseMessageMatching(IsNodeReadyAsync)));
}

/// <inheritdoc />
protected override void Validate()
{
base.Validate();

_ = Guard.Argument(DockerResourceConfiguration.Environments["TYPESENSE_DATA_DIR"], "DataDirectory")
.NotNull()
.NotEmpty();

_ = Guard.Argument(DockerResourceConfiguration.Environments["TYPESENSE_API_KEY"], "ApiKey")
.NotNull()
.NotEmpty();
}

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

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

/// <inheritdoc />
protected override TypesenseBuilder Merge(TypesenseConfiguration oldValue, TypesenseConfiguration newValue)
{
return new TypesenseBuilder(new TypesenseConfiguration(oldValue, newValue));
}

private static async Task<bool> IsNodeReadyAsync(HttpResponseMessage response)
{
var content = await response.Content.ReadAsStringAsync()
.ConfigureAwait(false);

return "{\"ok\":true}".Equals(content, StringComparison.OrdinalIgnoreCase);
}
}
53 changes: 53 additions & 0 deletions src/Testcontainers.Typesense/TypesenseConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace Testcontainers.Typesense;

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

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

/// <summary>
/// Initializes a new instance of the <see cref="TypesenseConfiguration" /> class.
/// </summary>
/// <param name="oldValue">The old Docker resource configuration.</param>
/// <param name="newValue">The new Docker resource configuration.</param>
public TypesenseConfiguration(TypesenseConfiguration oldValue, TypesenseConfiguration newValue)
Comment thread
brainded marked this conversation as resolved.
: base(oldValue, newValue)
{
}
}
24 changes: 24 additions & 0 deletions src/Testcontainers.Typesense/TypesenseContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Testcontainers.Typesense;

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

/// <summary>
/// Gets the Typesense base address.
/// </summary>
/// <returns>The Typesense base address.</returns>
public string GetBaseAddress()
{
return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(TypesenseBuilder.TypesensePort)).ToString();
}
}
9 changes: 9 additions & 0 deletions src/Testcontainers.Typesense/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
global using System;
global using System.Net.Http;
global using System.Threading.Tasks;
global using Docker.DotNet.Models;
global using DotNet.Testcontainers;
global using DotNet.Testcontainers.Builders;
global using DotNet.Testcontainers.Configurations;
global using DotNet.Testcontainers.Containers;
global using JetBrains.Annotations;
1 change: 1 addition & 0 deletions tests/Testcontainers.Typesense.Tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net9.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit.v3"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers.Typesense/Testcontainers.Typesense.csproj"/>
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions tests/Testcontainers.Typesense.Tests/TypesenseContainerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Testcontainers.Typesense;

public sealed class TypesenseContainerTest : IAsyncLifetime
{
private readonly TypesenseContainer _typesenseContainer = new TypesenseBuilder().Build();

public async ValueTask InitializeAsync()
{
await _typesenseContainer.StartAsync()
.ConfigureAwait(false);
}

public ValueTask DisposeAsync()
{
return _typesenseContainer.DisposeAsync();
}

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task GetCollectionsReturnsEmptyArray()
{
// Given
using var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("X-TYPESENSE-API-KEY", TypesenseBuilder.DefaultApiKey);
httpClient.BaseAddress = new Uri(_typesenseContainer.GetBaseAddress());

// When
using var httpResponse = await httpClient.GetAsync("/collections", TestContext.Current.CancellationToken)
.ConfigureAwait(true);

var response = await httpResponse.Content.ReadAsStringAsync(TestContext.Current.CancellationToken)
.ConfigureAwait(true);

// Then
Assert.Equal("[]", response);
}
}
7 changes: 7 additions & 0 deletions tests/Testcontainers.Typesense.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
global using System;
global using System.Net.Http;
global using System.Text.Json;
global using System.Threading.Tasks;
global using DotNet.Testcontainers.Commons;
global using JetBrains.Annotations;
global using Xunit;