@@ -90,22 +90,38 @@ func (suite *PouchRunVolumeSuite) TestRunWithVolumeCopyData(c *check.C) {
9090 command .PouchRun ("volume" , "rm" , volumeName ).Assert (c , icmd .Success )
9191 }()
9292
93+ // dirs under busybox image `/var` directory
94+ // notes: there is a `/var/log` directory under rich mode container
95+ expectedDirs := []string {"spool" , "www" }
96+
9397 command .PouchRun ("run" , "-t" , "-v" , volumeName + ":/var" , "--name" , containerName1 , busyboxImage , "ls" , "/var" ).Assert (c , icmd .Success )
9498 defer DelContainerForceMultyTime (c , containerName1 )
9599 output1 := icmd .RunCommand ("ls" , DefaultVolumeMountPath + "/" + volumeName ).Stdout ()
96- lines := strings .Split (output1 , "\n " )
97- if ! utils .StringInSlice (lines , "spool" ) {
98- c .Fatalf ("expected \" spool\" directory under /var directory, but got %s" , output1 )
99- }
100- if ! utils .StringInSlice (lines , "www" ) {
101- c .Fatalf ("expected \" www\" directory under /var directory, but got %s" , output1 )
100+
101+ if ! lsResultContains (output1 , expectedDirs ) {
102+ c .Fatalf ("expected \" %s\" directory under /var directory, but got %s" ,
103+ strings .Join (expectedDirs , " " ), output1 )
102104 }
103105
104106 command .PouchRun ("run" , "-t" , "-v" , hostdir + ":/var" , "--name" , containerName2 , busyboxImage , "ls" , "/var" ).Assert (c , icmd .Success )
105107 defer DelContainerForceMultyTime (c , containerName2 )
106108 defer icmd .RunCommand ("rm" , "-rf" , hostdir )
107109 output2 := icmd .RunCommand ("ls" , hostdir ).Stdout ()
108- c .Assert (output2 , check .Equals , "" )
110+
111+ if lsResultContains (output2 , expectedDirs ) {
112+ c .Fatalf ("volume mount in host bind mode, but \" %s\" exists" , strings .Join (expectedDirs , " " ))
113+ }
114+ }
115+
116+ func lsResultContains (res string , names []string ) bool {
117+ lines := strings .Split (res , "\n " )
118+ for _ , name := range names {
119+ name = strings .TrimSpace (name )
120+ if ! utils .StringInSlice (lines , name ) {
121+ return false
122+ }
123+ }
124+ return true
109125}
110126
111127// TestRunWithHostFileVolume tests binding a host file as a volume into container.
0 commit comments