@@ -233,12 +233,7 @@ services:
233233}
234234
235235func TestComposeRunWithEnv (t * testing.T ) {
236- base := testutil .NewBase (t )
237- // specify the name of container in order to remove
238- // TODO: when `compose rm` is implemented, replace it.
239- containerName := testutil .Identifier (t )
240-
241- dockerComposeYAML := fmt .Sprintf (`
236+ var dockerComposeYAML = fmt .Sprintf (`
242237services:
243238 alpine:
244239 image: %s
@@ -248,19 +243,35 @@ services:
248243 - "echo $$FOO"
249244` , testutil .CommonImage )
250245
251- comp := testutil .NewComposeDir (t , dockerComposeYAML )
252- defer comp .CleanUp ()
253- projectName := comp .ProjectName ()
254- t .Logf ("projectName=%q" , projectName )
255- defer base .ComposeCmd ("-f" , comp .YAMLFullPath (), "down" , "-v" ).Run ()
246+ testCase := nerdtest .Setup ()
256247
257- defer base .Cmd ("rm" , "-f" , "-v" , containerName ).Run ()
258- const partialOutput = "bar"
259- // unbuffer(1) emulates tty, which is required by `nerdctl run -t`.
260- // unbuffer(1) can be installed with `apt-get install expect`.
261- unbuffer := []string {"unbuffer" }
262- base .ComposeCmdWithHelper (unbuffer , "-f" , comp .YAMLFullPath (),
263- "run" , "-e" , "FOO=bar" , "--name" , containerName , "alpine" ).AssertOutContains (partialOutput )
248+ testCase .Setup = func (data test.Data , helpers test.Helpers ) {
249+ data .Temp ().Save (dockerComposeYAML , "compose.yaml" )
250+ }
251+
252+ testCase .Cleanup = func (data test.Data , helpers test.Helpers ) {
253+ helpers .Anyhow ("compose" , "-f" , data .Temp ().Path ("compose.yaml" ), "rm" , "-f" , "-v" )
254+ helpers .Anyhow ("compose" , "-f" , data .Temp ().Path ("compose.yaml" ), "down" , "-v" )
255+ }
256+
257+ testCase .Command = func (data test.Data , helpers test.Helpers ) test.TestableCommand {
258+ cmd := helpers .Command (
259+ "compose" ,
260+ "-f" ,
261+ data .Temp ().Path ("compose.yaml" ),
262+ "run" ,
263+ "-e" , "FOO=bar" ,
264+ "--name" ,
265+ data .Identifier (),
266+ "alpine" ,
267+ )
268+ cmd .WithPseudoTTY ()
269+ return cmd
270+ }
271+
272+ testCase .Expected = test .Expects (expect .ExitCodeSuccess , nil , expect .Contains ("bar" ))
273+
274+ testCase .Run (t )
264275}
265276
266277func TestComposeRunWithUser (t * testing.T ) {
0 commit comments