diff --git a/client/driver/lxc_test.go b/client/driver/lxc_test.go index d21a0235b7a0..ddc78193c7d4 100644 --- a/client/driver/lxc_test.go +++ b/client/driver/lxc_test.go @@ -3,8 +3,11 @@ package driver import ( + "bytes" "fmt" + "io/ioutil" "os" + "os/exec" "path/filepath" "testing" "time" @@ -75,6 +78,19 @@ func TestLxcDriver_Start_Wait(t *testing.T) { Resources: structs.DefaultResources(), } + testFileContents := []byte("this should be visible under /mnt/tmp") + tmpFile, err := ioutil.TempFile("/tmp", "testlxcdriver_start_wait") + if err != nil { + t.Fatalf("error writing temp file: %v", err) + } + defer os.Remove(tmpFile.Name()) + if _, err := tmpFile.Write(testFileContents); err != nil { + t.Fatalf("error writing temp file: %v", err) + } + if err := tmpFile.Close(); err != nil { + t.Fatalf("error closing temp file: %v", err) + } + ctx := testDriverContexts(t, task) defer ctx.AllocDir.Destroy() d := NewLxcDriver(ctx.DriverCtx) @@ -118,6 +134,16 @@ func TestLxcDriver_Start_Wait(t *testing.T) { } } + // Test that /mnt/tmp/$tempFile exists in the container: + mountedContents, err := exec.Command("lxc-attach", "-n", containerName, "--", "cat", filepath.Join("/mnt/", tmpFile.Name())).Output() + if err != nil { + t.Fatalf("err reading temp file in bind mount: %v", err) + } + + if !bytes.Equal(mountedContents, testFileContents) { + t.Fatalf("contents of temp bind mounted file did not match, was '%s'", mountedContents) + } + // Desroy the container if err := sresp.Handle.Kill(); err != nil { t.Fatalf("err: %v", err)