Skip to content

Commit

Permalink
libpod/image: unit tests: use a registries.conf for aliases
Browse files Browse the repository at this point in the history
Since some unit tests use "busybox", we need to point it to some alias
if we want it to pass CI on F34 where we're running in enforced mode.

Furthermore, make sure that the registries.conf can actually be
overridden in the code.

Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg authored and mheon committed Mar 29, 2021
1 parent 43c772a commit c9640ba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
12 changes: 9 additions & 3 deletions libpod/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@ func TestImage_New(t *testing.T) {
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)
require.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)
Expand All @@ -168,8 +171,11 @@ func TestImage_MatchRepoTag(t *testing.T) {
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)
newImage, err := ir.New(context.Background(), "busybox", "", "", os.Stdout, &opts, SigningOptions{}, nil, util.PullImageMissing, nil)
require.NoError(t, err)
err = newImage.TagImage("foo:latest")
require.NoError(t, err)
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 c9640ba

Please sign in to comment.