Skip to content

Commit

Permalink
Add cleanup and container name to postgres db starter
Browse files Browse the repository at this point in the history
  • Loading branch information
amidgol committed Apr 15, 2021
1 parent f8c3991 commit ac313b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Expand Up @@ -14,7 +14,7 @@ namespace EvoMaster.DatabaseController.Containers
// credits to https://www.meziantou.net/2018/10/08/integration-testing-using-a-docker-container
internal abstract class DockerContainerBase
{
protected const string ContainerPrefix = "EvoMaster-DbContainer-";
protected const string ContainerPrefix = "EvoMaster-DB-";

protected DockerContainerBase(string imageName, string containerName)
{
Expand Down
@@ -1,4 +1,5 @@
using System.Data.Common;
using System;
using System.Data.Common;
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers.Builders;
using DotNet.Testcontainers.Containers.Configurations.Databases;
Expand All @@ -21,6 +22,7 @@ public PostgresDatabaseController(string databaseName, int port, string password
Timeout = timeout;
Password = password;
}

public string DatabaseName { get; }
public int Port { get; }
public int Timeout { get; }
Expand All @@ -29,13 +31,14 @@ public PostgresDatabaseController(string databaseName, int port, string password
public async Task<(string, DbConnection)> StartAsync()
{
var postgresBuilder = new TestcontainersBuilder<PostgreSqlTestcontainer>()
.WithName($"EvoMaster-DB-Postgres-{Guid.NewGuid()}")
.WithDatabase(new PostgreSqlTestcontainerConfiguration
{
Database = DatabaseName,
Username = "user",
Password = Password
})
.WithExposedPort(Port);
.WithExposedPort(Port).WithCleanUp(true);

_database = postgresBuilder.Build();
await _database.StartAsync();
Expand Down

0 comments on commit ac313b7

Please sign in to comment.