-
-
Notifications
You must be signed in to change notification settings - Fork 286
/
AzuriteBuilder.cs
125 lines (103 loc) · 4.36 KB
/
AzuriteBuilder.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
namespace Testcontainers.Azurite;
/// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
[PublicAPI]
public sealed class AzuriteBuilder : ContainerBuilder<AzuriteBuilder, AzuriteContainer, AzuriteConfiguration>
{
public const string AzuriteImage = "mcr.microsoft.com/azure-storage/azurite:3.28.0";
public const ushort BlobPort = 10000;
public const ushort QueuePort = 10001;
public const ushort TablePort = 10002;
public const string AccountName = "devstoreaccount1";
public const string AccountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
private static readonly ISet<AzuriteService> EnabledServices = new HashSet<AzuriteService>();
static AzuriteBuilder()
{
EnabledServices.Add(AzuriteService.Blob);
EnabledServices.Add(AzuriteService.Queue);
EnabledServices.Add(AzuriteService.Table);
}
/// <summary>
/// Initializes a new instance of the <see cref="AzuriteBuilder" /> class.
/// </summary>
public AzuriteBuilder()
: this(new AzuriteConfiguration())
{
DockerResourceConfiguration = Init().DockerResourceConfiguration;
}
/// <summary>
/// Initializes a new instance of the <see cref="AzuriteBuilder" /> class.
/// </summary>
/// <param name="resourceConfiguration">The Docker resource configuration.</param>
private AzuriteBuilder(AzuriteConfiguration resourceConfiguration)
: base(resourceConfiguration)
{
DockerResourceConfiguration = resourceConfiguration;
}
/// <inheritdoc />
protected override AzuriteConfiguration DockerResourceConfiguration { get; }
/// <summary>
/// Enables in-memory persistence.
/// </summary>
/// <remarks>
/// By default, the in-memory is limited to 50% of the total memory on the container.
/// </remarks>
/// <param name="megabytes">An optional in-memory limit in megabytes.</param>
/// <returns>A configured instance of <see cref="AzuriteBuilder" />.</returns>
public AzuriteBuilder WithInMemoryPersistence(float? megabytes = null)
{
if (megabytes.HasValue)
{
return WithCommand("--inMemoryPersistence", "--extentMemoryLimit", megabytes.ToString());
}
else
{
return WithCommand("--inMemoryPersistence");
}
}
/// <inheritdoc />
public override AzuriteContainer Build()
{
Validate();
var waitStrategy = Wait.ForUnixContainer();
if (EnabledServices.Contains(AzuriteService.Blob))
{
waitStrategy = waitStrategy.UntilMessageIsLogged("Blob service is successfully listening");
}
if (EnabledServices.Contains(AzuriteService.Queue))
{
waitStrategy = waitStrategy.UntilMessageIsLogged("Queue service is successfully listening");
}
if (EnabledServices.Contains(AzuriteService.Table))
{
waitStrategy = waitStrategy.UntilMessageIsLogged("Table service is successfully listening");
}
var azuriteBuilder = DockerResourceConfiguration.WaitStrategies.Count() > 1 ? this : WithWaitStrategy(waitStrategy);
return new AzuriteContainer(azuriteBuilder.DockerResourceConfiguration);
}
/// <inheritdoc />
protected override AzuriteBuilder Init()
{
return base.Init()
.WithImage(AzuriteImage)
.WithPortBinding(BlobPort, true)
.WithPortBinding(QueuePort, true)
.WithPortBinding(TablePort, true)
.WithEntrypoint("azurite")
.WithCommand("--blobHost", "0.0.0.0", "--queueHost", "0.0.0.0", "--tableHost", "0.0.0.0");
}
/// <inheritdoc />
protected override AzuriteBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new AzuriteConfiguration(resourceConfiguration));
}
/// <inheritdoc />
protected override AzuriteBuilder Clone(IContainerConfiguration resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new AzuriteConfiguration(resourceConfiguration));
}
/// <inheritdoc />
protected override AzuriteBuilder Merge(AzuriteConfiguration oldValue, AzuriteConfiguration newValue)
{
return new AzuriteBuilder(new AzuriteConfiguration(oldValue, newValue));
}
}