-
Notifications
You must be signed in to change notification settings - Fork 864
Expand file tree
/
Copy pathInfluxDBContainerFixture.cs
More file actions
39 lines (27 loc) · 1.12 KB
/
Copy pathInfluxDBContainerFixture.cs
File metadata and controls
39 lines (27 loc) · 1.12 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
using Testcontainers.InfluxDb;
namespace HealthChecks.InfluxDB.Tests;
public class InfluxDBContainerFixture : IAsyncLifetime
{
private const string Registry = "docker.io";
private const string Image = "library/influxdb";
private const string Tag = "2.7.12-alpine";
public InfluxDbContainer? Container { get; private set; }
public (string Address, string Username, string Password) GetConnectionProperties()
{
if (Container is null)
{
throw new InvalidOperationException("The test container was not initialized.");
}
return (Container.GetAddress(), InfluxDbBuilder.DefaultUsername, InfluxDbBuilder.DefaultPassword);
}
public async Task InitializeAsync() => Container = await CreateContainerAsync();
public Task DisposeAsync() => Container?.DisposeAsync().AsTask() ?? Task.CompletedTask;
private static async Task<InfluxDbContainer> CreateContainerAsync()
{
var container = new InfluxDbBuilder()
.WithImage($"{Registry}/{Image}:{Tag}")
.Build();
await container.StartAsync();
return container;
}
}