Skip to content

Commit

Permalink
Update testdata to handle aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Sep 15, 2023
1 parent 103b44c commit b09e449
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
9 changes: 6 additions & 3 deletions manifest/image/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,16 @@ func (l *ImageList) Dedup() error {
}
})

l.MakeAliases()

return nil
}

func (l *ImageList) MakeAliases() {
aliases := NewAliasCache(l.items).MakeAliasesForNames()
// TODO: check uniqueness of aliases, use tags and/or digests to disambiguate
for i := range aliases {
l.items[i].Alias = &aliases[i]
}

return nil
}

func (l *ImageList) Len() int { return len(l.items) }
Expand Down
2 changes: 2 additions & 0 deletions manifest/imagecopier/imagecopier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func makeImageCopierTest(tc testdata.TestCase) func(t *testing.T) {

SetNewImageRefs(makeDestination(tc.Description), sha256.New(), tc.Expected)

images.MakeAliases()

if tc.Expected != nil {
g.Expect(images.Items()).To(ConsistOf(tc.Expected))
} else {
Expand Down
2 changes: 2 additions & 0 deletions manifest/imageresolver/imageresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func makeImageResolverTest(tc testdata.TestCase) func(t *testing.T) {
resolver := NewRegistryResolver(nil)
g.Expect(resolver.ResolveDigests(ctx, images)).To(Succeed())

images.MakeAliases()

if tc.Expected != nil {
g.Expect(images.Items()).To(ConsistOf(tc.Expected))
} else {
Expand Down
2 changes: 2 additions & 0 deletions manifest/packager/packager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func makePackagerTest(tc testdata.TestCase) func(t *testing.T) {

g.Expect(updater.NewFileUpdater().Update(images)).To(Succeed())

images.MakeAliases()

if tc.Expected != nil {
g.Expect(images.Items()).To(ConsistOf(tc.Expected))
} else {
Expand Down
15 changes: 15 additions & 0 deletions manifest/testdata/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ var baseCasesDigests = map[string]string{
"ghcr.io/fluxcd/source-controller:v0.31.0": "sha256:1e0b062d5129a462250eb03c5e8bd09b4cc42e88b25e39e35eee81d7ed2d15c0",
}

var baseCasesAliases = map[string]string{
"ghcr.io/projectcontour/contour:v1.24.1": "contour",
"docker.io/envoyproxy/envoy:v1.25.1": "envoy",
"ghcr.io/fluxcd/kustomize-controller:v0.30.0": "kustomize-controller",
"ghcr.io/fluxcd/source-controller:v0.31.0": "source-controller",
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/webhook:v0.40.2@sha256:6b8aadbdcede63969ecb719e910b55b7681d87110fc0bf92ca4ee943042f620b": "webhook",
"gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/controller:v0.40.2@sha256:dc7bc7d6607466b502d8dc22ba0598461d7477f608ab68aaff1ff4dedaa04f81": "controller",
}

func BaseYAMLCases() TestCases {
baseCases := make([]TestCase, len(baseYAMLCases))
copy(baseCases, baseYAMLCases)
Expand All @@ -298,6 +307,12 @@ func BaseYAMLCasesWithDigests(t *testing.T) TestCases {
t.Logf("digest not found for %s", c.Expected[e].OriginalRef())
t.FailNow()
}
if alias, ok := baseCasesAliases[c.Expected[e].OriginalRef()]; ok {
c.Expected[e].Alias = &alias
} else if c.Expected[e].Alias == nil {
t.Logf("alias not found for %s", c.Expected[e].OriginalRef())
t.FailNow()
}
}
baseCases[i] = c
}
Expand Down
2 changes: 2 additions & 0 deletions manifest/updater/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func makeUpdaterTest(tc testdata.TestCase) func(t *testing.T) {

g.Expect(NewFileUpdater().Update(images)).To(Succeed())

images.MakeAliases()

if tc.Expected != nil {
g.Expect(images.Items()).To(ConsistOf(tc.Expected))
} else {
Expand Down

0 comments on commit b09e449

Please sign in to comment.