1
+ namespace Testcontainers . SqlEdge ;
2
+
3
+ /// <inheritdoc cref="ContainerBuilder{TBuilderEntity, TContainerEntity, TConfigurationEntity}" />
4
+ [ PublicAPI ]
5
+ public sealed class SqlEdgeBuilder : ContainerBuilder < SqlEdgeBuilder , SqlEdgeContainer , SqlEdgeConfiguration >
6
+ {
7
+ public const string SqlEdgeImage = "mcr.microsoft.com/azure-sql-edge:1.0.7" ;
8
+
9
+ public const ushort SqlEdgePort = 1433 ;
10
+
11
+ public const string DefaultDatabase = "master" ;
12
+
13
+ public const string DefaultUsername = "sa" ;
14
+
15
+ public const string DefaultPassword = "yourStrong(!)Password" ;
16
+
17
+ /// <summary>
18
+ /// Initializes a new instance of the <see cref="SqlEdgeBuilder" /> class.
19
+ /// </summary>
20
+ public SqlEdgeBuilder ( )
21
+ : this ( new SqlEdgeConfiguration ( ) )
22
+ {
23
+ DockerResourceConfiguration = Init ( ) . DockerResourceConfiguration ;
24
+ }
25
+
26
+ /// <summary>
27
+ /// Initializes a new instance of the <see cref="SqlEdgeBuilder" /> class.
28
+ /// </summary>
29
+ /// <param name="resourceConfiguration">The Docker resource configuration.</param>
30
+ private SqlEdgeBuilder ( SqlEdgeConfiguration resourceConfiguration )
31
+ : base ( resourceConfiguration )
32
+ {
33
+ DockerResourceConfiguration = resourceConfiguration ;
34
+ }
35
+
36
+ /// <inheritdoc />
37
+ protected override SqlEdgeConfiguration DockerResourceConfiguration { get ; }
38
+
39
+ /// <summary>
40
+ /// Sets the SqlEdge password.
41
+ /// </summary>
42
+ /// <param name="password">The SqlEdge password.</param>
43
+ /// <returns>A configured instance of <see cref="SqlEdgeBuilder" />.</returns>
44
+ public SqlEdgeBuilder WithPassword ( string password )
45
+ {
46
+ return Merge ( DockerResourceConfiguration , new SqlEdgeConfiguration ( password : password ) )
47
+ . WithEnvironment ( "MSSQL_SA_PASSWORD" , password ) ;
48
+ }
49
+
50
+ /// <inheritdoc />
51
+ public override SqlEdgeContainer Build ( )
52
+ {
53
+ Validate ( ) ;
54
+ return new SqlEdgeContainer ( DockerResourceConfiguration , TestcontainersSettings . Logger ) ;
55
+ }
56
+
57
+ /// <inheritdoc />
58
+ protected override SqlEdgeBuilder Init ( )
59
+ {
60
+ return base . Init ( )
61
+ . WithImage ( SqlEdgeImage )
62
+ . WithPortBinding ( SqlEdgePort , true )
63
+ . WithEnvironment ( "ACCEPT_EULA" , "Y" )
64
+ . WithDatabase ( DefaultDatabase )
65
+ . WithUsername ( DefaultUsername )
66
+ . WithPassword ( DefaultPassword )
67
+ . WithWaitStrategy ( Wait . ForUnixContainer ( ) . AddCustomWaitStrategy ( new WaitUntil ( ) ) ) ;
68
+ }
69
+
70
+ /// <inheritdoc />
71
+ protected override void Validate ( )
72
+ {
73
+ base . Validate ( ) ;
74
+
75
+ _ = Guard . Argument ( DockerResourceConfiguration . Password , nameof ( DockerResourceConfiguration . Password ) )
76
+ . NotNull ( )
77
+ . NotEmpty ( ) ;
78
+ }
79
+
80
+ /// <inheritdoc />
81
+ protected override SqlEdgeBuilder Clone ( IResourceConfiguration < CreateContainerParameters > resourceConfiguration )
82
+ {
83
+ return Merge ( DockerResourceConfiguration , new SqlEdgeConfiguration ( resourceConfiguration ) ) ;
84
+ }
85
+
86
+ /// <inheritdoc />
87
+ protected override SqlEdgeBuilder Clone ( IContainerConfiguration resourceConfiguration )
88
+ {
89
+ return Merge ( DockerResourceConfiguration , new SqlEdgeConfiguration ( resourceConfiguration ) ) ;
90
+ }
91
+
92
+ /// <inheritdoc />
93
+ protected override SqlEdgeBuilder Merge ( SqlEdgeConfiguration oldValue , SqlEdgeConfiguration newValue )
94
+ {
95
+ return new SqlEdgeBuilder ( new SqlEdgeConfiguration ( oldValue , newValue ) ) ;
96
+ }
97
+
98
+ /// <summary>
99
+ /// Sets the SqlEdge database.
100
+ /// </summary>
101
+ /// <remarks>
102
+ /// The Docker image does not allow to configure the database.
103
+ /// </remarks>
104
+ /// <param name="database">The SqlEdge database.</param>
105
+ /// <returns>A configured instance of <see cref="SqlEdgeBuilder" />.</returns>
106
+ private SqlEdgeBuilder WithDatabase ( string database )
107
+ {
108
+ return Merge ( DockerResourceConfiguration , new SqlEdgeConfiguration ( database : database ) ) ;
109
+ }
110
+
111
+ /// <summary>
112
+ /// Sets the SqlEdge username.
113
+ /// </summary>
114
+ /// <remarks>
115
+ /// The Docker image does not allow to configure the username.
116
+ /// </remarks>
117
+ /// <param name="username">The SqlEdge username.</param>
118
+ /// <returns>A configured instance of <see cref="SqlEdgeBuilder" />.</returns>
119
+ private SqlEdgeBuilder WithUsername ( string username )
120
+ {
121
+ return Merge ( DockerResourceConfiguration , new SqlEdgeConfiguration ( username : username ) ) ;
122
+ }
123
+
124
+ /// <inheritdoc cref="IWaitUntil" />
125
+ private sealed class WaitUntil : IWaitUntil
126
+ {
127
+ /// <inheritdoc />
128
+ public async Task < bool > UntilAsync ( IContainer container )
129
+ {
130
+ var ( stdout , _) = await container . GetLogs ( timestampsEnabled : false )
131
+ . ConfigureAwait ( false ) ;
132
+
133
+ return stdout . Contains ( "Recovery is complete." ) ;
134
+ }
135
+ }
136
+ }
0 commit comments