@@ -151,3 +151,30 @@ func (suite *PouchExecSuite) TestExecFail(c *check.C) {
151151 defer DelContainerForceMultyTime (c , name )
152152 c .Assert (res .Stderr (), check .NotNil )
153153}
154+
155+ // TestExecUser test exec with user.
156+ func (suite * PouchExecSuite ) TestExecUser (c * check.C ) {
157+ name := "TestExecUser"
158+ res := command .PouchRun ("run" , "-d" , "-u=1001" , "--name" , name , busyboxImage , "top" )
159+ defer DelContainerForceMultyTime (c , name )
160+ res .Assert (c , icmd .Success )
161+
162+ res = command .PouchRun ("exec" , name , "id" , "-u" )
163+ res .Assert (c , icmd .Success )
164+ if ! strings .Contains (res .Stdout (), "1001" ) {
165+ c .Fatalf ("failed to run a container with expected user: %s, but got %s" , "1001" , res .Stdout ())
166+ }
167+
168+ res = command .PouchRun ("exec" , "-u=1002" , name , "id" , "-u" )
169+ res .Assert (c , icmd .Success )
170+ if ! strings .Contains (res .Stdout (), "1002" ) {
171+ c .Fatalf ("failed to run a container with expected user: %s, but got %s" , "1002" , res .Stdout ())
172+ }
173+
174+ // test user should not changed by exec process
175+ res = command .PouchRun ("exec" , name , "id" , "-u" )
176+ res .Assert (c , icmd .Success )
177+ if ! strings .Contains (res .Stdout (), "1001" ) {
178+ c .Fatalf ("failed to run a container with expected user: %s, but got %s" , "1001" , res .Stdout ())
179+ }
180+ }
0 commit comments