... | ... |
@@ -73,6 +73,77 @@ func cmdWait(srv *Server, container *Container) error { |
73 | 73 |
return closeWrap(stdout, stdoutPipe) |
74 | 74 |
} |
75 | 75 |
|
76 |
+func cmdImages(srv *Server, args ...string) (string, error) { |
|
77 |
+ stdout, stdoutPipe := io.Pipe() |
|
78 |
+ |
|
79 |
+ go func() { |
|
80 |
+ if err := srv.CmdImages(nil, stdoutPipe, args...); err != nil { |
|
81 |
+ return |
|
82 |
+ } |
|
83 |
+ |
|
84 |
+ // force the pipe closed, so that the code below gets an EOF |
|
85 |
+ stdoutPipe.Close() |
|
86 |
+ }() |
|
87 |
+ |
|
88 |
+ output, err := ioutil.ReadAll(stdout) |
|
89 |
+ if err != nil { |
|
90 |
+ return "", err |
|
91 |
+ } |
|
92 |
+ |
|
93 |
+ // Cleanup pipes |
|
94 |
+ return string(output), closeWrap(stdout, stdoutPipe) |
|
95 |
+} |
|
96 |
+ |
|
97 |
+// TestImages checks that 'docker images' displays information correctly |
|
98 |
+func TestImages(t *testing.T) { |
|
99 |
+ |
|
100 |
+ runtime, err := newTestRuntime() |
|
101 |
+ if err != nil { |
|
102 |
+ t.Fatal(err) |
|
103 |
+ } |
|
104 |
+ defer nuke(runtime) |
|
105 |
+ |
|
106 |
+ srv := &Server{runtime: runtime} |
|
107 |
+ |
|
108 |
+ output, err := cmdImages(srv) |
|
109 |
+ |
|
110 |
+ if !strings.Contains(output, "REPOSITORY") { |
|
111 |
+ t.Fatal("'images' should have a header") |
|
112 |
+ } |
|
113 |
+ if !strings.Contains(output, "docker-ut") { |
|
114 |
+ t.Fatal("'images' should show the docker-ut image") |
|
115 |
+ } |
|
116 |
+ if !strings.Contains(output, "e9aa60c60128") { |
|
117 |
+ t.Fatal("'images' should show the docker-ut image id") |
|
118 |
+ } |
|
119 |
+ |
|
120 |
+ output, err = cmdImages(srv, "-q") |
|
121 |
+ |
|
122 |
+ if strings.Contains(output, "REPOSITORY") { |
|
123 |
+ t.Fatal("'images -q' should not have a header") |
|
124 |
+ } |
|
125 |
+ if strings.Contains(output, "docker-ut") { |
|
126 |
+ t.Fatal("'images' should not show the docker-ut image name") |
|
127 |
+ } |
|
128 |
+ if !strings.Contains(output, "e9aa60c60128") { |
|
129 |
+ t.Fatal("'images' should show the docker-ut image id") |
|
130 |
+ } |
|
131 |
+ |
|
132 |
+ output, err = cmdImages(srv, "-viz") |
|
133 |
+ |
|
134 |
+ if !strings.HasPrefix(output, "digraph docker {") { |
|
135 |
+ t.Fatal("'images -v' should start with the dot header") |
|
136 |
+ } |
|
137 |
+ if !strings.HasSuffix(output, "}\n") { |
|
138 |
+ t.Fatal("'images -v' should end with a '}'") |
|
139 |
+ } |
|
140 |
+ if !strings.Contains(output, "base -> \"e9aa60c60128\" [style=invis]") { |
|
141 |
+ t.Fatal("'images -v' should have the docker-ut image id node") |
|
142 |
+ } |
|
143 |
+ |
|
144 |
+ // todo: add checks for -a |
|
145 |
+} |
|
146 |
+ |
|
76 | 147 |
// TestRunHostname checks that 'docker run -h' correctly sets a custom hostname |
77 | 148 |
func TestRunHostname(t *testing.T) { |
78 | 149 |
runtime, err := newTestRuntime() |