-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_cli_rm_test.go
95 lines (77 loc) · 2.73 KB
/
docker_cli_rm_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
package main
import (
"os"
"strings"
"github.com/go-check/check"
)
func (s *DockerSuite) TestRmContainerWithRemovedVolume(c *check.C) {
testRequires(c, DaemonIsLinux)
testRequires(c, SameHostDaemon)
dockerCmd(c, "run", "--name", "losemyvolumes", "-v", "/tmp/testing:/test", "busybox", "true")
if err := os.Remove("/tmp/testing"); err != nil {
c.Fatal(err)
}
dockerCmd(c, "rm", "-v", "losemyvolumes")
}
func (s *DockerSuite) TestRmContainerWithVolume(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerCmd(c, "run", "--name", "foo", "-v", "/srv", "busybox", "true")
dockerCmd(c, "rm", "-v", "foo")
}
func (s *DockerSuite) TestRmRunningContainer(c *check.C) {
testRequires(c, DaemonIsLinux)
createRunningContainer(c, "foo")
if _, _, err := dockerCmdWithError("rm", "foo"); err == nil {
c.Fatalf("Expected error, can't rm a running container")
}
}
func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {
testRequires(c, DaemonIsLinux)
createRunningContainer(c, "foo")
// Stop then remove with -s
dockerCmd(c, "rm", "-f", "foo")
}
func (s *DockerSuite) TestRmContainerOrphaning(c *check.C) {
testRequires(c, DaemonIsLinux)
dockerfile1 := `FROM busybox:latest
ENTRYPOINT ["/bin/true"]`
img := "test-container-orphaning"
dockerfile2 := `FROM busybox:latest
ENTRYPOINT ["/bin/true"]
MAINTAINER Integration Tests`
// build first dockerfile
img1, err := buildImage(img, dockerfile1, true)
if err != nil {
c.Fatalf("Could not build image %s: %v", img, err)
}
// run container on first image
if out, _, err := dockerCmdWithError("run", img); err != nil {
c.Fatalf("Could not run image %s: %v: %s", img, err, out)
}
// rebuild dockerfile with a small addition at the end
if _, err := buildImage(img, dockerfile2, true); err != nil {
c.Fatalf("Could not rebuild image %s: %v", img, err)
}
// try to remove the image, should error out.
if out, _, err := dockerCmdWithError("rmi", img); err == nil {
c.Fatalf("Expected to error out removing the image, but succeeded: %s", out)
}
// check if we deleted the first image
out, _, err := dockerCmdWithError("images", "-q", "--no-trunc")
if err != nil {
c.Fatalf("%v: %s", err, out)
}
if !strings.Contains(out, img1) {
c.Fatalf("Orphaned container (could not find %q in docker images): %s", img1, out)
}
}
func (s *DockerSuite) TestRmInvalidContainer(c *check.C) {
if out, _, err := dockerCmdWithError("rm", "unknown"); err == nil {
c.Fatal("Expected error on rm unknown container, got none")
} else if !strings.Contains(out, "failed to remove containers") {
c.Fatalf("Expected output to contain 'failed to remove containers', got %q", out)
}
}
func createRunningContainer(c *check.C, name string) {
dockerCmd(c, "run", "-dt", "--name", name, "busybox", "top")
}