@@ -4,12 +4,12 @@ use anyhow::{Context, Result, bail};
4
4
use tempfile:: { Builder , NamedTempFile } ;
5
5
6
6
use super :: config:: {
7
- ComposeConfig , ComposeTestConfig , E2E_TESTS_DIR , Environment , INTEGRATION_TESTS_DIR ,
8
- RustToolchainConfig ,
7
+ ComposeConfig , ComposeTestConfig , E2E_TESTS_DIR , INTEGRATION_TESTS_DIR , RustToolchainConfig ,
9
8
} ;
10
9
use super :: runner:: { ContainerTestRunner as _, IntegrationTestRunner , TestRunner as _} ;
11
10
use super :: state:: EnvsDir ;
12
11
use crate :: app:: CommandExt as _;
12
+ use crate :: environment:: { Environment , extract_present, rename_environment_keys} ;
13
13
use crate :: testing:: build:: ALL_INTEGRATIONS_FEATURE_FLAG ;
14
14
use crate :: testing:: docker:: { CONTAINER_TOOL , DOCKER_SOCKET } ;
15
15
@@ -103,7 +103,7 @@ impl ComposeTest {
103
103
envs_dir,
104
104
runner,
105
105
compose,
106
- env_config,
106
+ env_config : rename_environment_keys ( & env_config ) ,
107
107
build_all,
108
108
retries,
109
109
} ;
@@ -121,8 +121,8 @@ impl ComposeTest {
121
121
122
122
let mut env_vars = self . config . env . clone ( ) ;
123
123
// Make sure the test runner has the same config environment vars as the services do.
124
- for ( key, value) in config_env ( & self . env_config ) {
125
- env_vars. insert ( key, Some ( value) ) ;
124
+ for ( key, value) in self . env_config . clone ( ) {
125
+ env_vars. insert ( key, value) ;
126
126
}
127
127
128
128
env_vars. insert ( "TEST_LOG" . to_string ( ) , Some ( "info" . into ( ) ) ) ;
@@ -181,8 +181,11 @@ impl ComposeTest {
181
181
// image for the runner. So we must build that image before starting the
182
182
// compose so that it is available.
183
183
if self . local_config . kind == ComposeTestKind :: E2E {
184
- self . runner
185
- . build ( Some ( & self . config . features ) , self . local_config . directory ) ?;
184
+ self . runner . build (
185
+ Some ( & self . config . features ) ,
186
+ self . local_config . directory ,
187
+ & self . env_config ,
188
+ ) ?;
186
189
}
187
190
188
191
self . config . check_required ( ) ?;
@@ -275,9 +278,11 @@ impl Compose {
275
278
}
276
279
}
277
280
278
- fn start ( & self , config : & Environment ) -> Result < ( ) > {
279
- self . prepare ( ) ?;
280
- self . run ( "Starting" , & [ "up" , "--detach" ] , Some ( config) )
281
+ fn start ( & self , environment : & Environment ) -> Result < ( ) > {
282
+ #[ cfg( unix) ]
283
+ unix:: prepare_compose_volumes ( & self . config , & self . test_dir , environment) ?;
284
+
285
+ self . run ( "Starting" , & [ "up" , "--detach" ] , Some ( environment) )
281
286
}
282
287
283
288
fn stop ( & self ) -> Result < ( ) > {
@@ -289,7 +294,12 @@ impl Compose {
289
294
)
290
295
}
291
296
292
- fn run ( & self , action : & str , args : & [ & ' static str ] , config : Option < & Environment > ) -> Result < ( ) > {
297
+ fn run (
298
+ & self ,
299
+ action : & str ,
300
+ args : & [ & ' static str ] ,
301
+ environment : Option < & Environment > ,
302
+ ) -> Result < ( ) > {
293
303
let mut command = Command :: new ( CONTAINER_TOOL . clone ( ) ) ;
294
304
command. arg ( "compose" ) ;
295
305
// When the integration test environment is already active, the tempfile path does not
@@ -320,30 +330,13 @@ impl Compose {
320
330
command. env ( key, value) ;
321
331
}
322
332
}
323
- if let Some ( config ) = config {
324
- command. envs ( config_env ( config ) ) ;
333
+ if let Some ( environment ) = environment {
334
+ command. envs ( extract_present ( environment ) ) ;
325
335
}
326
336
327
337
waiting ! ( "{action} service environment" ) ;
328
338
command. check_run ( )
329
339
}
330
-
331
- fn prepare ( & self ) -> Result < ( ) > {
332
- #[ cfg( unix) ]
333
- unix:: prepare_compose_volumes ( & self . config , & self . test_dir ) ?;
334
- Ok ( ( ) )
335
- }
336
- }
337
-
338
- fn config_env ( config : & Environment ) -> impl Iterator < Item = ( String , String ) > + ' _ {
339
- config. iter ( ) . filter_map ( |( var, value) | {
340
- value. as_ref ( ) . map ( |value| {
341
- (
342
- format ! ( "CONFIG_{}" , var. replace( '-' , "_" ) . to_uppercase( ) ) ,
343
- value. to_string ( ) ,
344
- )
345
- } )
346
- } )
347
340
}
348
341
349
342
#[ cfg( unix) ]
@@ -353,6 +346,7 @@ mod unix {
353
346
use std:: path:: { Path , PathBuf } ;
354
347
355
348
use super :: super :: config:: ComposeConfig ;
349
+ use crate :: environment:: { Environment , resolve_placeholders} ;
356
350
use crate :: testing:: config:: VolumeMount ;
357
351
use anyhow:: { Context , Result } ;
358
352
@@ -362,7 +356,11 @@ mod unix {
362
356
const ALL_READ_DIR : u32 = 0o555 ;
363
357
364
358
/// Fix up potential issues before starting a compose container
365
- pub fn prepare_compose_volumes ( config : & ComposeConfig , test_dir : & Path ) -> Result < ( ) > {
359
+ pub fn prepare_compose_volumes (
360
+ config : & ComposeConfig ,
361
+ test_dir : & Path ,
362
+ environment : & Environment ,
363
+ ) -> Result < ( ) > {
366
364
for service in config. services . values ( ) {
367
365
if let Some ( volumes) = & service. volumes {
368
366
for volume in volumes {
@@ -374,12 +372,12 @@ mod unix {
374
372
}
375
373
VolumeMount :: Long { source, .. } => source,
376
374
} ;
377
-
378
- if !config. volumes . contains_key ( source)
375
+ let source = resolve_placeholders ( source , environment ) ;
376
+ if !config. volumes . contains_key ( & source)
379
377
&& !source. starts_with ( '/' )
380
378
&& !source. starts_with ( '$' )
381
379
{
382
- let path: PathBuf = [ test_dir, Path :: new ( source) ] . iter ( ) . collect ( ) ;
380
+ let path: PathBuf = [ test_dir, Path :: new ( & source) ] . iter ( ) . collect ( ) ;
383
381
add_read_permission ( & path) ?;
384
382
}
385
383
}
0 commit comments