-
-
Notifications
You must be signed in to change notification settings - Fork 347
feat: Add Typesense module #1446
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4bd122e
feat: Add Typesense module with CI/CD configuration
brainded 3651b60
pull in cors and volume configs end to end
brainded 44a8bb2
Merge branch 'develop' into typesense
brainded da3eb2b
Merge branch 'develop' into typesense
HofmeisterAn 4be1df0
chore: Align Typesense module
HofmeisterAn ab3d0d5
Merge branch 'develop' into typesense
brainded File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| root = true |
12 changes: 12 additions & 0 deletions
12
src/Testcontainers.Typesense/Testcontainers.Typesense.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| : base(oldValue, newValue) | ||
| { | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| root = true |
18 changes: 18 additions & 0 deletions
18
tests/Testcontainers.Typesense.Tests/Testcontainers.Typesense.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
37
tests/Testcontainers.Typesense.Tests/TypesenseContainerTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.