Skip to content

Commit

Permalink
Merge pullSource tests as table driven format
Browse files Browse the repository at this point in the history
Follow up PR: containers#1411 (comment)
Merge the test and test data of TestPullSourcesMirrorFromReference to TestPullSourcesFromReference

Signed-off-by: Qi Wang <qiwan@redhat.com>
  • Loading branch information
QiWang19 committed Feb 2, 2023
1 parent a49c94a commit bc58a99
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 140 deletions.
75 changes: 21 additions & 54 deletions pkg/sysregistriesv2/system_registries_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,101 +650,68 @@ func TestPullSourcesFromReference(t *testing.T) {
SystemRegistriesConfDirPath: "testdata/this-does-not-exist",
}
registries, err := GetRegistries(sys)
assert.Nil(t, err)
assert.Equal(t, 2, len(registries))

// Registry A allowing any kind of pull from mirrors
registryA, err := FindRegistry(sys, "registry-a.com/foo/image:latest")
assert.Nil(t, err)
assert.NotNil(t, registryA)
// Digest
referenceADigest := toNamedRef(t, "registry-a.com/foo/image@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
pullSources, err := registryA.PullSourcesFromReference(referenceADigest)
assert.Nil(t, err)
assert.Equal(t, 3, len(pullSources))
assert.Equal(t, "mirror-1.registry-a.com/image@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", pullSources[0].Reference.String())
assert.True(t, pullSources[1].Endpoint.Insecure)
// Tag
referenceATag := toNamedRef(t, "registry-a.com/foo/image:aaa")
pullSources, err = registryA.PullSourcesFromReference(referenceATag)
assert.Nil(t, err)
assert.Equal(t, 3, len(pullSources))
assert.Equal(t, "registry-a.com/bar/image:aaa", pullSources[2].Reference.String())

// Registry B allowing digests pull only from mirrors
registryB, err := FindRegistry(sys, "registry-b.com/foo/image:latest")
assert.Nil(t, err)
assert.NotNil(t, registryB)
// Digest
referenceBDigest := toNamedRef(t, "registry-b.com/foo/image@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
pullSources, err = registryB.PullSourcesFromReference(referenceBDigest)
assert.Nil(t, err)
assert.Equal(t, 3, len(pullSources))
assert.Equal(t, "registry-b.com/bar", pullSources[2].Endpoint.Location)
assert.Equal(t, "registry-b.com/bar/image@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", pullSources[2].Reference.String())
// Tag
referenceBTag := toNamedRef(t, "registry-b.com/foo/image:aaa")
pullSources, err = registryB.PullSourcesFromReference(referenceBTag)
assert.Nil(t, err)
assert.Equal(t, 1, len(pullSources))
}

func TestPullSourcesMirrorFromReference(t *testing.T) {
sys := &types.SystemContext{
SystemRegistriesConfPath: "testdata/pull-sources-mirror-reference.conf",
SystemRegistriesConfDirPath: "testdata/this-does-not-exist",
}
registries, err := GetRegistries(sys)
require.NoError(t, err)
assert.Equal(t, 7, len(registries))
assert.Equal(t, 9, len(registries))

digest := "@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
tag := ":aaa"
tag := "aaa"
for _, tc := range []struct {
registry string
digestSources []string
tagSources []string
}{
// Registry A has mirrors allow any kind of pull
// Registry A allowing any kind of pull from mirrors
{
"registry-a.com/foo/image",
[]string{"mirror-1.registry-a.com", "mirror-2.registry-a.com", "registry-a.com/bar"},
[]string{"mirror-1.registry-a.com", "mirror-2.registry-a.com", "registry-a.com/bar"},
},
// Registry B has mirrors allow digests pull only
// Registry B allowing digests pull only from mirrors
{
"registry-b.com/foo/image",
[]string{"mirror-1.registry-b.com", "mirror-2.registry-b.com", "registry-b.com/bar"},
[]string{"registry-b.com/bar"},
},
// Registry A has mirrors allow any kind of pull
{
"registry-a.com/baz/image",
[]string{"mirror-1.registry-a.com", "mirror-2.registry-a.com", "registry-a.com/bar"},
[]string{"mirror-1.registry-a.com", "mirror-2.registry-a.com", "registry-a.com/bar"},
},
// Registry B has mirrors allow digests pull only
{
"registry-b.com/baz/image",
[]string{"mirror-1.registry-b.com", "mirror-2.registry-b.com", "registry-b.com/bar"},
[]string{"registry-b.com/bar"},
},
// Registry C has a mirror allows digest pull only and a mirror allows any kind of pull
{
"registry-c.com/foo/image",
"registry-c.com/baz/image",
[]string{"mirror-1.registry-c.com", "mirror-2.registry-c.com", "registry-c.com/bar"},
[]string{"mirror-1.registry-c.com", "registry-c.com/bar"},
},
// Registry D set digest-only for registry level, allows only digest pulls
// Registry D has no digest-only set for mirrors table
{
"registry-d.com/foo/image",
"registry-d.com/baz/image",
[]string{"mirror-1.registry-d.com", "mirror-2.registry-d.com", "registry-d.com/bar"},
[]string{"registry-d.com/bar"},
},
// Registry E has mirrors only allows tag pull
{
"registry-e.com/foo/image",
"registry-e.com/baz/image",
[]string{"registry-e.com/bar"},
[]string{"mirror-1.registry-e.com", "mirror-2.registry-e.com", "registry-e.com/bar"},
},
// Registry F has one tag only mirror does not allow digest pull
{
"registry-f.com/foo/image",
"registry-f.com/baz/image",
[]string{"mirror-1.registry-f.com", "registry-f.com/bar"},
[]string{"mirror-1.registry-f.com", "mirror-2.registry-f.com", "registry-f.com/bar"},
},
// Registry G has one digest-only pull and one tag only pull
{
"registry-g.com/foo/image",
"registry-g.com/baz/image",
[]string{"mirror-1.registry-g.com", "mirror-3.registry-g.com", "mirror-4.registry-g.com", "registry-g.com/bar"},
[]string{"mirror-2.registry-g.com", "mirror-3.registry-g.com", "mirror-4.registry-g.com", "registry-g.com/bar"},
},
Expand Down
87 changes: 87 additions & 0 deletions pkg/sysregistriesv2/testdata/pull-sources-from-reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,90 @@ location = "mirror-1.registry-b.com"

[[registry.mirror]]
location = "mirror-2.registry-b.com"

[[registry]]
prefix = "registry-a.com/baz"
location = "registry-a.com/bar"

[[registry.mirror]]
location = "mirror-1.registry-a.com"

[[registry.mirror]]
location = "mirror-2.registry-a.com"
insecure = true

[[registry]]
prefix = "registry-b.com/baz"
location = "registry-b.com/bar"

[[registry.mirror]]
pull-from-mirror = "digest-only"
location = "mirror-1.registry-b.com"

[[registry.mirror]]
pull-from-mirror = "digest-only"
location = "mirror-2.registry-b.com"

[[registry]]
prefix = "registry-c.com/baz"
location = "registry-c.com/bar"

[[registry.mirror]]
location = "mirror-1.registry-c.com"

[[registry.mirror]]
pull-from-mirror = "digest-only"
location = "mirror-2.registry-c.com"

[[registry]]
prefix = "registry-d.com/baz"
location = "registry-d.com/bar"
mirror-by-digest-only = true

[[registry.mirror]]
location = "mirror-1.registry-d.com"

[[registry.mirror]]
location = "mirror-2.registry-d.com"

[[registry]]
prefix = "registry-e.com/baz"
location = "registry-e.com/bar"

[[registry.mirror]]
pull-from-mirror = "tag-only"
location = "mirror-1.registry-e.com"

[[registry.mirror]]
pull-from-mirror = "tag-only"
location = "mirror-2.registry-e.com"

[[registry]]
prefix = "registry-f.com/baz"
location = "registry-f.com/bar"

[[registry.mirror]]
location = "mirror-1.registry-f.com"

[[registry.mirror]]
pull-from-mirror = "tag-only"
location = "mirror-2.registry-f.com"

[[registry]]
prefix = "registry-g.com/baz"
location = "registry-g.com/bar"

[[registry.mirror]]
pull-from-mirror = "digest-only"
location = "mirror-1.registry-g.com"

[[registry.mirror]]
pull-from-mirror = "tag-only"
location = "mirror-2.registry-g.com"

[[registry.mirror]]
location = "mirror-3.registry-g.com"

[[registry.mirror]]
pull-from-mirror = "all"
location = "mirror-4.registry-g.com"
86 changes: 0 additions & 86 deletions pkg/sysregistriesv2/testdata/pull-sources-mirror-reference.conf

This file was deleted.

0 comments on commit bc58a99

Please sign in to comment.