Skip to content

Commit

Permalink
lxc_test: add test for contents of file in bind-mounted dir
Browse files Browse the repository at this point in the history
Ensure that bind mounting via the volumes config really did work.

Signed-off-by: Michael McCracken <mikmccra@cisco.com>
  • Loading branch information
mikemccracken committed Jan 18, 2018
1 parent f86fbdc commit 561376e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions client/driver/lxc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
package driver

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 561376e

Please sign in to comment.