Skip to content

Commit

Permalink
Merge pull request #9817 from vrothberg/image-unit-aliases
Browse files Browse the repository at this point in the history
image unit tests - make them pass on F34 with enforced short-name mode
  • Loading branch information
openshift-merge-robot authored Mar 25, 2021
2 parents 896ea08 + 2a66ef3 commit d64ebc5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
57 changes: 26 additions & 31 deletions libpod/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/containers/storage/pkg/reexec"
"github.com/opencontainers/go-digest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
Expand Down Expand Up @@ -93,6 +94,8 @@ func TestImage_NewFromLocal(t *testing.T) {
// Need images to be present for this test
ir, err := NewImageRuntimeFromOptions(so)
assert.NoError(t, err)
defer cleanup(workdir, ir)

ir.Eventer = events.NewNullEventer()
bb, err := ir.New(context.Background(), "docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing, nil)
assert.NoError(t, err)
Expand All @@ -106,13 +109,10 @@ func TestImage_NewFromLocal(t *testing.T) {
assert.NoError(t, err)
for _, name := range image.names {
newImage, err := ir.NewFromLocal(name)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, newImage.ID(), image.img.ID())
}
}

// Shutdown the runtime and remove the temporary storage
cleanup(workdir, ir)
}

// TestImage_New tests pulling the image by various names, tags, and from
Expand All @@ -125,30 +125,31 @@ func TestImage_New(t *testing.T) {
var names []string
workdir, err := mkWorkDir()
assert.NoError(t, err)

so := storage.StoreOptions{
RunRoot: workdir,
GraphRoot: workdir,
}
ir, err := NewImageRuntimeFromOptions(so)
assert.NoError(t, err)
defer cleanup(workdir, ir)

ir.Eventer = events.NewNullEventer()
// Build the list of pull names
names = append(names, bbNames...)
writer := os.Stdout

opts := DockerRegistryOptions{
RegistriesConfPath: "testdata/registries.conf",
}
// Iterate over the names and delete the image
// after the pull
for _, img := range names {
newImage, err := ir.New(context.Background(), img, "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing, nil)
assert.NoError(t, err)
newImage, err := ir.New(context.Background(), img, "", "", writer, &opts, SigningOptions{}, nil, util.PullImageMissing, nil)
require.NoError(t, err, img)
assert.NotEqual(t, newImage.ID(), "")
err = newImage.Remove(context.Background(), false)
assert.NoError(t, err)
}

// Shutdown the runtime and remove the temporary storage
cleanup(workdir, ir)
}

// TestImage_MatchRepoTag tests the various inputs we need to match
Expand All @@ -161,20 +162,24 @@ func TestImage_MatchRepoTag(t *testing.T) {
//Set up
workdir, err := mkWorkDir()
assert.NoError(t, err)

so := storage.StoreOptions{
RunRoot: workdir,
GraphRoot: workdir,
}
ir, err := NewImageRuntimeFromOptions(so)
assert.NoError(t, err)
require.NoError(t, err)
defer cleanup(workdir, ir)

opts := DockerRegistryOptions{
RegistriesConfPath: "testdata/registries.conf",
}
ir.Eventer = events.NewNullEventer()
newImage, err := ir.New(context.Background(), "busybox", "", "", os.Stdout, nil, SigningOptions{}, nil, util.PullImageMissing, nil)
assert.NoError(t, err)
newImage, err := ir.New(context.Background(), "busybox", "", "", os.Stdout, &opts, SigningOptions{}, nil, util.PullImageMissing, nil)
require.NoError(t, err)
err = newImage.TagImage("foo:latest")
assert.NoError(t, err)
require.NoError(t, err)
err = newImage.TagImage("foo:bar")
assert.NoError(t, err)
require.NoError(t, err)

// Tests start here.
for _, name := range bbNames {
Expand All @@ -187,23 +192,19 @@ func TestImage_MatchRepoTag(t *testing.T) {

// foo should resolve to foo:latest
repoTag, err := newImage.MatchRepoTag("foo")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, "localhost/foo:latest", repoTag)

// foo:bar should resolve to foo:bar
repoTag, err = newImage.MatchRepoTag("foo:bar")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, "localhost/foo:bar", repoTag)
// Shutdown the runtime and remove the temporary storage
cleanup(workdir, ir)
}

// TestImage_RepoDigests tests RepoDigest generation.
func TestImage_RepoDigests(t *testing.T) {
dgst, err := digest.Parse("sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

for _, tt := range []struct {
name string
Expand Down Expand Up @@ -235,10 +236,7 @@ func TestImage_RepoDigests(t *testing.T) {
},
}
actual, err := image.RepoDigests()
if err != nil {
t.Fatal(err)
}

require.NoError(t, err)
assert.Equal(t, test.expected, actual)

image = &Image{
Expand All @@ -248,10 +246,7 @@ func TestImage_RepoDigests(t *testing.T) {
},
}
actual, err = image.RepoDigests()
if err != nil {
t.Fatal(err)
}

require.NoError(t, err)
assert.Equal(t, test.expected, actual)
})
}
Expand Down
8 changes: 7 additions & 1 deletion libpod/image/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func (ir *Runtime) pullImageFromHeuristicSource(ctx context.Context, inputName s
sc.OSChoice = dockerOptions.OSChoice
sc.ArchitectureChoice = dockerOptions.ArchitectureChoice
sc.VariantChoice = dockerOptions.VariantChoice
sc.SystemRegistriesConfPath = dockerOptions.RegistriesConfPath
}
if signaturePolicyPath == "" {
sc.SignaturePolicyPath = ir.SignaturePolicyPath
Expand Down Expand Up @@ -306,7 +307,12 @@ func (ir *Runtime) doPullImage(ctx context.Context, sc *types.SystemContext, goa
}
}()

systemRegistriesConfPath := registries.SystemRegistriesConfPath()
var systemRegistriesConfPath string
if dockerOptions != nil && dockerOptions.RegistriesConfPath != "" {
systemRegistriesConfPath = dockerOptions.RegistriesConfPath
} else {
systemRegistriesConfPath = registries.SystemRegistriesConfPath()
}

var (
images []string
Expand Down
4 changes: 4 additions & 0 deletions libpod/image/testdata/registries.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
short-name-mode="enforcing"

[aliases]
"busybox"="docker.io/library/busybox"

0 comments on commit d64ebc5

Please sign in to comment.