From 41b6ec07ceb4a02f5be84d8b6db8c8faf11d10d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 24 Feb 2023 12:36:53 +0100 Subject: [PATCH] e2e: Skip tests with platform-specific digests on other platforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- e2e/container/run_test.go | 4 ++++ e2e/image/pull_test.go | 4 ++++ e2e/image/push_test.go | 8 ++++++++ e2e/trust/sign_test.go | 6 ++++++ internal/test/environment/testenv.go | 10 ++++++++++ 5 files changed, 32 insertions(+) diff --git a/e2e/container/run_test.go b/e2e/container/run_test.go index dbc005c9f5..3b0414ffab 100644 --- a/e2e/container/run_test.go +++ b/e2e/container/run_test.go @@ -18,6 +18,10 @@ const registryPrefix = "registry:5000" func TestRunAttachedFromRemoteImageAndRemove(t *testing.T) { skip.If(t, environment.RemoteDaemon()) + // Digests in golden file are linux/amd64 specific. + // TODO: Fix this test and make it work on all platforms. + environment.SkipIfNotPlatform(t, "linux/amd64") + image := createRemoteImage(t) result := icmd.RunCommand("docker", "run", "--rm", image, diff --git a/e2e/image/pull_test.go b/e2e/image/pull_test.go index 0d12fe68fa..80779b166d 100644 --- a/e2e/image/pull_test.go +++ b/e2e/image/pull_test.go @@ -17,6 +17,10 @@ const registryPrefix = "registry:5000" func TestPullWithContentTrust(t *testing.T) { skip.If(t, environment.RemoteDaemon()) + // Digests in golden files are linux/amd64 specific. + // TODO: Fix this test and make it work on all platforms. + environment.SkipIfNotPlatform(t, "linux/amd64") + dir := fixtures.SetupConfigFile(t) defer dir.Remove() image := fixtures.CreateMaskedTrustedRemoteImage(t, registryPrefix, "trust-pull", "latest") diff --git a/e2e/image/push_test.go b/e2e/image/push_test.go index 9695c99aa8..0bc3402ce7 100644 --- a/e2e/image/push_test.go +++ b/e2e/image/push_test.go @@ -33,6 +33,10 @@ const ( func TestPushAllTags(t *testing.T) { skip.If(t, environment.RemoteDaemon()) + // Compared digests are linux/amd64 specific. + // TODO: Fix this test and make it work on all platforms. + environment.SkipIfNotPlatform(t, "linux/amd64") + _ = createImage(t, "push-all-tags", "latest", "v1", "v1.0", "v1.0.1") result := icmd.RunCmd(icmd.Command("docker", "push", "--all-tags", registryPrefix+"/push-all-tags")) @@ -51,6 +55,10 @@ func TestPushAllTags(t *testing.T) { func TestPushWithContentTrust(t *testing.T) { skip.If(t, environment.RemoteDaemon()) + // Compared digests are linux/amd64 specific. + // TODO: Fix this test and make it work on all platforms. + environment.SkipIfNotPlatform(t, "linux/amd64") + dir := fixtures.SetupConfigFile(t) defer dir.Remove() image := createImage(t, "trust-push", "latest") diff --git a/e2e/trust/sign_test.go b/e2e/trust/sign_test.go index 9f953b4adb..087620f895 100644 --- a/e2e/trust/sign_test.go +++ b/e2e/trust/sign_test.go @@ -20,6 +20,9 @@ const ( func TestSignLocalImage(t *testing.T) { skip.If(t, environment.RemoteDaemon()) + // Digests in golden files are linux/amd64 specific. + // TODO: Fix this test and make it work on all platforms. + environment.SkipIfNotPlatform(t, "linux/amd64") dir := fixtures.SetupConfigFile(t) defer dir.Remove() @@ -35,6 +38,9 @@ func TestSignLocalImage(t *testing.T) { func TestSignWithLocalFlag(t *testing.T) { skip.If(t, environment.RemoteDaemon()) + // Digests in golden files are linux/amd64 specific. + // TODO: Fix this test and make it work on all platforms. + environment.SkipIfNotPlatform(t, "linux/amd64") dir := fixtures.SetupConfigFile(t) defer dir.Remove() diff --git a/internal/test/environment/testenv.go b/internal/test/environment/testenv.go index a719c1b117..8b035fca1b 100644 --- a/internal/test/environment/testenv.go +++ b/internal/test/environment/testenv.go @@ -98,3 +98,13 @@ func SkipIfCgroupNamespacesNotSupported(t *testing.T) { skip.If(t, !cgroupNsFound, fmt.Sprintf("running against a daemon that doesn't support cgroup namespaces (security options: %s)", result.Stdout())) } + +// SkipIfNotPlatform skips the test if the running docker daemon is not running on a specific platform. +// platform should be in format os/arch (for example linux/arm64). +func SkipIfNotPlatform(t *testing.T, platform string) { + t.Helper() + result := icmd.RunCmd(icmd.Command("docker", "version", "--format", "{{.Server.Os}}/{{.Server.Arch}}")) + result.Assert(t, icmd.Expected{Err: icmd.None}) + daemonPlatform := strings.TrimSpace(result.Stdout()) + skip.If(t, daemonPlatform != platform, "running against a non %s daemon", platform) +}