zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/pkg/meta/convert/convert_test.go (about) 1 package convert_test 2 3 import ( 4 "testing" 5 "time" 6 7 ispec "github.com/opencontainers/image-spec/specs-go/v1" 8 . "github.com/smartystreets/goconvey/convey" 9 10 "zotregistry.dev/zot/pkg/meta/convert" 11 "zotregistry.dev/zot/pkg/meta/proto/gen" 12 ) 13 14 func TestConvertErrors(t *testing.T) { 15 Convey("Errors", t, func() { 16 Convey("GetImageArtifactType", func() { 17 str := convert.GetImageArtifactType(&gen.ImageMeta{MediaType: "bad-media-type"}) 18 So(str, ShouldResemble, "") 19 }) 20 Convey("GetImageManifestSize", func() { 21 size := convert.GetImageManifestSize(&gen.ImageMeta{MediaType: "bad-media-type"}) 22 So(size, ShouldEqual, 0) 23 }) 24 Convey("GetImageDigest", func() { 25 dig := convert.GetImageDigest(&gen.ImageMeta{MediaType: "bad-media-type"}) 26 So(dig.String(), ShouldResemble, "") 27 }) 28 Convey("GetImageDigestStr", func() { 29 digStr := convert.GetImageDigestStr(&gen.ImageMeta{MediaType: "bad-media-type"}) 30 So(digStr, ShouldResemble, "") 31 }) 32 Convey("GetImageAnnotations", func() { 33 annot := convert.GetImageAnnotations(&gen.ImageMeta{MediaType: "bad-media-type"}) 34 So(annot, ShouldBeEmpty) 35 }) 36 Convey("GetImageSubject", func() { 37 subjs := convert.GetImageSubject(&gen.ImageMeta{MediaType: "bad-media-type"}) 38 So(subjs, ShouldBeNil) 39 }) 40 Convey("GetDescriptorRef", func() { 41 ref := convert.GetDescriptorRef(nil) 42 So(ref, ShouldBeNil) 43 }) 44 Convey("GetPlatform", func() { 45 platf := convert.GetPlatform(nil) 46 So(platf, ShouldEqual, ispec.Platform{}) 47 }) 48 Convey("GetPlatformRef", func() { 49 platf := convert.GetPlatform(&gen.Platform{Architecture: "arch"}) 50 So(platf.Architecture, ShouldResemble, "arch") 51 }) 52 Convey("GetImageReferrers", func() { 53 ref := convert.GetImageReferrers(nil) 54 So(ref, ShouldNotBeNil) 55 }) 56 Convey("GetImageSignatures", func() { 57 sigs := convert.GetImageSignatures(nil) 58 So(sigs, ShouldNotBeNil) 59 }) 60 Convey("GetImageStatistics", func() { 61 sigs := convert.GetImageStatistics(nil) 62 So(sigs, ShouldNotBeNil) 63 }) 64 Convey("GetFullImageMetaFromProto", func() { 65 imageMeta := convert.GetFullImageMetaFromProto("tag", nil, nil) 66 So(imageMeta.Digest.String(), ShouldResemble, "") 67 }) 68 Convey("GetFullManifestData", func() { 69 imageMeta := convert.GetFullManifestData(nil, nil) 70 So(len(imageMeta), ShouldEqual, 0) 71 }) 72 }) 73 } 74 75 func TestGetProtoEarlierUpdatedImage(t *testing.T) { 76 Convey("GetProtoEarlierUpdatedImage with nil params", t, func() { 77 // repoLastImage is nil 78 lastImage := gen.RepoLastUpdatedImage{} 79 80 repoLastUpdatedImage := convert.GetProtoEarlierUpdatedImage(nil, &lastImage) 81 So(repoLastUpdatedImage, ShouldNotBeNil) 82 So(repoLastUpdatedImage.LastUpdated, ShouldBeNil) 83 84 // lastImage is nil 85 repoLastImage := gen.RepoLastUpdatedImage{} 86 87 repoLastUpdatedImage = convert.GetProtoEarlierUpdatedImage(&repoLastImage, nil) 88 So(repoLastUpdatedImage, ShouldNotBeNil) 89 So(repoLastUpdatedImage.LastUpdated, ShouldBeNil) 90 91 // lastImage.LastUpdated is not nil, but repoLastImage.LastUpdated is nil 92 lastUpdated := time.Time{} 93 lastImage = gen.RepoLastUpdatedImage{ 94 LastUpdated: convert.GetProtoTime(&lastUpdated), 95 } 96 97 repoLastUpdatedImage = convert.GetProtoEarlierUpdatedImage(&repoLastImage, &lastImage) 98 So(repoLastUpdatedImage, ShouldNotBeNil) 99 So(repoLastUpdatedImage.LastUpdated, ShouldNotBeNil) 100 }) 101 }