Skip to content

Commit

Permalink
e2e: Skip tests with platform-specific digests on other platforms
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
  • Loading branch information
vvoland committed Apr 27, 2023
1 parent 591320d commit 41b6ec0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions e2e/container/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions e2e/image/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions e2e/image/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand All @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions e2e/trust/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions internal/test/environment/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 41b6ec0

Please sign in to comment.