From bc58a9910164b260389616efcb5701420adb4414 Mon Sep 17 00:00:00 2001 From: Qi Wang Date: Thu, 2 Feb 2023 17:49:09 -0500 Subject: [PATCH] Merge pullSource tests as table driven format Follow up PR: https://github.com/containers/image/pull/1411#discussion_r785275923 Merge the test and test data of TestPullSourcesMirrorFromReference to TestPullSourcesFromReference Signed-off-by: Qi Wang --- .../system_registries_v2_test.go | 75 +++++----------- .../testdata/pull-sources-from-reference.conf | 87 +++++++++++++++++++ .../pull-sources-mirror-reference.conf | 86 ------------------ 3 files changed, 108 insertions(+), 140 deletions(-) delete mode 100644 pkg/sysregistriesv2/testdata/pull-sources-mirror-reference.conf diff --git a/pkg/sysregistriesv2/system_registries_v2_test.go b/pkg/sysregistriesv2/system_registries_v2_test.go index 6e4be24dff..9305688445 100644 --- a/pkg/sysregistriesv2/system_registries_v2_test.go +++ b/pkg/sysregistriesv2/system_registries_v2_test.go @@ -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"}, }, diff --git a/pkg/sysregistriesv2/testdata/pull-sources-from-reference.conf b/pkg/sysregistriesv2/testdata/pull-sources-from-reference.conf index f01176dbae..a4f7fd3f83 100644 --- a/pkg/sysregistriesv2/testdata/pull-sources-from-reference.conf +++ b/pkg/sysregistriesv2/testdata/pull-sources-from-reference.conf @@ -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" \ No newline at end of file diff --git a/pkg/sysregistriesv2/testdata/pull-sources-mirror-reference.conf b/pkg/sysregistriesv2/testdata/pull-sources-mirror-reference.conf deleted file mode 100644 index 50d51c2892..0000000000 --- a/pkg/sysregistriesv2/testdata/pull-sources-mirror-reference.conf +++ /dev/null @@ -1,86 +0,0 @@ -[[registry]] -prefix = "registry-a.com/foo" -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/foo" -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/foo" -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/foo" -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/foo" -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/foo" -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/foo" -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"