forked from testcontainers/testcontainers-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCockroachDbContainerTest.cs
More file actions
60 lines (49 loc) · 2.15 KB
/
CockroachDbContainerTest.cs
File metadata and controls
60 lines (49 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
namespace Testcontainers.CockroachDb;
public abstract class CockroachDbContainerTest(CockroachDbContainerTest.CockroachDbDefaultFixture fixture)
{
[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public void ConnectionStateReturnsOpen()
{
// Given
using DbConnection connection = fixture.CreateConnection();
// When
connection.Open();
// Then
Assert.Equal(ConnectionState.Open, connection.State);
}
[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task ExecScriptReturnsSuccessful()
{
// Given
const string scriptContent = "SELECT 1;";
// When
var execResult = await fixture.Container.ExecScriptAsync(scriptContent, TestContext.Current.CancellationToken)
.ConfigureAwait(true);
// Then
Assert.True(0L.Equals(execResult.ExitCode), execResult.Stderr);
Assert.Empty(execResult.Stderr);
}
public class CockroachDbDefaultFixture(IMessageSink messageSink)
: DbContainerFixture<CockroachDbBuilder, CockroachDbContainer>(messageSink)
{
protected override CockroachDbBuilder Configure()
=> new CockroachDbBuilder(TestSession.GetImageFromDockerfile());
public override DbProviderFactory DbProviderFactory
=> NpgsqlFactory.Instance;
}
[UsedImplicitly]
public class CockroachDbWaitForDatabaseFixture(IMessageSink messageSink)
: CockroachDbDefaultFixture(messageSink)
{
protected override CockroachDbBuilder Configure()
=> base.Configure().WithWaitStrategy(Wait.ForUnixContainer().UntilDatabaseIsAvailable(DbProviderFactory));
}
[UsedImplicitly]
public sealed class CockroachDbDefaultConfiguration(CockroachDbDefaultFixture fixture)
: CockroachDbContainerTest(fixture), IClassFixture<CockroachDbDefaultFixture>;
[UsedImplicitly]
public sealed class CockroachDbWaitForDatabaseConfiguration(CockroachDbWaitForDatabaseFixture fixture)
: CockroachDbContainerTest(fixture), IClassFixture<CockroachDbWaitForDatabaseFixture>;
}