简体   繁体   中英

.NET TestContainers does not indicate container creation

So I have a simple xunit integration test using TestContainers nuget package of version 2.3.0 to run Sql server in docker container.

The test looks like this:

[Fact]
public async Task TestDatabaseConnection()
{
    var container = new TestcontainersBuilder<MsSqlTestcontainer>()
        .WithDatabase(new MsSqlTestcontainerConfiguration
        {
            Password = "password",
        })
        .Build();
    await container.StartAsync();

    using var connection = new SqlConnection(container.ConnectionString);
    connection.Open();
    connection.State.Should().Be(System.Data.ConnectionState.Open);
}

But in container.StartAsync(); method I'm getting following DockerAPIException:

Docker.DotNet.DockerApiException: Docker API responded with status code=Conflict, response={"message":"Container 7b487d4475ece5c37e24f553a2f9d9c133a37636025b8731b22dea5022c628ca is not running"} .

Have you guys have any guess how to fix this?

Btw. In Docker Desktop I can see the container with the exact same Id as in Exception has been created, and at the end of the test removed.

Allright my bad. Password requirements was the problem:

/*
 * username is always `sa`
 * password will be used for the `sa` user
 *  - at least 8 characters in length
 *  - has at least 3 out of 4 categories of
 *    - has upper case alphabet
 *    - has lower case alphabet
 *    - has digit
 *    - has non-alphanumeric character
 * container does not allow automatic creation of an initial database
 * 
 * default image is mcr.microsoft.com/mssql/server:2017-latest-ubuntu 
 */

see documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM