forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_pull_test.go
75 lines (58 loc) · 1.96 KB
/
cli_pull_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
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"
)
// PouchPullSuite is the test suite for pull CLI.
type PouchPullSuite struct{}
func init() {
check.Suite(&PouchPullSuite{})
}
// SetUpSuite does common setup in the beginning of each test suite.
func (suite *PouchPullSuite) SetUpSuite(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
environment.PruneAllContainers(apiClient)
}
// TearDownTest does cleanup work in the end of each test.
func (suite *PouchPullSuite) TearDownTest(c *check.C) {
}
// TestPullWorks tests "pouch pull" work.
func (suite *PouchPullSuite) TestPullWorks(c *check.C) {
checkPull := func(target string, expected string) {
command.PouchRun("pull", target).Assert(c, icmd.Success)
res := command.PouchRun("images").Assert(c, icmd.Success)
if out := res.Combined(); !strings.Contains(out, expected) {
c.Fatalf("unexpected output %s: should got image %s\n", out, expected)
}
command.PouchRun("rmi", "-f", expected).Assert(c, icmd.Success)
}
busyboxRepo := environment.BusyboxRepo
// without tag
latest := busyboxRepo + ":latest"
checkPull(busyboxRepo, latest)
// with latest
checkPull(latest, latest)
// with default tag
version := busyboxRepo + ":" + environment.BusyboxTag
checkPull(version, version)
// image with digest for tag
busyboxDigest := busyboxRepo + "@" + environment.BusyboxDigest
busyboxDigestWithWrongTag := busyboxRepo + ":whatever" + "@" + environment.BusyboxDigest
checkPull(busyboxDigestWithWrongTag, busyboxDigest)
}
// TestPullInWrongWay pulls in wrong way.
func (suite *PouchPullSuite) TestPullInWrongWay(c *check.C) {
// pull unknown images
{
res := command.PouchRun("pull", "unknown")
c.Assert(res.Stderr(), check.NotNil)
}
// pull with invalid flag
{
res := command.PouchRun("pull", busyboxImage, "-f")
c.Assert(res.Stderr(), check.NotNil)
}
}