forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_run_working_dir_test.go
98 lines (77 loc) · 3.19 KB
/
cli_run_working_dir_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
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"
)
// PouchRunWorkingDirSuite is the test suite for run CLI.
type PouchRunWorkingDirSuite struct{}
func init() {
check.Suite(&PouchRunWorkingDirSuite{})
}
// SetUpSuite does common setup in the beginning of each test suite.
func (suite *PouchRunWorkingDirSuite) SetUpSuite(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
environment.PruneAllContainers(apiClient)
PullImage(c, busyboxImage)
}
// TearDownTest does cleanup work in the end of each test.
func (suite *PouchRunWorkingDirSuite) TearDownTest(c *check.C) {
}
// TestRunWithExistWorkingDir is to verify the valid running container
// with specifying working dir
func (suite *PouchRunWorkingDirSuite) TestRunWithExistWorkingDir(c *check.C) {
SkipIfFalse(c, environment.IsMemorySupport)
cname := "TestRunWithExistWorkingDir"
res := command.PouchRun("run", "-d", "-w", "/root", "--name", cname, busyboxImage, "top")
defer DelContainerForceMultyTime(c, cname)
res.Assert(c, icmd.Success)
// test if the value is in inspect result
workingDir, err := inspectFilter(cname, ".Config.WorkingDir")
c.Assert(err, check.IsNil)
c.Assert(workingDir, check.Equals, "/root")
}
// TestRunWithNotExistWorkingDir is to verify the valid running container
// with specifying a not exist working dir
func (suite *PouchRunWorkingDirSuite) TestRunWithNotExistWorkingDir(c *check.C) {
SkipIfFalse(c, environment.IsMemorySupport)
cname := "TestRunWithNotExistWorkingDir"
res := command.PouchRun("run", "-d", "-w", "/tmp/notexist/dir", "--name", cname, busyboxImage, "top")
defer DelContainerForceMultyTime(c, cname)
res.Assert(c, icmd.Success)
// test if the value is in inspect result
workingDir, err := inspectFilter(cname, ".Config.WorkingDir")
c.Assert(err, check.IsNil)
c.Assert(workingDir, check.Equals, "/tmp/notexist/dir")
}
// TestRunWithWorkingDir is to verify the valid running container
// with specifying working dir
func (suite *PouchRunWorkingDirSuite) TestRunWithWorkingDir(c *check.C) {
SkipIfFalse(c, environment.IsMemorySupport)
dir := "/tmp/testworkingdir"
cname := "TestRunWithNotExistWorkingDir"
res := command.PouchRun("run", "-w", dir, "--name", cname, busyboxImage, "pwd")
defer DelContainerForceMultyTime(c, cname)
res.Assert(c, icmd.Success)
out := res.Combined()
out = strings.TrimSpace(out)
if out != dir {
c.Errorf("failed to set working directory, expect %s, got %s", dir, out)
}
}
// TestRunWithWorkingDirExistAndIsFile is to verify the valid running container
// with specifying a exist file as working directory
func (suite *PouchRunWorkingDirSuite) TestRunWithWorkingDirExistAndIsFile(c *check.C) {
SkipIfFalse(c, environment.IsMemorySupport)
dir := "/bin/cat"
cname := "TestRunWithWorkingDirExistAndIsFile"
res := command.PouchRun("run", "-w", dir, "--name", cname, busyboxImage, "pwd")
defer DelContainerForceMultyTime(c, cname)
c.Assert(res.Stderr(), check.NotNil)
expected := "not a directory"
if out := res.Combined(); !strings.Contains(out, expected) {
c.Errorf("error information unmatched, expect %s, got %s", expected, out)
}
}