-
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added pre-configured database PostgreSql, part of #45.
- Loading branch information
1 parent
8d83d9e
commit 95729ac
Showing
11 changed files
with
193 additions
and
80 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/DotNet.Testcontainers.Tests/Unit/DatabaseContainerTest.cs
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,28 @@ | ||
namespace DotNet.Testcontainers.Tests.Unit | ||
{ | ||
using System.Threading.Tasks; | ||
using DotNet.Testcontainers.Core.Builder; | ||
using DotNet.Testcontainers.Core.Containers.Database; | ||
using Xunit; | ||
|
||
public class DatabaseContainerTest | ||
{ | ||
[Fact] | ||
public async Task PostgreSqlContainer() | ||
{ | ||
var database = string.Empty; | ||
|
||
var username = string.Empty; | ||
|
||
var password = string.Empty; | ||
|
||
var testcontainersBuilder = new TestcontainersBuilder<PostgreSqlContainer>() | ||
.WithDatabase(database, username, password); | ||
|
||
using (var testcontainer = testcontainersBuilder.Build()) | ||
{ | ||
await testcontainer.StartAsync(); | ||
} | ||
} | ||
} | ||
} |
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
79 changes: 41 additions & 38 deletions
79
src/DotNet.Testcontainers/Core/Builder/ITestcontainersBuilder.cs
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 |
---|---|---|
@@ -1,146 +1,149 @@ | ||
namespace DotNet.Testcontainers.Core.Builder | ||
{ | ||
using System; | ||
using DotNet.Testcontainers.Core.Containers; | ||
using DotNet.Testcontainers.Core.Images; | ||
using DotNet.Testcontainers.Diagnostics; | ||
|
||
public interface ITestcontainersBuilder | ||
public interface ITestcontainersBuilder<T> | ||
{ | ||
ITestcontainersBuilder<T> ConfigureContainer(Action<T> configureContainer); | ||
|
||
/// <summary> | ||
/// Sets the Docker image, which is used to create the Testcontainer instances. | ||
/// </summary> | ||
/// <param name="image">Docker image name.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithImage(string image); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithImage(string image); | ||
|
||
/// <summary> | ||
/// Sets the Docker image, which is used to create the Testcontainer instances. | ||
/// </summary> | ||
/// <param name="image">Docker image instance.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithImage(IDockerImage image); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithImage(IDockerImage image); | ||
|
||
/// <summary> | ||
/// Sets the name of the Testcontainer. | ||
/// </summary> | ||
/// <param name="name">Testcontainers name.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithName(string name); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithName(string name); | ||
|
||
/// <summary> | ||
/// Overrides the working directory of the Testcontainer for the instruction sets. | ||
/// </summary> | ||
/// <param name="workingDirectory">Working directory.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithWorkingDirectory(string workingDirectory); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithWorkingDirectory(string workingDirectory); | ||
|
||
/// <summary> | ||
/// Overrides the entrypoint of the Testcontainer to configure an executable. | ||
/// </summary> | ||
/// <param name="entrypoint">Entrypoint executable.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithEntrypoint(params string[] entrypoint); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithEntrypoint(params string[] entrypoint); | ||
|
||
/// <summary> | ||
/// Overrides the command of the Testcontainer to provide defaults for an executing. | ||
/// </summary> | ||
/// <param name="command">List of commands, "executable", "param1", "param2" or "param1", "param2".</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithCommand(params string[] command); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithCommand(params string[] command); | ||
|
||
/// <summary> | ||
/// Exports the environment variable in the Testcontainer. | ||
/// </summary> | ||
/// <param name="name">Environment variable name.</param> | ||
/// <param name="value">Environment variable value.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithEnvironment(string name, string value); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithEnvironment(string name, string value); | ||
|
||
/// <summary> | ||
/// Adds an user-defined metadata to the Testcontainer. | ||
/// </summary> | ||
/// <param name="name">Label name.</param> | ||
/// <param name="value">Label value.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithLabel(string name, string value); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithLabel(string name, string value); | ||
|
||
/// <summary> | ||
/// Sets the port of the Testcontainer to expose, without publishing the port to the host system’s interfaces. | ||
/// </summary> | ||
/// <param name="port">Port to expose.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithExposedPort(int port); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithExposedPort(int port); | ||
|
||
/// <summary> | ||
/// Exposes the port of the Testcontainer, without publishing the port to the host system’s interfaces. | ||
/// </summary> | ||
/// <param name="port">Port to expose.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithExposedPort(string port); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithExposedPort(string port); | ||
|
||
/// <summary> | ||
/// Binds the port of the Testcontainer to the same port of the host machine. | ||
/// </summary> | ||
/// <param name="port">Port to bind between Testcontainer and host machine.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithPortBinding(int port); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithPortBinding(int port); | ||
|
||
/// <summary> | ||
/// Binds the port of the Testcontainer to the specified port of the host machine. | ||
/// </summary> | ||
/// <param name="hostPort">Port of the host machine.</param> | ||
/// <param name="containerPort">Port of the Testcontainer.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithPortBinding(int hostPort, int containerPort); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithPortBinding(int hostPort, int containerPort); | ||
|
||
/// <summary> | ||
/// Binds the port of the Testcontainer to the same port of the host machine. | ||
/// </summary> | ||
/// <param name="port">Port to bind between Testcontainer and host machine.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithPortBinding(string port); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithPortBinding(string port); | ||
|
||
/// <summary> | ||
/// Binds the port of the Testcontainer to the specified port of the host machine. | ||
/// </summary> | ||
/// <param name="hostPort">Port of the host machine.</param> | ||
/// <param name="containerPort">Port of the Testcontainer.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithPortBinding(string hostPort, string containerPort); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithPortBinding(string hostPort, string containerPort); | ||
|
||
/// <summary> | ||
/// Binds and mounts the specified host machine volume into the Testcontainer. | ||
/// </summary> | ||
/// <param name="source">An absolute path or a name value within the host machine.</param> | ||
/// <param name="destination">An absolute path as destination in the container.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithMount(string source, string destination); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithMount(string source, string destination); | ||
|
||
/// <summary> | ||
/// If true, Testcontainer will remove the Testcontainer on finalize. Otherwise, Testcontainer will keep the Testcontainer. | ||
/// </summary> | ||
/// <param name="cleanUp">True, Testcontainer will remove the Testcontainer on finalize. Otherwise, Testcontainer will keep it.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithCleanUp(bool cleanUp); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithCleanUp(bool cleanUp); | ||
|
||
/// <summary> | ||
/// Sets the output consumer to capture the Testcontainer stdout and stderr messages. | ||
/// </summary> | ||
/// <param name="outputConsumer">Output consumer to capture stdout and strerr.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithOutputConsumer(IOutputConsumer outputConsumer); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithOutputConsumer(IOutputConsumer outputConsumer); | ||
|
||
/// <summary> | ||
/// Sets the wait strategy to complete the Testcontainer asynchronous start task. | ||
/// </summary> | ||
/// <param name="waitStrategy">Wait strategy to complete the Testcontainer start, default wait strategy implementation <see cref="DefaultWaitStrategy"/>.</param> | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder"/>.</returns> | ||
ITestcontainersBuilder WithWaitStrategy(WaitStrategy waitStrategy); | ||
/// <returns>A configured instance of <see cref="ITestcontainersBuilder{T}"/>.</returns> | ||
ITestcontainersBuilder<T> WithWaitStrategy(WaitStrategy waitStrategy); | ||
|
||
/// <summary> | ||
/// Builds the instance of <see cref="IDockerContainer"/> with the given configuration. | ||
/// </summary> | ||
/// <returns>A configured instance of <see cref="IDockerContainer"/>.</returns> | ||
IDockerContainer Build(); | ||
T Build(); | ||
} | ||
} |
Oops, something went wrong.