forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_checkpoint_test.go
87 lines (68 loc) · 3.17 KB
/
cli_checkpoint_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
package main
import (
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/util"
"github.com/gotestyourself/gotestyourself/icmd"
"github.com/go-check/check"
)
// PouchCheckpointSuite is the test suite for container create API.
type PouchCheckpointSuite struct{}
func init() {
check.Suite(&PouchCheckpointSuite{})
}
// SetUpTest does common setup in the beginning of each test.
func (suite *PouchCheckpointSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
SkipIfFalse(c, environment.IsCRIUExist)
}
// TestCreate tests create checkpoint
func (suite *PouchCheckpointSuite) TestCheckpointCreate(c *check.C) {
cname := "TestCheckpointCreate"
command.PouchRun("run", "-d", "--name", cname, busyboxImage, "top").Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, cname)
// create checkpoint cp0 leaving container running
ret := command.PouchRun("checkpoint", "create", cname, "--leave-running", "cp0")
ret.Assert(c, icmd.Success)
c.Assert(ret.Stdout(), check.Equals, "cp0\n")
// create a already exist checkpoint should fail
ret = command.PouchRun("checkpoint", "create", cname, "cp0")
c.Assert(util.PartialEqual(ret.Stderr(), "checkpoint cp0 is already exist"), check.IsNil)
// create checkpoint cp1 leaving container exited
ret = command.PouchRun("checkpoint", "create", cname, "cp1")
ret.Assert(c, icmd.Success)
c.Assert(ret.Stdout(), check.Equals, "cp1\n")
}
// TestCreate tests list checkpoint
func (suite *PouchCheckpointSuite) TestCheckpointList(c *check.C) {
cname := "TestCheckpointList"
command.PouchRun("run", "-d", "--name", cname, busyboxImage, "top").Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, cname)
command.PouchRun("checkpoint", "create", cname, "--leave-running", "cp0").Assert(c, icmd.Success)
ret := command.PouchRun("checkpoint", "ls", cname)
ret.Assert(c, icmd.Success)
c.Assert(ret.Stdout(), check.Equals, "cp0\n")
command.PouchRun("checkpoint", "create", cname, "--leave-running", "cp1").Assert(c, icmd.Success)
ret = command.PouchRun("checkpoint", "ls", cname)
ret.Assert(c, icmd.Success)
c.Assert(ret.Stdout(), check.Equals, "cp0\ncp1\n")
}
// TestCreate tests delete checkpoint
func (suite *PouchCheckpointSuite) TestCheckpointDelete(c *check.C) {
cname := "TestCheckpointDelete"
command.PouchRun("run", "-d", "--name", cname, busyboxImage, "top").Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, cname)
command.PouchRun("checkpoint", "create", cname, "--leave-running", "cp0").Assert(c, icmd.Success)
command.PouchRun("checkpoint", "create", cname, "cp1").Assert(c, icmd.Success)
ret := command.PouchRun("checkpoint", "ls", cname)
ret.Assert(c, icmd.Success)
c.Assert(ret.Stdout(), check.Equals, "cp0\ncp1\n")
// failed to delete a non-exist checkpoint
ret = command.PouchRun("checkpoint", "rm", "no-exist")
c.Assert(util.PartialEqual(ret.Stderr(), ""), check.IsNil)
command.PouchRun("checkpoint", "rm", cname, "cp0").Assert(c, icmd.Success)
command.PouchRun("checkpoint", "rm", cname, "cp1").Assert(c, icmd.Success)
ret = command.PouchRun("checkpoint", "ls", cname)
ret.Assert(c, icmd.Success)
c.Assert(ret.Stdout(), check.Equals, "")
}