Test for updating hosts files via links.
Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
This commit is contained in:
parent
20575d20ba
commit
68bc8de111
2 changed files with 39 additions and 1 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/iptables"
|
||||
)
|
||||
|
@ -177,3 +178,39 @@ func TestLinksNotStartedParentNotFail(t *testing.T) {
|
|||
}
|
||||
logDone("link - container start not failing on updating stopped parent links")
|
||||
}
|
||||
|
||||
func TestLinksHostsFilesInject(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
|
||||
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "one", "busybox", "top"))
|
||||
if err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
|
||||
idOne := strings.TrimSpace(out)
|
||||
|
||||
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top"))
|
||||
if err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
|
||||
idTwo := strings.TrimSpace(out)
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
contentOne, err := readContainerFile(idOne, "hosts")
|
||||
if err != nil {
|
||||
t.Fatal(err, string(contentOne))
|
||||
}
|
||||
|
||||
contentTwo, err := readContainerFile(idTwo, "hosts")
|
||||
if err != nil {
|
||||
t.Fatal(err, string(contentTwo))
|
||||
}
|
||||
|
||||
if !strings.Contains(string(contentTwo), "onetwo") {
|
||||
t.Fatal("Host is not present in updated hosts file", string(contentTwo))
|
||||
}
|
||||
|
||||
logDone("link - ensure containers hosts files are updated with the link alias.")
|
||||
}
|
||||
|
|
|
@ -736,10 +736,11 @@ func containerStorageFile(containerId, basename string) string {
|
|||
return filepath.Join("/var/lib/docker/containers", containerId, basename)
|
||||
}
|
||||
|
||||
// docker commands that use this function must be run with the '-d' switch.
|
||||
func runCommandAndReadContainerFile(filename string, cmd *exec.Cmd) ([]byte, error) {
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("%v: %q", err, out)
|
||||
}
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
|
Loading…
Reference in a new issue