1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

add tests

Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
This commit is contained in:
Victor Vieux 2014-07-22 18:16:15 +00:00
parent f3b2c93b9f
commit fc39f9c78d

View file

@ -1549,3 +1549,84 @@ func TestRunExitOnStdinClose(t *testing.T) {
} }
logDone("run - exit on stdin closing") logDone("run - exit on stdin closing")
} }
// Test for #2267
func TestWriteHostsFileAndNotCommit(t *testing.T) {
name := "writehosts"
cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hosts && cat /etc/hosts")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
if !strings.Contains(out, "test2267") {
t.Fatal("/etc/hosts should contain 'test2267'")
}
cmd = exec.Command(dockerBinary, "diff", name)
if err != nil {
t.Fatal(err, out)
}
out, _, err = runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
if len(strings.Trim(out, "\r\n")) != 0 {
t.Fatal("diff should be empty")
}
logDone("run - write to /etc/hosts and not commited")
}
// Test for #2267
func TestWriteHostnameFileAndNotCommit(t *testing.T) {
name := "writehostname"
cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/hostname && cat /etc/hostname")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
if !strings.Contains(out, "test2267") {
t.Fatal("/etc/hostname should contain 'test2267'")
}
cmd = exec.Command(dockerBinary, "diff", name)
if err != nil {
t.Fatal(err, out)
}
out, _, err = runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
if len(strings.Trim(out, "\r\n")) != 0 {
t.Fatal("diff should be empty")
}
logDone("run - write to /etc/hostname and not commited")
}
// Test for #2267
func TestWriteResolvFileAndNotCommit(t *testing.T) {
name := "writeresolv"
cmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo test2267 >> /etc/resolv.conf && cat /etc/resolv.conf")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
if !strings.Contains(out, "test2267") {
t.Fatal("/etc/resolv.conf should contain 'test2267'")
}
cmd = exec.Command(dockerBinary, "diff", name)
if err != nil {
t.Fatal(err, out)
}
out, _, err = runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
if len(strings.Trim(out, "\r\n")) != 0 {
t.Fatal("diff should be empty")
}
logDone("run - write to /etc/resolv.conf and not commited")
}