@@ -73,49 +73,36 @@ func TestRunWithSystemdTrueEnabled(t *testing.T) {
7373 )
7474
7575 testCase .Setup = func (data test.Data , helpers test.Helpers ) {
76- containerName := testutil .Identifier (t )
77- data .Labels ().Set ("containerName" , containerName )
78- helpers .Ensure ("run" , "-d" , "--name" , containerName , "--systemd=true" , "--entrypoint=/sbin/init" , testutil .SystemdImage )
79- nerdtest .EnsureContainerStarted (helpers , containerName )
76+ helpers .Ensure ("run" , "-d" , "--name" , data .Identifier (), "--systemd=true" , "--entrypoint=/sbin/init" , testutil .SystemdImage )
8077 }
8178
8279 testCase .Cleanup = func (data test.Data , helpers test.Helpers ) {
83- containerName := data .Labels ().Get ("containerName" )
84- helpers .Anyhow ("container" , "rm" , "-f" , containerName )
80+ helpers .Anyhow ("container" , "rm" , "-f" , data .Identifier ())
8581 }
8682
87- testCase .SubTests = []* test.Case {
88- {
89- Description : "should expose SIGTERM+3 stop signal labels" ,
90- NoParallel : true ,
91- Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
92- containerName := data .Labels ().Get ("containerName" )
93- return helpers .Command ("inspect" , "--format" , "{{json .Config.Labels}}" , containerName )
94- },
95- Expected : test .Expects (expect .ExitCodeSuccess , nil , expect .Contains ("SIGRTMIN+3" )),
96- },
97- {
98- Description : "waits for systemd to become ready and lists systemd jobs" ,
99- NoParallel : true ,
100- Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
101- containerName := data .Labels ().Get ("containerName" )
102- return helpers .Command ("exec" , containerName , "sh" , "-c" , "--" , `tries=0
103-
104- until systemctl is-system-running >/dev/null 2>&1; do
105-
106- >&2 printf "Waiting for systemd to come up...\n"
107- sleep 1s
108- tries=$(( tries + 1))
109- [ $tries -lt 10 ] || {
110- >&2 printf "systemd failed to come up in a reasonable amount of time\n"
111- exit 1
112- }
113- done
114- systemctl list-jobs` )
115- },
116- Expected : test .Expects (expect .ExitCodeSuccess , nil , expect .Contains ("jobs" )),
117- },
118- }
83+ testCase .Command = func (data test.Data , helpers test.Helpers ) test.TestableCommand {
84+ // should expose SIGTERM+3 stop signal labels
85+ helpers .Command ("inspect" , "--format" , "{{json .Config.Labels}}" , data .Identifier ()).
86+ Run (& test.Expected {
87+ ExitCode : expect .ExitCodeSuccess ,
88+ Output : expect .Contains ("SIGRTMIN+3" ),
89+ })
90+
91+ // waits for systemd to become ready and lists systemd jobs
92+ return helpers .Command ("exec" , data .Identifier (), "sh" , "-c" , "--" , `tries=0
93+ until systemctl is-system-running >/dev/null 2>&1; do
94+ >&2 printf "Waiting for systemd to come up...\n"
95+ sleep 1s
96+ tries=$(( tries + 1))
97+ [ $tries -lt 10 ] || {
98+ >&2 printf "systemd failed to come up in a reasonable amount of time\n"
99+ exit 1
100+ }
101+ done
102+ systemctl list-jobs` )
103+ }
104+
105+ testCase .Expected = test .Expects (expect .ExitCodeSuccess , nil , expect .Contains ("jobs" ))
119106
120107 testCase .Run (t )
121108}
0 commit comments