Skip to content

Commit

Permalink
Fix broken TestImageInspectDifferentValidReferencesForTheSameImage
Browse files Browse the repository at this point in the history
Signed-off-by: apostasie <spam_blackhole@farcloser.world>
  • Loading branch information
apostasie committed Oct 2, 2024
1 parent b943664 commit 061a0d9
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions cmd/nerdctl/image/image_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package image

import (
"encoding/json"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -71,18 +70,15 @@ func TestImageInspectSimpleCases(t *testing.T) {
func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) {
nerdtest.Setup()

platform := runtime.GOOS + "/" + runtime.GOARCH

tags := []string{
"",
":latest",
":stable",
}
names := []string{
"busybox",
"library/busybox",
"docker.io/library/busybox",
"registry-1.docker.io/library/busybox",
"apostasie/busybox",
"docker.io/apostasie/busybox",
"registry-1.docker.io/apostasie/busybox",
}

testCase := &test.Case{
Expand All @@ -94,16 +90,16 @@ func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) {
nerdtest.Private,
),
Setup: func(data test.Data, helpers test.Helpers) {
helpers.Ensure("pull", "alpine", "--platform", platform)
helpers.Ensure("pull", "busybox", "--platform", platform)
helpers.Ensure("pull", "busybox:stable", "--platform", platform)
helpers.Ensure("pull", "registry-1.docker.io/library/busybox", "--platform", platform)
helpers.Ensure("pull", "registry-1.docker.io/library/busybox:stable", "--platform", platform)
helpers.Ensure("pull", "alpine")
helpers.Ensure("pull", "apostasie/busybox")
helpers.Ensure("pull", "apostasie/busybox:stable")
helpers.Ensure("pull", "registry-1.docker.io/apostasie/busybox")
helpers.Ensure("pull", "registry-1.docker.io/apostasie/busybox:stable")
},
SubTests: []*test.Case{
{
Description: "name and tags +/- sha combinations",
Command: test.RunCommand("image", "inspect", "busybox"),
Command: test.RunCommand("image", "inspect", "apostasie/busybox"),
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: func(stdout string, info string, t *testing.T) {
Expand All @@ -112,7 +108,7 @@ func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) {
assert.NilError(t, err, "Unable to unmarshal output\n"+info)
assert.Equal(t, 1, len(dc), "Unexpectedly got multiple results\n"+info)
reference := dc[0].ID
sha := strings.TrimPrefix(dc[0].RepoDigests[0], "busybox@sha256:")
sha := strings.TrimPrefix(dc[0].RepoDigests[0], "apostasie/busybox@sha256:")

for _, name := range names {
for _, tag := range tags {
Expand All @@ -128,7 +124,7 @@ func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) {
},
{
Description: "by digest, short or long, with or without prefix",
Command: test.RunCommand("image", "inspect", "busybox"),
Command: test.RunCommand("image", "inspect", "apostasie/busybox"),
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: func(stdout string, info string, t *testing.T) {
Expand All @@ -137,7 +133,7 @@ func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) {
assert.NilError(t, err, "Unable to unmarshal output\n"+info)
assert.Equal(t, 1, len(dc), "Unexpectedly got multiple results\n"+info)
reference := dc[0].ID
sha := strings.TrimPrefix(dc[0].RepoDigests[0], "busybox@sha256:")
sha := strings.TrimPrefix(dc[0].RepoDigests[0], "apostasie/busybox@sha256:")

for _, id := range []string{"sha256:" + sha, sha, sha[0:8], "sha256:" + sha[0:8]} {
it := nerdtest.InspectImage(helpers, id)
Expand All @@ -159,17 +155,17 @@ func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) {
},
{
Description: "prove that wrong references with correct digest do not get resolved",
Command: test.RunCommand("image", "inspect", "busybox"),
Command: test.RunCommand("image", "inspect", "apostasie/busybox"),
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: func(stdout string, info string, t *testing.T) {
var dc []dockercompat.Image
err := json.Unmarshal([]byte(stdout), &dc)
assert.NilError(t, err, "Unable to unmarshal output\n"+info)
assert.Equal(t, 1, len(dc), "Unexpectedly got multiple results\n"+info)
sha := strings.TrimPrefix(dc[0].RepoDigests[0], "busybox@sha256:")
sha := strings.TrimPrefix(dc[0].RepoDigests[0], "apostasie/busybox@sha256:")

for _, id := range []string{"doesnotexist", "doesnotexist:either", "busybox:bogustag"} {
for _, id := range []string{"doesnotexist", "doesnotexist:either", "apostasie/busybox:bogustag"} {
cmd := helpers.Command("image", "inspect", id+"@sha256:"+sha)
cmd.Run(&test.Expected{
Output: test.Equals(""),
Expand All @@ -181,7 +177,7 @@ func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) {
},
{
Description: "prove that invalid reference return no result without crashing",
Command: test.RunCommand("image", "inspect", "busybox"),
Command: test.RunCommand("image", "inspect", "apostasie/busybox"),
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: func(stdout string, info string, t *testing.T) {
Expand All @@ -202,15 +198,15 @@ func TestImageInspectDifferentValidReferencesForTheSameImage(t *testing.T) {
},
{
Description: "retrieving multiple entries at once",
Command: test.RunCommand("image", "inspect", "busybox", "busybox", "busybox:stable"),
Command: test.RunCommand("image", "inspect", "apostasie/busybox", "apostasie/busybox", "apostasie/busybox:stable"),
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
return &test.Expected{
Output: func(stdout string, info string, t *testing.T) {
var dc []dockercompat.Image
err := json.Unmarshal([]byte(stdout), &dc)
assert.NilError(t, err, "Unable to unmarshal output\n"+info)
assert.Equal(t, 3, len(dc), "Unexpectedly did not get 3 results\n"+info)
reference := nerdtest.InspectImage(helpers, "busybox")
reference := nerdtest.InspectImage(helpers, "apostasie/busybox")
assert.Equal(t, dc[0].ID, reference.ID)
assert.Equal(t, dc[1].ID, reference.ID)
assert.Equal(t, dc[2].ID, reference.ID)
Expand Down

0 comments on commit 061a0d9

Please sign in to comment.