Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
- FakeRegistry should keep state of images that are written to it, so
that it may serve them later

Co-authored-by: Dennis Leon <[email protected]>
Co-authored-by: Cari Dean <[email protected]>
  • Loading branch information
DennisDenuto and cari-lynn committed Feb 3, 2021
1 parent a27bf13 commit 83e196f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/imgpkg/cmd/copy_repo_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (o CopyRepoSrc) CopyToTar(dstPath string) error {
if err != nil {
return err
}

ids, err := o.tarImageSet.Export(unprocessedImageRefs, dstPath, o.registry, imagelayers.NewImageLayerWriterCheck(o.IncludeNonDistributableFlag.IncludeNonDistributable))
if err != nil {
return err
Expand Down
30 changes: 26 additions & 4 deletions pkg/imgpkg/cmd/fake_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,29 @@ func (r *FakeRegistry) Build() *imagesetfakes.FakeImagesReaderWriter {
fakeRegistry := &imagesetfakes.FakeImagesReaderWriter{}
fakeRegistry.GenericCalls(func(reference name.Reference) (descriptor v1.Descriptor, err error) {
mediaType := types.OCIManifestSchema1
if val, found := r.state[reference.String()]; found {
if val, found := r.state[reference.Context().String()]; found {
if val.image != nil {
mediaType, err = r.state[reference.String()].image.MediaType()
} else {
mediaType, err = r.state[reference.String()].imageIndex.MediaType()
mediaType, err = r.state[reference.Context().String()].image.MediaType()
digest, err := val.image.Digest()
if err != nil {
r.t.Fatal(err.Error())
}
return v1.Descriptor{
MediaType: mediaType,
Digest: digest,
}, nil
}

imageIndex := r.state[reference.Context().String()].imageIndex
digest, err := imageIndex.Digest()
if err != nil {
r.t.Fatal(err.Error())
}
mediaType, err = imageIndex.MediaType()
return v1.Descriptor{
MediaType: mediaType,
Digest: digest,
}, nil
}

return v1.Descriptor{
Expand All @@ -54,6 +71,11 @@ func (r *FakeRegistry) Build() *imagesetfakes.FakeImagesReaderWriter {
}, nil
})

fakeRegistry.WriteImageStub = func(reference name.Reference, v v1.Image) error {
r.state[reference.Context().Name()] = &ImageOrImageIndexWithTarPath{t: r.t, image: v}
return nil
}

fakeRegistry.ImageStub = func(reference name.Reference) (v v1.Image, err error) {
if bundle, found := r.state[reference.Context().Name()]; found {
return bundle.image, nil
Expand Down

0 comments on commit 83e196f

Please sign in to comment.