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 ArangoDB module #1058

Merged
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 @@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{7164F1FB
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ActiveMq", "src\Testcontainers.ActiveMq\Testcontainers.ActiveMq.csproj", "{5365F780-0E6C-41F0-B1B9-7DC34368F80C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ArangoDb", "src\Testcontainers.ArangoDb\Testcontainers.ArangoDb.csproj", "{AB9C1563-07C7-4685-BACD-BB1FF64B3611}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Azurite", "src\Testcontainers.Azurite\Testcontainers.Azurite.csproj", "{3F2E254F-C203-43FD-A078-DC3E2CBC0F9F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.BigQuery", "src\Testcontainers.BigQuery\Testcontainers.BigQuery.csproj", "{A9FF9C7F-BBA0-4B44-90B7-48A60F9E00F3}"
Expand Down Expand Up @@ -93,6 +95,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers", "src\Testc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ActiveMq.Tests", "tests\Testcontainers.ActiveMq.Tests\Testcontainers.ActiveMq.Tests.csproj", "{AB93C67F-0A53-4525-AE6C-29B065820ABE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ArangoDb.Tests", "tests\Testcontainers.ArangoDb.Tests\Testcontainers.ArangoDb.Tests.csproj", "{8E1E0A6D-EEBB-4455-B8E8-A55AF9B2062C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Azurite.Tests", "tests\Testcontainers.Azurite.Tests\Testcontainers.Azurite.Tests.csproj", "{B272FDDE-5E01-425D-B9E1-10FF883DDAAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.BigQuery.Tests", "tests\Testcontainers.BigQuery.Tests\Testcontainers.BigQuery.Tests.csproj", "{03E60673-078A-4508-99AD-8537CE6F78F1}"
Expand Down Expand Up @@ -192,6 +196,10 @@ Global
{5365F780-0E6C-41F0-B1B9-7DC34368F80C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5365F780-0E6C-41F0-B1B9-7DC34368F80C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5365F780-0E6C-41F0-B1B9-7DC34368F80C}.Release|Any CPU.Build.0 = Release|Any CPU
{AB9C1563-07C7-4685-BACD-BB1FF64B3611}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB9C1563-07C7-4685-BACD-BB1FF64B3611}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB9C1563-07C7-4685-BACD-BB1FF64B3611}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB9C1563-07C7-4685-BACD-BB1FF64B3611}.Release|Any CPU.Build.0 = Release|Any CPU
{3F2E254F-C203-43FD-A078-DC3E2CBC0F9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F2E254F-C203-43FD-A078-DC3E2CBC0F9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F2E254F-C203-43FD-A078-DC3E2CBC0F9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -348,6 +356,10 @@ Global
{AB93C67F-0A53-4525-AE6C-29B065820ABE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB93C67F-0A53-4525-AE6C-29B065820ABE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB93C67F-0A53-4525-AE6C-29B065820ABE}.Release|Any CPU.Build.0 = Release|Any CPU
{8E1E0A6D-EEBB-4455-B8E8-A55AF9B2062C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E1E0A6D-EEBB-4455-B8E8-A55AF9B2062C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E1E0A6D-EEBB-4455-B8E8-A55AF9B2062C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E1E0A6D-EEBB-4455-B8E8-A55AF9B2062C}.Release|Any CPU.Build.0 = Release|Any CPU
{B272FDDE-5E01-425D-B9E1-10FF883DDAAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B272FDDE-5E01-425D-B9E1-10FF883DDAAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B272FDDE-5E01-425D-B9E1-10FF883DDAAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -523,6 +535,7 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5365F780-0E6C-41F0-B1B9-7DC34368F80C} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{AB9C1563-07C7-4685-BACD-BB1FF64B3611} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{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}
Expand Down Expand Up @@ -562,6 +575,7 @@ Global
{64A87DE5-29B0-4A54-9E74-560484D8C7C0} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{EC76857B-A3B8-4B7A-A1B0-8D867A4D1733} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{AB93C67F-0A53-4525-AE6C-29B065820ABE} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{8E1E0A6D-EEBB-4455-B8E8-A55AF9B2062C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{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}
Expand Down
1 change: 1 addition & 0 deletions src/Testcontainers.ArangoDb/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
92 changes: 92 additions & 0 deletions src/Testcontainers.ArangoDb/ArangoDbBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
namespace Testcontainers.ArangoDb;

/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
[PublicAPI]
public sealed class ArangoDbBuilder : ContainerBuilder<ArangoDbBuilder, ArangoDbContainer, ArangoDbConfiguration>
{
public const string ArangoDbImage = "arangodb:3.11.5";

public const ushort ArangoDbPort = 8529;

public const string DefaultUsername = "root";

public const string DefaultPassword = "root";

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

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

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

/// <summary>
/// Sets the ArangoDb password.
/// </summary>
/// <param name="password">The ArangoDb password.</param>
/// <returns>A configured instance of <see cref="ArangoDbBuilder" />.</returns>
public ArangoDbBuilder WithPassword(string password)
{
return Merge(DockerResourceConfiguration, new ArangoDbConfiguration(password: password))
.WithEnvironment("ARANGO_ROOT_PASSWORD", password);
}

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

/// <inheritdoc />
protected override ArangoDbBuilder Init()
{
return base.Init()
.WithImage(ArangoDbImage)
.WithPortBinding(ArangoDbPort, true)
.WithPassword(DefaultPassword)
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Have fun!"));
}

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

_ = Guard.Argument(DockerResourceConfiguration.Password, nameof(DockerResourceConfiguration.Password))
.NotNull()
.NotEmpty();
}

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

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

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

/// <inheritdoc cref="ContainerConfiguration" />
[PublicAPI]
public sealed class ArangoDbConfiguration : ContainerConfiguration
{
/// <summary>
/// Initializes a new instance of the <see cref="ArangoDbConfiguration" /> class.
/// </summary>
/// <param name="password">The ArangoDb password.</param>
public ArangoDbConfiguration(
string password = null)
{
Password = password;
}

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

/// <summary>
/// Initializes a new instance of the <see cref="ArangoDbConfiguration" /> class.
/// </summary>
/// <param name="oldValue">The old Docker resource configuration.</param>
/// <param name="newValue">The new Docker resource configuration.</param>
public ArangoDbConfiguration(ArangoDbConfiguration oldValue, ArangoDbConfiguration newValue)
: base(oldValue, newValue)
{
Password = BuildConfiguration.Combine(oldValue.Password, newValue.Password);
}

/// <summary>
/// Gets the ArangoDb password.
/// </summary>
public string Password { get; }
}
25 changes: 25 additions & 0 deletions src/Testcontainers.ArangoDb/ArangoDbContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Testcontainers.ArangoDb;

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

/// <summary>
/// Gets the transport address.
/// </summary>
/// <returns>The transport address.</returns>
public string GetTransportAddress()
{
return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(ArangoDbBuilder.ArangoDbPort)).ToString();
}
}
12 changes: 12 additions & 0 deletions src/Testcontainers.ArangoDb/Testcontainers.ArangoDb.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj"/>
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions src/Testcontainers.ArangoDb/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global using System;
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;
global using Microsoft.Extensions.Logging;
1 change: 1 addition & 0 deletions tests/Testcontainers.ArangoDb.Tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
root = true
35 changes: 35 additions & 0 deletions tests/Testcontainers.ArangoDb.Tests/ArangoDbContainerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Testcontainers.ArangoDb;

public sealed class ArangoDbContainerTest : IAsyncLifetime
{
private readonly ArangoDbContainer _arangoDbContainer = new ArangoDbBuilder().Build();

public Task InitializeAsync()
{
return _arangoDbContainer.StartAsync();
}

public Task DisposeAsync()
{
return _arangoDbContainer.DisposeAsync().AsTask();
}

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task RetrievesDatabases()
{
// Given
var address = new Uri(_arangoDbContainer.GetTransportAddress());

using var transport = HttpApiTransport.UsingBasicAuth(address, ArangoDbBuilder.DefaultUsername, ArangoDbBuilder.DefaultPassword);

using var client = new ArangoDBClient(transport);

// When
var response = await client.Database.GetDatabasesAsync()
.ConfigureAwait(false);

// Then
Assert.Equal(HttpStatusCode.OK, response.Code);
}
}
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="ArangoDBNetStandard" Version="2.0.1"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers.ArangoDb/Testcontainers.ArangoDb.csproj"/>
<ProjectReference Include="$(SolutionDir)tests/Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions tests/Testcontainers.ArangoDb.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
global using System;
global using System.Net;
global using System.Threading.Tasks;
global using ArangoDBNetStandard;
global using ArangoDBNetStandard.Transport.Http;
global using DotNet.Testcontainers.Commons;
global using Xunit;