@@ -188,18 +188,26 @@ public void WithMySqlTwiceEndsUpWithOneAdminContainer()
188
188
Assert . Single ( builder . Resources . OfType < PhpMyAdminContainerResource > ( ) ) ;
189
189
}
190
190
191
- [ Fact ]
192
- public async Task SingleMySqlInstanceProducesCorrectMySqlHostsVariable ( )
191
+ [ Theory ]
192
+ [ InlineData ( null , "host.docker.internal" ) ]
193
+ [ InlineData ( "host.containers.internal" , "host.containers.internal" ) ]
194
+ public async Task SingleMySqlInstanceProducesCorrectMySqlHostsVariable ( string ? containerHost , string expectedHost )
193
195
{
194
196
var builder = DistributedApplication . CreateBuilder ( ) ;
197
+
198
+ if ( containerHost is not null )
199
+ {
200
+ builder . Configuration [ "AppHost:ContainerHostname" ] = containerHost ;
201
+ }
202
+
195
203
var mysql = builder . AddMySql ( "mySql" ) . WithPhpMyAdmin ( ) ;
196
204
using var app = builder . Build ( ) ;
197
205
198
206
// Add fake allocated endpoints.
199
- mysql . WithAnnotation ( new AllocatedEndpointAnnotation ( "tcp" , ProtocolType . Tcp , "host.docker.internal " , 5001 , "tcp" ) ) ;
207
+ mysql . WithAnnotation ( new AllocatedEndpointAnnotation ( "tcp" , ProtocolType . Tcp , "localhost " , 5001 , "tcp" ) ) ;
200
208
201
209
var model = app . Services . GetRequiredService < DistributedApplicationModel > ( ) ;
202
- var hook = new PhpMyAdminConfigWriterHook ( ) ;
210
+ var hook = new PhpMyAdminConfigWriterHook ( builder . Configuration ) ;
203
211
await hook . AfterEndpointsAllocatedAsync ( model , CancellationToken . None ) ;
204
212
205
213
var myAdmin = builder . Resources . Single ( r => r . Name . EndsWith ( "-phpmyadmin" ) ) ;
@@ -215,7 +223,7 @@ public async Task SingleMySqlInstanceProducesCorrectMySqlHostsVariable()
215
223
annotation . Callback ( context ) ;
216
224
}
217
225
218
- Assert . Equal ( "host.docker.internal :5001", context . EnvironmentVariables [ "PMA_HOST" ] ) ;
226
+ Assert . Equal ( $ " { expectedHost } :5001", context . EnvironmentVariables [ "PMA_HOST" ] ) ;
219
227
Assert . NotNull ( context . EnvironmentVariables [ "PMA_USER" ] ) ;
220
228
Assert . NotNull ( context . EnvironmentVariables [ "PMA_PASSWORD" ] ) ;
221
229
}
@@ -233,32 +241,40 @@ public void WithPhpMyAdminAddsContainer()
233
241
Assert . Equal ( "/etc/phpmyadmin/config.user.inc.php" , volume . Target ) ;
234
242
}
235
243
236
- [ Fact ]
237
- public void WithPhpMyAdminProducesValidServerConfigFile ( )
244
+ [ Theory ]
245
+ [ InlineData ( null , "host.docker.internal" ) ]
246
+ [ InlineData ( "host.containers.internal" , "host.containers.internal" ) ]
247
+ public void WithPhpMyAdminProducesValidServerConfigFile ( string ? containerHost , string expectedHost )
238
248
{
239
249
var builder = DistributedApplication . CreateBuilder ( ) ;
250
+
251
+ if ( containerHost is not null )
252
+ {
253
+ builder . Configuration [ "AppHost:ContainerHostname" ] = containerHost ;
254
+ }
255
+
240
256
var mysql1 = builder . AddMySql ( "mysql1" ) . WithPhpMyAdmin ( 8081 ) ;
241
257
var mysql2 = builder . AddMySql ( "mysql2" ) . WithPhpMyAdmin ( 8081 ) ;
242
258
243
259
// Add fake allocated endpoints.
244
- mysql1 . WithAnnotation ( new AllocatedEndpointAnnotation ( "tcp" , ProtocolType . Tcp , "host.docker.internal " , 5001 , "tcp" ) ) ;
245
- mysql2 . WithAnnotation ( new AllocatedEndpointAnnotation ( "tcp" , ProtocolType . Tcp , "host.docker.internal " , 5002 , "tcp" ) ) ;
260
+ mysql1 . WithAnnotation ( new AllocatedEndpointAnnotation ( "tcp" , ProtocolType . Tcp , "localhost " , 5001 , "tcp" ) ) ;
261
+ mysql2 . WithAnnotation ( new AllocatedEndpointAnnotation ( "tcp" , ProtocolType . Tcp , "localhost " , 5002 , "tcp" ) ) ;
246
262
247
263
var myAdmin = builder . Resources . Single ( r => r . Name . EndsWith ( "-phpmyadmin" ) ) ;
248
264
var volume = myAdmin . Annotations . OfType < ContainerMountAnnotation > ( ) . Single ( ) ;
249
265
250
266
using var app = builder . Build ( ) ;
251
267
var appModel = app . Services . GetRequiredService < DistributedApplicationModel > ( ) ;
252
268
253
- var hook = new PhpMyAdminConfigWriterHook ( ) ;
269
+ var hook = new PhpMyAdminConfigWriterHook ( builder . Configuration ) ;
254
270
hook . AfterEndpointsAllocatedAsync ( appModel , CancellationToken . None ) ;
255
271
256
272
using var stream = File . OpenRead ( volume . Source ! ) ;
257
273
var fileContents = new StreamReader ( stream ) . ReadToEnd ( ) ;
258
274
259
275
// check to see that the two hosts are in the file
260
- string pattern1 = @"\$cfg\['Servers'\]\[\$i\]\['host'\] = 'host.docker.internal :5001';" ;
261
- string pattern2 = @"\$cfg\['Servers'\]\[\$i\]\['host'\] = 'host.docker.internal :5002';" ;
276
+ string pattern1 = $ @ "\$cfg\['Servers'\]\[\$i\]\['host'\] = '{ expectedHost } :5001';";
277
+ string pattern2 = $ @ "\$cfg\['Servers'\]\[\$i\]\['host'\] = '{ expectedHost } :5002';";
262
278
Match match1 = Regex . Match ( fileContents , pattern1 ) ;
263
279
Assert . True ( match1 . Success ) ;
264
280
Match match2 = Regex . Match ( fileContents , pattern2 ) ;
0 commit comments