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 <ahmetalpbalkan@gmail.com> Upstream-commit: 6bbb456138e48c7558cfe5c797c57d136f1a694b Component: engine
This commit is contained in:
@ -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))
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user