@@ -185,7 +185,7 @@ func (suite *PouchRunSuite) TestRunInWrongWay(c *check.C) {
185185func (suite * PouchRunSuite ) TestRunEnableLxcfs (c * check.C ) {
186186 name := "test-run-lxcfs"
187187
188- command .PouchRun ("run" , "--name" , name , "-m" , "512M" , "--enableLxcfs=true" ,
188+ command .PouchRun ("run" , "-d" , "- -name" , name , "-m" , "512M" , "--enableLxcfs=true" ,
189189 busyboxImage , "sleep" , "10000" ).Assert (c , icmd .Success )
190190
191191 res := command .PouchRun ("exec" , name , "head" , "-n" , "5" , "/proc/meminfo" )
@@ -237,7 +237,7 @@ func (suite *PouchRunSuite) TestRunRestartPolicyNone(c *check.C) {
237237func (suite * PouchRunSuite ) TestRunWithIPCMode (c * check.C ) {
238238 name := "test-run-with-ipc-mode"
239239
240- res := command .PouchRun ("run" , "--name" , name , "--ipc" , "host" , busyboxImage )
240+ res := command .PouchRun ("run" , "-d" , "- -name" , name , "--ipc" , "host" , busyboxImage )
241241 res .Assert (c , icmd .Success )
242242 DelContainerForceMultyTime (c , name )
243243}
@@ -247,7 +247,7 @@ func (suite *PouchRunSuite) TestRunWithIPCMode(c *check.C) {
247247func (suite * PouchRunSuite ) TestRunWithPIDMode (c * check.C ) {
248248 name := "test-run-with-pid-mode"
249249
250- res := command .PouchRun ("run" , "--name" , name , "--pid" , "host" , busyboxImage )
250+ res := command .PouchRun ("run" , "-d" , "- -name" , name , "--pid" , "host" , busyboxImage )
251251 res .Assert (c , icmd .Success )
252252 DelContainerForceMultyTime (c , name )
253253}
@@ -256,7 +256,7 @@ func (suite *PouchRunSuite) TestRunWithPIDMode(c *check.C) {
256256func (suite * PouchRunSuite ) TestRunWithUTSMode (c * check.C ) {
257257 name := "test-run-with-uts-mode"
258258
259- res := command .PouchRun ("run" , "--name" , name , "--uts" , "host" , busyboxImage )
259+ res := command .PouchRun ("run" , "-d" , "- -name" , name , "--uts" , "host" , busyboxImage )
260260 res .Assert (c , icmd .Success )
261261 DelContainerForceMultyTime (c , name )
262262}
@@ -266,7 +266,7 @@ func (suite *PouchRunSuite) TestRunWithSysctls(c *check.C) {
266266 sysctl := "net.ipv4.ip_forward=1"
267267 name := "run-sysctl"
268268
269- res := command .PouchRun ("run" , "--name" , name , "--sysctl" , sysctl , busyboxImage )
269+ res := command .PouchRun ("run" , "-d" , "- -name" , name , "--sysctl" , sysctl , busyboxImage )
270270 res .Assert (c , icmd .Success )
271271
272272 output := command .PouchRun ("exec" , name , "cat" , "/proc/sys/net/ipv4/ip_forward" ).Stdout ()
@@ -281,7 +281,7 @@ func (suite *PouchRunSuite) TestRunWithUser(c *check.C) {
281281 user := "1001"
282282 name := "run-user"
283283
284- res := command .PouchRun ("run" , "--name" , name , "--user" , user , busyboxImage )
284+ res := command .PouchRun ("run" , "-d" , "- -name" , name , "--user" , user , busyboxImage )
285285 res .Assert (c , icmd .Success )
286286
287287 output := command .PouchRun ("exec" , name , "id" , "-u" ).Stdout ()
@@ -304,7 +304,7 @@ func (suite *PouchRunSuite) TestRunWithAppArmor(c *check.C) {
304304 appArmor := "apparmor=unconfined"
305305 name := "run-apparmor"
306306
307- res := command .PouchRun ("run" , "--name" , name , "--security-opt" , appArmor , busyboxImage )
307+ res := command .PouchRun ("run" , "-d" , "- -name" , name , "--security-opt" , appArmor , busyboxImage )
308308 res .Assert (c , icmd .Success )
309309
310310 // TODO: do the test more strictly with effective AppArmor profile.
@@ -317,7 +317,7 @@ func (suite *PouchRunSuite) TestRunWithSeccomp(c *check.C) {
317317 seccomp := "seccomp=unconfined"
318318 name := "run-seccomp"
319319
320- res := command .PouchRun ("run" , "--name" , name , "--security-opt" , seccomp , busyboxImage )
320+ res := command .PouchRun ("run" , "-d" , "- -name" , name , "--security-opt" , seccomp , busyboxImage )
321321 res .Assert (c , icmd .Success )
322322
323323 // TODO: do the test more strictly with effective seccomp profile.
@@ -359,7 +359,7 @@ func (suite *PouchRunSuite) TestRunWithPrivilege(c *check.C) {
359359func (suite * PouchRunSuite ) TestRunWithBlkioWeight (c * check.C ) {
360360 name := "test-run-with-blkio-weight"
361361
362- res := command .PouchRun ("run" , "--name" , name , "--blkio-weight" , "500" , busyboxImage )
362+ res := command .PouchRun ("run" , "-d" , "- -name" , name , "--blkio-weight" , "500" , busyboxImage )
363363 res .Assert (c , icmd .Success )
364364 DelContainerForceMultyTime (c , name )
365365}
@@ -817,7 +817,7 @@ func (suite *PouchRunSuite) TestRunWithDiskQuota(c *check.C) {
817817// TestRunWithAnnotation is to verify the valid running container with annotation, and verify SpecAnnotation filed has been in inspect output.
818818func (suite * PouchRunSuite ) TestRunWithAnnotation (c * check.C ) {
819819 cname := "TestRunWithAnnotation"
820- command .PouchRun ("run" , "-d" , "--annotation" , "a=b" , "--annotation" , "foo=bar" , "--name" , cname , busyboxImage ).Stdout ( )
820+ command .PouchRun ("run" , "-d" , "--annotation" , "a=b" , "--annotation" , "foo=bar" , "--name" , cname , busyboxImage ).Assert ( c , icmd . Success )
821821
822822 output := command .PouchRun ("inspect" , cname ).Stdout ()
823823 result := []types.ContainerJSON {}
@@ -835,3 +835,19 @@ func (suite *PouchRunSuite) TestRunWithAnnotation(c *check.C) {
835835 c .Assert (util .PartialEqual (annotationStr , "a=b" ), check .IsNil )
836836 c .Assert (util .PartialEqual (annotationStr , "foo=bar" ), check .IsNil )
837837}
838+
839+ // TestRunWithExitCode is to verify the valid running container with exit code != 0.
840+ func (suite * PouchRunSuite ) TestRunWithExitCode (c * check.C ) {
841+ cname := "TestRunWithExitCode"
842+ ret := command .PouchRun ("run" , "--name" , cname , busyboxImage , "sh" , "-c" , "exit 101" )
843+ // test process exit code $? == 101
844+ ret .Assert (c , icmd.Expected {ExitCode : 101 })
845+
846+ // test container ExitCode == 101
847+ output := command .PouchRun ("inspect" , cname ).Stdout ()
848+ result := []types.ContainerJSON {}
849+ if err := json .Unmarshal ([]byte (output ), & result ); err != nil {
850+ c .Errorf ("failed to decode inspect output: %v" , err )
851+ }
852+ c .Assert (result [0 ].State .ExitCode , check .Equals , int64 (101 ))
853+ }
0 commit comments