Browse code

restart: add test for recording restart policy name

Add test for recording restart policy name on
- restart=no
- restart=always
- restart=on-failure

Signed-off-by: Hu Keping <hukeping@huawei.com>

HuKeping authored on 2015/01/16 18:58:26
Showing 1 changed files
... ...
@@ -151,3 +151,72 @@ func TestRestartWithVolumes(t *testing.T) {
151 151
 
152 152
 	logDone("restart - does not create a new volume on restart")
153 153
 }
154
+
155
+func TestRecordRestartPolicyNO(t *testing.T) {
156
+	defer deleteAllContainers()
157
+
158
+	cmd := exec.Command(dockerBinary, "run", "-d", "--restart=no", "busybox", "false")
159
+	out, _, err := runCommandWithOutput(cmd)
160
+	if err != nil {
161
+		t.Fatal(err, out)
162
+	}
163
+
164
+	id := strings.TrimSpace(string(out))
165
+	name, err := inspectField(id, "HostConfig.RestartPolicy.Name")
166
+	if err != nil {
167
+		t.Fatal(err, out)
168
+	}
169
+	if name != "no" {
170
+		t.Fatalf("Container restart policy name is %s, expected %s", name, "no")
171
+	}
172
+
173
+	logDone("restart - recording restart policy name for --restart=no")
174
+}
175
+
176
+func TestRecordRestartPolicyAlways(t *testing.T) {
177
+	defer deleteAllContainers()
178
+
179
+	cmd := exec.Command(dockerBinary, "run", "-d", "--restart=always", "busybox", "false")
180
+	out, _, err := runCommandWithOutput(cmd)
181
+	if err != nil {
182
+		t.Fatal(err, out)
183
+	}
184
+
185
+	id := strings.TrimSpace(string(out))
186
+	name, err := inspectField(id, "HostConfig.RestartPolicy.Name")
187
+	if err != nil {
188
+		t.Fatal(err, out)
189
+	}
190
+	if name != "always" {
191
+		t.Fatalf("Container restart policy name is %s, expected %s", name, "always")
192
+	}
193
+
194
+	cmd = exec.Command(dockerBinary, "stop", id)
195
+	out, _, err = runCommandWithOutput(cmd)
196
+	if err != nil {
197
+		t.Fatal(err, out)
198
+	}
199
+
200
+	logDone("restart - recording restart policy name for --restart=always")
201
+}
202
+
203
+func TestRecordRestartPolicyOnFailure(t *testing.T) {
204
+	defer deleteAllContainers()
205
+
206
+	cmd := exec.Command(dockerBinary, "run", "-d", "--restart=on-failure:1", "busybox", "false")
207
+	out, _, err := runCommandWithOutput(cmd)
208
+	if err != nil {
209
+		t.Fatal(err, out)
210
+	}
211
+
212
+	id := strings.TrimSpace(string(out))
213
+	name, err := inspectField(id, "HostConfig.RestartPolicy.Name")
214
+	if err != nil {
215
+		t.Fatal(err, out)
216
+	}
217
+	if name != "on-failure" {
218
+		t.Fatalf("Container restart policy name is %s, expected %s", name, "on-failure")
219
+	}
220
+
221
+	logDone("restart - recording restart policy name for --restart=on-failure")
222
+}