forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_restart_test.go
120 lines (87 loc) · 4.25 KB
/
cli_restart_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"strings"
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)
// PouchRestartSuite is the test suite for restart CLI.
type PouchRestartSuite struct{}
func init() {
check.Suite(&PouchRestartSuite{})
}
// SetUpSuite does common setup in the beginning of each test suite.
func (suite *PouchRestartSuite) SetUpSuite(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
environment.PruneAllContainers(apiClient)
command.PouchRun("pull", busyboxImage).Assert(c, icmd.Success)
}
// TearDownTest does cleanup work in the end of each test.
func (suite *PouchRestartSuite) TearDownTest(c *check.C) {
}
// 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)
res.Assert(c, icmd.Success)
res = command.PouchRun("restart", "-t", "1", name)
res.Assert(c, icmd.Success)
if out := res.Combined(); !strings.Contains(out, name) {
c.Fatalf("unexpected output: %s, expected: %s", out, name)
}
}
// 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.
res := command.PouchRun("run", "--name", name, busyboxImage, "ls")
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)
command.PouchRun("wait", name).Assert(c, icmd.Success)
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("run", "-d", "--name", name, busyboxImage, "top")
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)
command.PouchRun("stop", "-t", "1", name).Assert(c, icmd.Success)
command.PouchRun("restart", "-t", "1", name).Assert(c, icmd.Success)
}
// TestPouchRestartPausedContainer is to verify restart paused container
func (suite *PouchRestartSuite) TestPouchRestartPausedContainer(c *check.C) {
name := "TestPouchRestartPausedContainer"
res := command.PouchRun("run", "-d", "--name", name, busyboxImage, "top")
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)
command.PouchRun("pause", name).Assert(c, icmd.Success)
command.PouchRun("restart", name).Assert(c, icmd.Success)
}
// TestPouchRestartMultiContainers is to verify the correctness of restarting more than one running container.
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")
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)
}
res := command.PouchRun("restart", "-t", "1", containernames[0], containernames[1])
res.Assert(c, icmd.Success)
if out := res.Combined(); !strings.Contains(out, containernames[0]) || !strings.Contains(out, containernames[1]) {
c.Fatalf("unexpected output: %s, expected: %s\n%s", out, containernames[0], containernames[1])
}
}