mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 12:58:02 +08:00
fix(cov): coverage boltdb+dynamo (#2018)
Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
@@ -327,7 +327,7 @@ func GetImageManifestMeta(manifestContent ispec.Manifest, configContent ispec.Im
|
||||
MediaType: ispec.MediaTypeImageManifest,
|
||||
Digest: digest,
|
||||
Size: size,
|
||||
Manifests: []mTypes.ManifestData{
|
||||
Manifests: []mTypes.ManifestMeta{
|
||||
{
|
||||
Digest: digest,
|
||||
Size: size,
|
||||
@@ -361,11 +361,11 @@ func GetTags(tags map[string]*proto_go.TagDescriptor) map[string]mTypes.Descript
|
||||
return resultMap
|
||||
}
|
||||
|
||||
func GetManifests(descriptors []ispec.Descriptor) []mTypes.ManifestData {
|
||||
manifestList := []mTypes.ManifestData{}
|
||||
func GetManifests(descriptors []ispec.Descriptor) []mTypes.ManifestMeta {
|
||||
manifestList := []mTypes.ManifestMeta{}
|
||||
|
||||
for _, manifest := range descriptors {
|
||||
manifestList = append(manifestList, mTypes.ManifestData{
|
||||
manifestList = append(manifestList, mTypes.ManifestMeta{
|
||||
Digest: manifest.Digest,
|
||||
Size: manifest.Size,
|
||||
})
|
||||
@@ -384,6 +384,10 @@ func GetTime(time *timestamppb.Timestamp) *time.Time {
|
||||
|
||||
func GetFullImageMetaFromProto(tag string, protoRepoMeta *proto_go.RepoMeta, protoImageMeta *proto_go.ImageMeta,
|
||||
) mTypes.FullImageMeta {
|
||||
if protoRepoMeta == nil {
|
||||
return mTypes.FullImageMeta{}
|
||||
}
|
||||
|
||||
imageMeta := GetImageMeta(protoImageMeta)
|
||||
imageDigest := imageMeta.Digest.String()
|
||||
|
||||
@@ -404,7 +408,7 @@ func GetFullImageMetaFromProto(tag string, protoRepoMeta *proto_go.RepoMeta, pro
|
||||
}
|
||||
}
|
||||
|
||||
func GetFullManifestData(protoRepoMeta *proto_go.RepoMeta, manifestData []mTypes.ManifestData,
|
||||
func GetFullManifestData(protoRepoMeta *proto_go.RepoMeta, manifestData []mTypes.ManifestMeta,
|
||||
) []mTypes.FullManifestMeta {
|
||||
if protoRepoMeta == nil {
|
||||
return []mTypes.FullManifestMeta{}
|
||||
@@ -414,7 +418,7 @@ func GetFullManifestData(protoRepoMeta *proto_go.RepoMeta, manifestData []mTypes
|
||||
|
||||
for i := range manifestData {
|
||||
results = append(results, mTypes.FullManifestMeta{
|
||||
ManifestData: manifestData[i],
|
||||
ManifestMeta: manifestData[i],
|
||||
Referrers: GetImageReferrers(protoRepoMeta.Referrers[manifestData[i].Digest.String()]),
|
||||
Statistics: GetImageStatistics(protoRepoMeta.Statistics[manifestData[i].Digest.String()]),
|
||||
Signatures: GetImageSignatures(protoRepoMeta.Signatures[manifestData[i].Digest.String()]),
|
||||
@@ -511,6 +515,10 @@ func GetLastUpdatedImage(protoLastUpdated *proto_go.RepoLastUpdatedImage) *mType
|
||||
}
|
||||
|
||||
func GetImageMeta(dbImageMeta *proto_go.ImageMeta) mTypes.ImageMeta {
|
||||
if dbImageMeta == nil {
|
||||
return mTypes.ImageMeta{}
|
||||
}
|
||||
|
||||
imageMeta := mTypes.ImageMeta{
|
||||
MediaType: dbImageMeta.MediaType,
|
||||
Size: GetImageManifestSize(dbImageMeta),
|
||||
@@ -538,10 +546,10 @@ func GetImageMeta(dbImageMeta *proto_go.ImageMeta) mTypes.ImageMeta {
|
||||
}
|
||||
}
|
||||
|
||||
manifestDataList := make([]mTypes.ManifestData, 0, len(dbImageMeta.Manifests))
|
||||
manifestDataList := make([]mTypes.ManifestMeta, 0, len(dbImageMeta.Manifests))
|
||||
|
||||
for _, manifest := range dbImageMeta.Manifests {
|
||||
manifestDataList = append(manifestDataList, mTypes.ManifestData{
|
||||
manifestDataList = append(manifestDataList, mTypes.ManifestMeta{
|
||||
Size: manifest.Size,
|
||||
Digest: godigest.Digest(manifest.Digest),
|
||||
Manifest: ispec.Manifest{
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package convert_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"zotregistry.io/zot/pkg/meta/convert"
|
||||
"zotregistry.io/zot/pkg/meta/proto/gen"
|
||||
)
|
||||
|
||||
func TestConvertErrors(t *testing.T) {
|
||||
Convey("Errors", t, func() {
|
||||
Convey("GetImageArtifactType", func() {
|
||||
str := convert.GetImageArtifactType(&gen.ImageMeta{MediaType: "bad-media-type"})
|
||||
So(str, ShouldResemble, "")
|
||||
})
|
||||
Convey("GetImageManifestSize", func() {
|
||||
size := convert.GetImageManifestSize(&gen.ImageMeta{MediaType: "bad-media-type"})
|
||||
So(size, ShouldEqual, 0)
|
||||
})
|
||||
Convey("GetImageDigest", func() {
|
||||
dig := convert.GetImageDigest(&gen.ImageMeta{MediaType: "bad-media-type"})
|
||||
So(dig.String(), ShouldResemble, "")
|
||||
})
|
||||
Convey("GetImageDigestStr", func() {
|
||||
digStr := convert.GetImageDigestStr(&gen.ImageMeta{MediaType: "bad-media-type"})
|
||||
So(digStr, ShouldResemble, "")
|
||||
})
|
||||
Convey("GetImageAnnotations", func() {
|
||||
annot := convert.GetImageAnnotations(&gen.ImageMeta{MediaType: "bad-media-type"})
|
||||
So(annot, ShouldBeEmpty)
|
||||
})
|
||||
Convey("GetImageSubject", func() {
|
||||
subjs := convert.GetImageSubject(&gen.ImageMeta{MediaType: "bad-media-type"})
|
||||
So(subjs, ShouldBeNil)
|
||||
})
|
||||
Convey("GetDescriptorRef", func() {
|
||||
ref := convert.GetDescriptorRef(nil)
|
||||
So(ref, ShouldBeNil)
|
||||
})
|
||||
Convey("GetPlatform", func() {
|
||||
platf := convert.GetPlatform(nil)
|
||||
So(platf, ShouldEqual, ispec.Platform{})
|
||||
})
|
||||
Convey("GetPlatformRef", func() {
|
||||
platf := convert.GetPlatform(&gen.Platform{Architecture: "arch"})
|
||||
So(platf.Architecture, ShouldResemble, "arch")
|
||||
})
|
||||
Convey("GetImageReferrers", func() {
|
||||
ref := convert.GetImageReferrers(nil)
|
||||
So(ref, ShouldNotBeNil)
|
||||
})
|
||||
Convey("GetImageSignatures", func() {
|
||||
sigs := convert.GetImageSignatures(nil)
|
||||
So(sigs, ShouldNotBeNil)
|
||||
})
|
||||
Convey("GetImageStatistics", func() {
|
||||
sigs := convert.GetImageStatistics(nil)
|
||||
So(sigs, ShouldNotBeNil)
|
||||
})
|
||||
Convey("GetFullImageMetaFromProto", func() {
|
||||
imageMeta := convert.GetFullImageMetaFromProto("tag", nil, nil)
|
||||
So(imageMeta.Digest.String(), ShouldResemble, "")
|
||||
})
|
||||
Convey("GetFullManifestData", func() {
|
||||
imageMeta := convert.GetFullManifestData(nil, nil)
|
||||
So(len(imageMeta), ShouldEqual, 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user