-
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com>
- Loading branch information
1 parent
49c1fa4
commit 7808ac4
Showing
15 changed files
with
438 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
This file contains 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,168 @@ | ||
namespace Testcontainers.InfluxDb; | ||
|
||
/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" /> | ||
[PublicAPI] | ||
public sealed class InfluxDbBuilder : ContainerBuilder<InfluxDbBuilder, InfluxDbContainer, InfluxDbConfiguration> | ||
{ | ||
public const string InfluxDbImage = "influxdb:2.7"; | ||
|
||
public const ushort InfluxDbPort = 8086; | ||
|
||
public const string DefaultUsername = "username"; | ||
|
||
public const string DefaultPassword = "password"; | ||
|
||
public const string DefaultOrganization = "organization"; | ||
|
||
public const string DefaultBucket = "bucket"; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InfluxDbBuilder" /> class. | ||
/// </summary> | ||
public InfluxDbBuilder() | ||
: this(new InfluxDbConfiguration()) | ||
{ | ||
DockerResourceConfiguration = Init().DockerResourceConfiguration; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InfluxDbBuilder" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
private InfluxDbBuilder(InfluxDbConfiguration resourceConfiguration) | ||
: base(resourceConfiguration) | ||
{ | ||
DockerResourceConfiguration = resourceConfiguration; | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override InfluxDbConfiguration DockerResourceConfiguration { get; } | ||
|
||
/// <summary> | ||
/// Sets the InfluxDb username. | ||
/// </summary> | ||
/// <param name="username">The InfluxDb username.</param> | ||
/// <returns>A configured instance of <see cref="InfluxDbBuilder" />.</returns> | ||
public InfluxDbBuilder WithUsername(string username) | ||
{ | ||
return Merge(DockerResourceConfiguration, new InfluxDbConfiguration(username: username)) | ||
.WithEnvironment("DOCKER_INFLUXDB_INIT_USERNAME", username); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the InfluxDb password. | ||
/// </summary> | ||
/// <param name="password">The InfluxDb password.</param> | ||
/// <returns>A configured instance of <see cref="InfluxDbBuilder" />.</returns> | ||
public InfluxDbBuilder WithPassword(string password) | ||
{ | ||
return Merge(DockerResourceConfiguration, new InfluxDbConfiguration(password: password)) | ||
.WithEnvironment("DOCKER_INFLUXDB_INIT_PASSWORD", password); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the InfluxDb organization. | ||
/// </summary> | ||
/// <param name="organization">The InfluxDb organization.</param> | ||
/// <returns>A configured instance of <see cref="InfluxDbBuilder" />.</returns> | ||
public InfluxDbBuilder WithOrganization(string organization) | ||
{ | ||
return Merge(DockerResourceConfiguration, new InfluxDbConfiguration(organization: organization)) | ||
.WithEnvironment("DOCKER_INFLUXDB_INIT_ORG", organization); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the InfluxDb bucket. | ||
/// </summary> | ||
/// <param name="bucket">The InfluxDb bucket.</param> | ||
/// <returns>A configured instance of <see cref="InfluxDbBuilder" />.</returns> | ||
public InfluxDbBuilder WithBucket(string bucket) | ||
{ | ||
return Merge(DockerResourceConfiguration, new InfluxDbConfiguration(bucket: bucket)) | ||
.WithEnvironment("DOCKER_INFLUXDB_INIT_BUCKET", bucket); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the InfluxDb admin token. | ||
/// </summary> | ||
/// <param name="adminToken">The InfluxDb admin token.</param> | ||
/// <returns>A configured instance of <see cref="InfluxDbBuilder" />.</returns> | ||
public InfluxDbBuilder WithAdminToken(string adminToken) | ||
{ | ||
return Merge(DockerResourceConfiguration, new InfluxDbConfiguration(adminToken: adminToken)) | ||
.WithEnvironment("DOCKER_INFLUXDB_INIT_ADMIN_TOKEN", adminToken); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the InfluxDb retention. | ||
/// </summary> | ||
/// <param name="retention">The InfluxDb retention.</param> | ||
/// <returns>A configured instance of <see cref="InfluxDbBuilder" />.</returns> | ||
public InfluxDbBuilder WithRetention(string retention) | ||
{ | ||
return Merge(DockerResourceConfiguration, new InfluxDbConfiguration(retention: retention)) | ||
.WithEnvironment("DOCKER_INFLUXDB_INIT_RETENTION", retention); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override InfluxDbContainer Build() | ||
{ | ||
Validate(); | ||
return new InfluxDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override InfluxDbBuilder Init() | ||
{ | ||
return base.Init() | ||
.WithImage(InfluxDbImage) | ||
.WithPortBinding(InfluxDbPort, true) | ||
.WithEnvironment("DOCKER_INFLUXDB_INIT_MODE", "setup") | ||
.WithUsername(DefaultUsername) | ||
.WithPassword(DefaultPassword) | ||
.WithOrganization(DefaultOrganization) | ||
.WithBucket(DefaultBucket) | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request => | ||
request.ForPort(InfluxDbPort).ForPath("/ping").ForStatusCode(HttpStatusCode.NoContent))); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Validate() | ||
{ | ||
base.Validate(); | ||
|
||
_ = Guard.Argument(DockerResourceConfiguration.Username, nameof(DockerResourceConfiguration.Username)) | ||
.NotNull() | ||
.NotEmpty(); | ||
|
||
_ = Guard.Argument(DockerResourceConfiguration.Password, nameof(DockerResourceConfiguration.Password)) | ||
.NotNull() | ||
.NotEmpty(); | ||
|
||
_ = Guard.Argument(DockerResourceConfiguration.Organization, nameof(DockerResourceConfiguration.Organization)) | ||
.NotNull() | ||
.NotEmpty(); | ||
|
||
_ = Guard.Argument(DockerResourceConfiguration.Bucket, nameof(DockerResourceConfiguration.Bucket)) | ||
.NotNull() | ||
.NotEmpty(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override InfluxDbBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new InfluxDbConfiguration(resourceConfiguration)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override InfluxDbBuilder Clone(IContainerConfiguration resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new InfluxDbConfiguration(resourceConfiguration)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override InfluxDbBuilder Merge(InfluxDbConfiguration oldValue, InfluxDbConfiguration newValue) | ||
{ | ||
return new InfluxDbBuilder(new InfluxDbConfiguration(oldValue, newValue)); | ||
} | ||
} |
This file contains 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,107 @@ | ||
namespace Testcontainers.InfluxDb; | ||
|
||
/// <inheritdoc cref="ContainerConfiguration" /> | ||
[PublicAPI] | ||
public sealed class InfluxDbConfiguration : ContainerConfiguration | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InfluxDbConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="username">The InfluxDb username.</param> | ||
/// <param name="password">The InfluxDb password.</param> | ||
/// <param name="organization">The InfluxDb organization.</param> | ||
/// <param name="bucket">The InfluxDb bucket.</param> | ||
/// <param name="adminToken">The InfluxDb admin token.</param> | ||
/// <param name="retention">The InfluxDb retention.</param> | ||
public InfluxDbConfiguration( | ||
string username = null, | ||
string password = null, | ||
string organization = null, | ||
string bucket = null, | ||
string adminToken = null, | ||
string retention = null) | ||
{ | ||
Username = username; | ||
Password = password; | ||
Organization = organization; | ||
Bucket = bucket; | ||
AdminToken = adminToken; | ||
Retention = retention; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InfluxDbConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public InfluxDbConfiguration(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="InfluxDbConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public InfluxDbConfiguration(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="InfluxDbConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="resourceConfiguration">The Docker resource configuration.</param> | ||
public InfluxDbConfiguration(InfluxDbConfiguration resourceConfiguration) | ||
: this(new InfluxDbConfiguration(), resourceConfiguration) | ||
{ | ||
// Passes the configuration upwards to the base implementations to create an updated immutable copy. | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InfluxDbConfiguration" /> class. | ||
/// </summary> | ||
/// <param name="oldValue">The old Docker resource configuration.</param> | ||
/// <param name="newValue">The new Docker resource configuration.</param> | ||
public InfluxDbConfiguration(InfluxDbConfiguration oldValue, InfluxDbConfiguration newValue) | ||
: base(oldValue, newValue) | ||
{ | ||
Username = BuildConfiguration.Combine(oldValue.Username, newValue.Username); | ||
Password = BuildConfiguration.Combine(oldValue.Password, newValue.Password); | ||
Organization = BuildConfiguration.Combine(oldValue.Organization, newValue.Organization); | ||
Bucket = BuildConfiguration.Combine(oldValue.Bucket, newValue.Bucket); | ||
AdminToken = BuildConfiguration.Combine(oldValue.AdminToken, newValue.AdminToken); | ||
Retention = BuildConfiguration.Combine(oldValue.Retention, newValue.Retention); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the InfluxDb username. | ||
/// </summary> | ||
public string Username { get; } | ||
|
||
/// <summary> | ||
/// Gets the InfluxDb password. | ||
/// </summary> | ||
public string Password { get; } | ||
|
||
/// <summary> | ||
/// Gets the InfluxDb organization. | ||
/// </summary> | ||
public string Organization { get; } | ||
|
||
/// <summary> | ||
/// Gets the InfluxDb bucket. | ||
/// </summary> | ||
public string Bucket { get; } | ||
|
||
/// <summary> | ||
/// Gets the InfluxDb admin token. | ||
/// </summary> | ||
public string AdminToken { get; } | ||
|
||
/// <summary> | ||
/// Gets the InfluxDb retention. | ||
/// </summary> | ||
public string Retention { get; } | ||
} |
This file contains 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,25 @@ | ||
namespace Testcontainers.InfluxDb; | ||
|
||
/// <inheritdoc cref="DockerContainer" /> | ||
[PublicAPI] | ||
public sealed class InfluxDbContainer : DockerContainer | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InfluxDbContainer" /> class. | ||
/// </summary> | ||
/// <param name="configuration">The container configuration.</param> | ||
/// <param name="logger">The logger.</param> | ||
public InfluxDbContainer(InfluxDbConfiguration configuration, ILogger logger) | ||
: base(configuration, logger) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets the InfluxDb address. | ||
/// </summary> | ||
/// <returns>The InfluxDb address.</returns> | ||
public string GetAddress() | ||
{ | ||
return new UriBuilder(Uri.UriSchemeHttp, Hostname, GetMappedPublicPort(InfluxDbBuilder.InfluxDbPort)).ToString(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Testcontainers.InfluxDb/Testcontainers.InfluxDb.csproj
This file contains 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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/> | ||
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" PrivateAssets="All"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj"/> | ||
</ItemGroup> | ||
</Project> |
This file contains 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; | ||
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; |
Oops, something went wrong.