浏览代码

Add test for ACI start

Djordje Lukic 5 年之前
父节点
当前提交
aa8bf1daaa
共有 2 个文件被更改,包括 24 次插入2 次删除
  1. 1 1
      cli/cmd/start.go
  2. 23 1
      tests/aci-e2e/e2e-aci_test.go

+ 1 - 1
cli/cmd/start.go

@@ -30,7 +30,7 @@ import (
 	"github.com/docker/api/client"
 )
 
-// StartCommand deletes containers
+// StartCommand starts containers
 func StartCommand() *cobra.Command {
 	cmd := &cobra.Command{
 		Use:   "start",

+ 23 - 1
tests/aci-e2e/e2e-aci_test.go

@@ -385,8 +385,18 @@ func TestContainerRunAttached(t *testing.T) {
 		assert.Assert(t, is.Len(out, 2))
 	})
 
+	t.Run("start container", func(t *testing.T) {
+		res := c.RunDockerCmd("start", container)
+		res.Assert(t, icmd.Expected{Out: container})
+		waitForStatus(t, c, container, "Running")
+	})
+
 	t.Run("rm stopped container", func(t *testing.T) {
-		res := c.RunDockerCmd("rm", container)
+		res := c.RunDockerCmd("stop", container)
+		res.Assert(t, icmd.Expected{Out: container})
+		waitForStatus(t, c, container, "Terminated")
+
+		res = c.RunDockerCmd("rm", container)
 		res.Assert(t, icmd.Expected{Out: container})
 	})
 }
@@ -653,3 +663,15 @@ func getContainerName(stdout string) string {
 	out := strings.Split(strings.TrimSpace(stdout), "\n")
 	return strings.TrimSpace(out[len(out)-1])
 }
+
+func waitForStatus(t *testing.T, c *E2eCLI, containerID string, status string) {
+	checkStopped := func(t poll.LogT) poll.Result {
+		res := c.RunDockerCmd("inspect", containerID)
+		if strings.Contains(res.Stdout(), status) {
+			return poll.Success()
+		}
+		return poll.Continue("waiting for container to stop")
+	}
+
+	poll.WaitOn(t, checkStopped, poll.WithDelay(5*time.Second), poll.WithTimeout(60*time.Second))
+}