From e150e43f7e3caeeca9f0dfd2beb6b41f4f7fdb31 Mon Sep 17 00:00:00 2001 From: Allen Sun Date: Tue, 19 Jun 2018 15:23:28 +0800 Subject: [PATCH] test: add all states container restart validation Signed-off-by: Allen Sun --- test/cli_restart_test.go | 42 ++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/test/cli_restart_test.go b/test/cli_restart_test.go index cc9b38ce0..71571aad7 100644 --- a/test/cli_restart_test.go +++ b/test/cli_restart_test.go @@ -2,6 +2,7 @@ package main import ( "strings" + "time" "github.com/alibaba/pouch/test/command" "github.com/alibaba/pouch/test/environment" @@ -30,9 +31,9 @@ func (suite *PouchRestartSuite) SetUpSuite(c *check.C) { func (suite *PouchRestartSuite) TearDownTest(c *check.C) { } -// TestPouchRestart is to verify the correctness of restarting a running container. -func (suite *PouchRestartSuite) TestPouchRestart(c *check.C) { - name := "TestPouchRestart" +// TestPouchRestartRunningContainer is to verify the correctness of restarting a running container. +func (suite *PouchRestartSuite) TestPouchRestartRunningContainer(c *check.C) { + name := "TestPouchRestartRunningContainer" res := command.PouchRun("run", "-d", "--name", name, busyboxImage, "top") defer DelContainerForceMultyTime(c, name) @@ -46,16 +47,46 @@ func (suite *PouchRestartSuite) TestPouchRestart(c *check.C) { } } +// TestPouchRestartCreatedContainer is to verify the correctness of restarting a created container. +// Pouch should be compatible with moby's API. Restarting a created container is allowed. +func (suite *PouchRestartSuite) TestPouchRestartCreatedContainer(c *check.C) { + name := "TestPouchRestartCreatedContainer" + + res := command.PouchRun("create", "--name", name, busyboxImage, "top") + defer DelContainerForceMultyTime(c, name) + + res.Assert(c, icmd.Success) + + command.PouchRun("restart", "-t", "1", name).Assert(c, icmd.Success) +} + +// TestPouchRestartExitedContainer is to verify the correctness of restarting an exited container. +// Pouch should be compatible with moby's API. Restarting an exited container is allowed. +func (suite *PouchRestartSuite) TestPouchRestartExitedContainer(c *check.C) { + name := "TestPouchRestartExitedContainer" + + // run a container and make it exit within 0.01s, so the status is exited + res := command.PouchRun("run", "-d", "--name", name, busyboxImage, "sleep", "0.01") + defer DelContainerForceMultyTime(c, name) + + res.Assert(c, icmd.Success) + time.Sleep(1 * time.Second) + + command.PouchRun("restart", "-t", "1", name).Assert(c, icmd.Success) +} + // TestPouchRestartStoppedContainer is to verify the correctness of restarting a stopped container. // Pouch should be compatible with moby's API. Restarting a stopped container is allowed. func (suite *PouchRestartSuite) TestPouchRestartStoppedContainer(c *check.C) { name := "TestPouchRestartStoppedContainer" - res := command.PouchRun("create", "--name", name, busyboxImage) + res := command.PouchRun("run", "-d", "--name", name, busyboxImage, "top") defer DelContainerForceMultyTime(c, name) res.Assert(c, icmd.Success) + command.PouchRun("stop", name).Assert(c, icmd.Success) + command.PouchRun("restart", "-t", "1", name).Assert(c, icmd.Success) } @@ -76,8 +107,7 @@ func (suite *PouchRestartSuite) TestPouchRestartPausedContainer(c *check.C) { func (suite *PouchRestartSuite) TestPouchRestartMultiContainers(c *check.C) { containernames := []string{"TestPouchRestartMultiContainer-1", "TestPouchRestartMultiContainer-2"} for _, name := range containernames { - res := command.PouchRun("run", "-d", - "--name", name, busyboxImage, "top") + res := command.PouchRun("run", "-d", "--name", name, busyboxImage, "top") defer DelContainerForceMultyTime(c, name) res.Assert(c, icmd.Success) }