Browse Source

backend.local: Add volume e2e test

Signed-off-by: Chris Crone <[email protected]>
Chris Crone 5 years ago
parent
commit
74a27541e4
1 changed files with 40 additions and 1 deletions
  1. 40 1
      local/e2e/backend_test.go

+ 40 - 1
local/e2e/backend_test.go

@@ -43,12 +43,13 @@ func TestMain(m *testing.M) {
 	os.Exit(exitCode)
 }
 
-func TestLocalBackend(t *testing.T) {
+func TestLocalBackendRun(t *testing.T) {
 	c := NewParallelE2eCLI(t, binDir)
 	c.RunDockerCmd("context", "create", "local", "test-context").Assert(t, icmd.Success)
 	c.RunDockerCmd("context", "use", "test-context").Assert(t, icmd.Success)
 
 	t.Run("run", func(t *testing.T) {
+		t.Parallel()
 		res := c.RunDockerCmd("run", "-d", "nginx")
 		containerName := strings.TrimSpace(res.Combined())
 		t.Cleanup(func() {
@@ -59,6 +60,7 @@ func TestLocalBackend(t *testing.T) {
 	})
 
 	t.Run("run rm", func(t *testing.T) {
+		t.Parallel()
 		res := c.RunDockerCmd("run", "--rm", "-d", "nginx")
 		containerName := strings.TrimSpace(res.Combined())
 		t.Cleanup(func() {
@@ -87,7 +89,20 @@ func TestLocalBackend(t *testing.T) {
 		res.Assert(t, icmd.Expected{Out: "0.0.0.0:8080->80/tcp"})
 	})
 
+	t.Run("run with volume", func(t *testing.T) {
+		t.Parallel()
+		t.Cleanup(func() {
+			_ = c.RunDockerOrExitError("volume", "rm", "local-test")
+		})
+		c.RunDockerCmd("volume", "create", "local-test")
+		c.RunDockerCmd("run", "--rm", "-d", "--volume", "local-test:/data", "alpine", "sh", "-c", `echo "testdata" > /data/test`)
+		// FIXME: Remove sleep when race to attach to dead container is fixed
+		res := c.RunDockerOrExitError("run", "--rm", "--volume", "local-test:/data", "alpine", "sh", "-c", "cat /data/test && sleep 1")
+		res.Assert(t, icmd.Expected{Out: "testdata"})
+	})
+
 	t.Run("inspect not found", func(t *testing.T) {
+		t.Parallel()
 		res := c.RunDockerOrExitError("inspect", "nonexistentcontainer")
 		res.Assert(t, icmd.Expected{
 			ExitCode: 1,
@@ -95,3 +110,27 @@ func TestLocalBackend(t *testing.T) {
 		})
 	})
 }
+
+func TestLocalBackendVolumes(t *testing.T) {
+	c := NewParallelE2eCLI(t, binDir)
+	c.RunDockerCmd("context", "create", "local", "test-context").Assert(t, icmd.Success)
+	c.RunDockerCmd("context", "use", "test-context").Assert(t, icmd.Success)
+
+	t.Run("volume crud", func(t *testing.T) {
+		t.Parallel()
+		name := "crud"
+		t.Cleanup(func() {
+			_ = c.RunDockerOrExitError("volume", "rm", name)
+		})
+		res := c.RunDockerCmd("volume", "create", name)
+		res.Assert(t, icmd.Expected{Out: name})
+		res = c.RunDockerCmd("volume", "ls")
+		res.Assert(t, icmd.Expected{Out: name})
+		res = c.RunDockerCmd("volume", "inspect", name)
+		res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`"ID": "%s"`, name)})
+		res = c.RunDockerCmd("volume", "rm", name)
+		res.Assert(t, icmd.Expected{Out: name})
+		res = c.RunDockerOrExitError("volume", "inspect", name)
+		res.Assert(t, icmd.Expected{ExitCode: 1})
+	})
+}