-
-
Notifications
You must be signed in to change notification settings - Fork 341
feat: Add Weaviate module #1356
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 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a6703de
Add Testcontainers.Weaviate
roji bd5da22
Address review comments
roji 4d061ed
Switch to global usings
roji 718772a
chore: Remove UTF-8 BOM
HofmeisterAn 0c5d82b
chore: Align with repo standards
HofmeisterAn eabc1fd
chore: Update csproj
HofmeisterAn 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
12 changes: 12 additions & 0 deletions
12
src/Testcontainers.Weaviate/Testcontainers.Weaviate.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,51 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using Docker.DotNet.Models; | ||
| using DotNet.Testcontainers.Builders; | ||
| using DotNet.Testcontainers.Configurations; | ||
|
|
||
| namespace Testcontainers.Weaviate; | ||
|
|
||
| public sealed class WeaviateBuilder : ContainerBuilder<WeaviateBuilder, WeaviateContainer, WeaviateConfiguration> | ||
| { | ||
| public const string WeaviateImage = "semitechnologies/weaviate:1.26.14"; | ||
|
|
||
| public const ushort WeaviateHttpPort = 8080; | ||
|
|
||
| public const ushort WeaviateGrpcPort = 50051; | ||
|
|
||
| public WeaviateBuilder() : this(new WeaviateConfiguration()) | ||
| => DockerResourceConfiguration = Init().DockerResourceConfiguration; | ||
|
|
||
| private WeaviateBuilder(WeaviateConfiguration dockerResourceConfiguration) : base(dockerResourceConfiguration) | ||
| => DockerResourceConfiguration = dockerResourceConfiguration; | ||
|
|
||
| public override WeaviateContainer Build() | ||
| { | ||
| Validate(); | ||
| return new WeaviateContainer(DockerResourceConfiguration); | ||
| } | ||
|
|
||
| protected override WeaviateBuilder Init() | ||
| => base.Init() | ||
| .WithImage(WeaviateImage) | ||
| .WithPortBinding(WeaviateHttpPort, true) | ||
| .WithPortBinding(WeaviateGrpcPort, true) | ||
| .WithEnvironment("AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED", "true") | ||
| .WithEnvironment("PERSISTENCE_DATA_PATH", "/var/lib/weaviate") | ||
| .WithWaitStrategy(Wait.ForUnixContainer() | ||
| .UntilPortIsAvailable(WeaviateHttpPort) | ||
| .UntilPortIsAvailable(WeaviateGrpcPort) | ||
| .UntilHttpRequestIsSucceeded(r => r.ForPath("/v1/.well-known/ready").ForPort(WeaviateHttpPort))); | ||
|
|
||
| protected override WeaviateBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
| => Merge(DockerResourceConfiguration, new WeaviateConfiguration(resourceConfiguration)); | ||
|
|
||
| protected override WeaviateBuilder Merge(WeaviateConfiguration oldValue, WeaviateConfiguration newValue) | ||
| => new(new WeaviateConfiguration(oldValue, newValue)); | ||
|
|
||
| protected override WeaviateConfiguration DockerResourceConfiguration { get; } | ||
|
|
||
| protected override WeaviateBuilder Clone(IContainerConfiguration resourceConfiguration) | ||
| => Merge(DockerResourceConfiguration, new WeaviateConfiguration(resourceConfiguration)); | ||
| } | ||
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 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using Docker.DotNet.Models; | ||
| using DotNet.Testcontainers.Configurations; | ||
roji marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace Testcontainers.Weaviate; | ||
|
|
||
| public sealed class WeaviateConfiguration : ContainerConfiguration | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="WeaviateConfiguration" /> class. | ||
| /// </summary> | ||
| public WeaviateConfiguration() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="WeaviateConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| public WeaviateConfiguration(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
| : base(resourceConfiguration) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="WeaviateConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| public WeaviateConfiguration(IContainerConfiguration resourceConfiguration) | ||
| : base(resourceConfiguration) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="WeaviateConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
| public WeaviateConfiguration(WeaviateConfiguration resourceConfiguration) | ||
| : this(new WeaviateConfiguration(), resourceConfiguration) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="WeaviateConfiguration" /> class. | ||
| /// </summary> | ||
| /// <param name="oldValue">The old Docker resource configuration.</param> | ||
| /// <param name="newValue">The new Docker resource configuration.</param> | ||
| public WeaviateConfiguration(WeaviateConfiguration oldValue, WeaviateConfiguration 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,7 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using DotNet.Testcontainers.Containers; | ||
roji marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace Testcontainers.Weaviate; | ||
|
|
||
| public class WeaviateContainer(WeaviateConfiguration configuration) : DockerContainer(configuration); | ||
19 changes: 19 additions & 0 deletions
19
tests/Testcontainers.Weaviate.Tests/Testcontainers.Weaviate.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,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>net9.0</TargetFrameworks> | ||
| <IsPackable>false</IsPackable> | ||
| <IsPublishable>false</IsPublishable> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <!-- -8<- [start:PackageReferences] --> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk"/> | ||
| <PackageReference Include="coverlet.collector"/> | ||
| <PackageReference Include="xunit.runner.visualstudio"/> | ||
| <PackageReference Include="xunit"/> | ||
| <!-- -8<- [end:PackageReferences] --> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="../../src/Testcontainers.Weaviate/Testcontainers.Weaviate.csproj"/> | ||
| <ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/> | ||
| </ItemGroup> | ||
| </Project> |
28 changes: 28 additions & 0 deletions
28
tests/Testcontainers.Weaviate.Tests/WeaviateContainerTest.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,28 @@ | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Threading.Tasks; | ||
| using DotNet.Testcontainers.Commons; | ||
| using Xunit; | ||
roji marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| namespace Testcontainers.Weaviate; | ||
|
|
||
| public sealed class WeaviateContainerTest : IAsyncLifetime | ||
| { | ||
| // # --8<-- [start:UseWeaviateContainer] | ||
| private readonly WeaviateContainer _weaviateContainer = new WeaviateBuilder().Build(); | ||
|
|
||
| public Task InitializeAsync() => _weaviateContainer.StartAsync(); | ||
| public Task DisposeAsync() => _weaviateContainer.DisposeAsync().AsTask(); | ||
|
|
||
| [Fact] | ||
| [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] | ||
| public async Task ListCollections() | ||
| { | ||
| var client = new HttpClient(); | ||
| var response = await client.GetAsync( | ||
| $"http://{_weaviateContainer.Hostname}:{_weaviateContainer.GetMappedPublicPort(WeaviateBuilder.WeaviateHttpPort)}/v1/schema"); | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| } | ||
| // # --8<-- [end:UseWeaviateContainer] | ||
| } | ||
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.