Browse Source

- Runtime: small bugfixes in external mount-bind integration

Solomon Hykes 12 năm trước cách đây
mục cha
commit
46a9f29bae
2 tập tin đã thay đổi với 7 bổ sung5 xóa
  1. 3 3
      container_test.go
  2. 4 2
      utils_test.go

+ 3 - 3
container_test.go

@@ -540,7 +540,7 @@ func TestCreateVolume(t *testing.T) {
 	runtime := mkRuntime(t)
 	defer nuke(runtime)
 
-	config, _, err := ParseRun([]string{"-v", "/var/lib/data", GetTestImage(runtime).ID, "echo", "hello", "world"}, nil)
+	config, hc, _, err := ParseRun([]string{"-v", "/var/lib/data", GetTestImage(runtime).ID, "echo", "hello", "world"}, nil)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -549,7 +549,7 @@ func TestCreateVolume(t *testing.T) {
 		t.Fatal(err)
 	}
 	defer runtime.Destroy(c)
-	if err := c.Start(); err != nil {
+	if err := c.Start(hc); err != nil {
 		t.Fatal(err)
 	}
 	c.WaitTimeout(500 * time.Millisecond)
@@ -1202,7 +1202,7 @@ func TestBindMounts(t *testing.T) {
 
 	// test writing to bind mount
 	runContainer(r, []string{"-b", fmt.Sprintf("%s:/tmp:rw", tmpDir), "_", "touch", "/tmp/holla"}, t)
-	readFile("/tmp/holla", t) // Will fail if the file doesn't exist
+	readFile(path.Join(tmpDir, "holla"), t) // Will fail if the file doesn't exist
 
 	// test mounting to an illegal destination directory
 	if _, err := runContainer(r, []string{"-b", fmt.Sprintf("%s:.", tmpDir), "ls", "."}, nil); err == nil {

+ 4 - 2
utils_test.go

@@ -32,7 +32,7 @@ func writeFile(dst, content string, t *testing.T) {
 	if err := os.MkdirAll(path.Dir(dst), 0700); err != nil && !os.IsExist(err) {
 		t.Fatal(err)
 	}
-	f, err := os.OpenFile(dst, os.O_RDWR|os.O_TRUNC, 0700)
+	f, err := os.OpenFile(dst, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0700)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -57,6 +57,7 @@ func readFile(src string, t *testing.T) (content string) {
 }
 
 // Create a test container from the given runtime `r` and run arguments `args`.
+// The image name (eg. the XXX in []string{"-i", "-t", "XXX", "bash"}, is dynamically replaced by the current test image.
 // The caller is responsible for destroying the container.
 // Call t.Fatal() at the first error.
 func mkContainer(r *Runtime, args []string, t *testing.T) (*Container, *HostConfig) {
@@ -64,16 +65,17 @@ func mkContainer(r *Runtime, args []string, t *testing.T) (*Container, *HostConf
 	if err != nil {
 		t.Fatal(err)
 	}
+	config.Image = GetTestImage(r).ID
 	c, err := NewBuilder(r).Create(config)
 	if err != nil {
 		t.Fatal(err)
 	}
-	c.Image = GetTestImage(r).ID
 	return c, hostConfig
 }
 
 // Create a test container, start it, wait for it to complete, destroy it,
 // and return its standard output as a string.
+// The image name (eg. the XXX in []string{"-i", "-t", "XXX", "bash"}, is dynamically replaced by the current test image.
 // If t is not nil, call t.Fatal() at the first error. Otherwise return errors normally.
 func runContainer(r *Runtime, args []string, t *testing.T) (output string, err error) {
 	defer func() {