From 6bbb456138e48c7558cfe5c797c57d136f1a694b Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Mon, 16 Feb 2015 11:32:25 -0800 Subject: [PATCH] readContainerFileWithExec for links tests Shout out to @estesp for the idea. Some use cases of `readContainerFile` can be replaced with `docker exec $id cat $file`. This helper method can eliminate the requirement that host/cli should be on the same machine. TestRunMutableNetworkFiles and TestRunResolvconfUpdater still need to access the docker host filesystem as they modify the file directly from there assuming cli and daemon are on the same machine. This fixes TestLinksUpdateOnRestart and TestLinksHostsFilesInject for Windows CI. Signed-off-by: Ahmet Alp Balkan --- integration-cli/docker_cli_links_test.go | 8 ++++---- integration-cli/docker_utils.go | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index 651e96f8cc..a429902ee4 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -251,12 +251,12 @@ func TestLinksHostsFilesInject(t *testing.T) { time.Sleep(1 * time.Second) - contentOne, err := readContainerFile(idOne, "hosts") + contentOne, err := readContainerFileWithExec(idOne, "/etc/hosts") if err != nil { t.Fatal(err, string(contentOne)) } - contentTwo, err := readContainerFile(idTwo, "hosts") + contentTwo, err := readContainerFileWithExec(idTwo, "/etc/hosts") if err != nil { t.Fatal(err, string(contentTwo)) } @@ -302,7 +302,7 @@ func TestLinksUpdateOnRestart(t *testing.T) { if err != nil { t.Fatal(err) } - content, err := readContainerFile(id, "hosts") + content, err := readContainerFileWithExec(id, "/etc/hosts") if err != nil { t.Fatal(err, string(content)) } @@ -327,7 +327,7 @@ func TestLinksUpdateOnRestart(t *testing.T) { if err != nil { t.Fatal(err) } - content, err = readContainerFile(id, "hosts") + content, err = readContainerFileWithExec(id, "/etc/hosts") if err != nil { t.Fatal(err, string(content)) } diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 56283952ca..2c4518fa14 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -895,6 +895,11 @@ func readContainerFile(containerId, filename string) ([]byte, error) { return content, nil } +func readContainerFileWithExec(containerId, filename string) ([]byte, error) { + out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "exec", containerId, "cat", filename)) + return []byte(out), err +} + func setupRegistry(t *testing.T) func() { reg, err := newTestRegistryV2(t) if err != nil {