From f856b831d150667df81e1a469c1cd2f07325ed47 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Wed, 26 Feb 2020 06:55:54 +0100 Subject: [PATCH 1/2] test: refactor container-diff call Signed-off-by: Yoan Blanc --- integration/integration_test.go | 60 ++++++++++++--------------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/integration/integration_test.go b/integration/integration_test.go index 558a1c53f3..1403e7cffb 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -199,13 +199,7 @@ func TestRun(t *testing.T) { dockerImage := GetDockerImage(config.imageRepo, dockerfile) kanikoImage := GetKanikoImage(config.imageRepo, dockerfile) - // container-diff - daemonDockerImage := daemonPrefix + dockerImage - containerdiffCmd := exec.Command("container-diff", "diff", "--no-cache", - daemonDockerImage, kanikoImage, - "-q", "--type=file", "--type=metadata", "--json") - diff := RunCommand(containerdiffCmd, t) - t.Logf("diff = %s", string(diff)) + diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache") expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage) checkContainerDiffOutput(t, diff, expected) @@ -249,7 +243,7 @@ func TestGitBuildcontext(t *testing.T) { repo})...) out, err := RunCommandWithoutTest(dockerCmd) if err != nil { - t.Errorf("Failed to build image %s with docker command \"%s\": %s %s", dockerImage, dockerCmd.Args, err, string(out)) + t.Errorf("Failed to build image %s with docker command %q: %s %s", dockerImage, dockerCmd.Args, err, string(out)) } // Build with kaniko @@ -265,16 +259,10 @@ func TestGitBuildcontext(t *testing.T) { out, err = RunCommandWithoutTest(kanikoCmd) if err != nil { - t.Errorf("Failed to build image %s with kaniko command \"%s\": %v %s", dockerImage, kanikoCmd.Args, err, string(out)) + t.Errorf("Failed to build image %s with kaniko command %q: %v %s", dockerImage, kanikoCmd.Args, err, string(out)) } - // container-diff - daemonDockerImage := daemonPrefix + dockerImage - containerdiffCmd := exec.Command("container-diff", "diff", "--no-cache", - daemonDockerImage, kanikoImage, - "-q", "--type=file", "--type=metadata", "--json") - diff := RunCommand(containerdiffCmd, t) - t.Logf("diff = %s", string(diff)) + diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache") expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage) checkContainerDiffOutput(t, diff, expected) @@ -293,7 +281,7 @@ func TestBuildViaRegistryMirror(t *testing.T) { repo})...) out, err := RunCommandWithoutTest(dockerCmd) if err != nil { - t.Errorf("Failed to build image %s with docker command \"%s\": %s %s", dockerImage, dockerCmd.Args, err, string(out)) + t.Errorf("Failed to build image %s with docker command %q: %s %s", dockerImage, dockerCmd.Args, err, string(out)) } // Build with kaniko @@ -310,16 +298,10 @@ func TestBuildViaRegistryMirror(t *testing.T) { out, err = RunCommandWithoutTest(kanikoCmd) if err != nil { - t.Errorf("Failed to build image %s with kaniko command \"%s\": %v %s", dockerImage, kanikoCmd.Args, err, string(out)) + t.Errorf("Failed to build image %s with kaniko command %q: %v %s", dockerImage, kanikoCmd.Args, err, string(out)) } - // container-diff - daemonDockerImage := daemonPrefix + dockerImage - containerdiffCmd := exec.Command("container-diff", "diff", "--no-cache", - daemonDockerImage, kanikoImage, - "-q", "--type=file", "--type=metadata", "--json") - diff := RunCommand(containerdiffCmd, t) - t.Logf("diff = %s", string(diff)) + diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache") expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage) checkContainerDiffOutput(t, diff, expected) @@ -391,13 +373,7 @@ func TestCache(t *testing.T) { kanikoVersion0 := GetVersionedKanikoImage(config.imageRepo, dockerfile, 0) kanikoVersion1 := GetVersionedKanikoImage(config.imageRepo, dockerfile, 1) - // container-diff - containerdiffCmd := exec.Command("container-diff", "diff", - kanikoVersion0, kanikoVersion1, - "-q", "--type=file", "--type=metadata", "--json") - - diff := RunCommand(containerdiffCmd, t) - t.Logf("diff = %s", diff) + diff := containerDiff(t, kanikoVersion0, kanikoVersion1) expected := fmt.Sprintf(emptyContainerDiff, kanikoVersion0, kanikoVersion1, kanikoVersion0, kanikoVersion1) checkContainerDiffOutput(t, diff, expected) @@ -420,13 +396,7 @@ func TestRelativePaths(t *testing.T) { dockerImage := GetDockerImage(config.imageRepo, dockerfile) kanikoImage := GetKanikoImage(config.imageRepo, dockerfile) - // container-diff - daemonDockerImage := daemonPrefix + dockerImage - containerdiffCmd := exec.Command("container-diff", "diff", "--no-cache", - daemonDockerImage, kanikoImage, - "-q", "--type=file", "--type=metadata", "--json") - diff := RunCommand(containerdiffCmd, t) - t.Logf("diff = %s", string(diff)) + diff := containerDiff(t, daemonPrefix+dockerImage, kanikoImage, "--no-cache") expected := fmt.Sprintf(emptyContainerDiff, dockerImage, kanikoImage, dockerImage, kanikoImage) checkContainerDiffOutput(t, diff, expected) @@ -657,3 +627,15 @@ func meetsRequirements() bool { } return hasRequirements } + +// containerDiff compares the container images image1 and image2. +func containerDiff(t *testing.T, image1, image2 string, flags ...string) []byte { + flags = append(flags, image1, image2, + "-q", "--type=file", "--type=metadata", "--json") + + containerdiffCmd := exec.Command("container-diff", "diff", flags...) + diff := RunCommand(containerdiffCmd, t) + t.Logf("diff = %s", string(diff)) + + return diff +} From 8b34c99de8dfea4fb37159f02369c17d5a37f5a8 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Wed, 26 Feb 2020 14:11:30 +0100 Subject: [PATCH 2/2] fixup! integration: refactor container-diff Signed-off-by: Yoan Blanc --- integration/integration_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration/integration_test.go b/integration/integration_test.go index 1403e7cffb..1425256037 100644 --- a/integration/integration_test.go +++ b/integration/integration_test.go @@ -630,10 +630,11 @@ func meetsRequirements() bool { // containerDiff compares the container images image1 and image2. func containerDiff(t *testing.T, image1, image2 string, flags ...string) []byte { + flags = append([]string{"diff"}, flags...) flags = append(flags, image1, image2, "-q", "--type=file", "--type=metadata", "--json") - containerdiffCmd := exec.Command("container-diff", "diff", flags...) + containerdiffCmd := exec.Command("container-diff", flags...) diff := RunCommand(containerdiffCmd, t) t.Logf("diff = %s", string(diff))