0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2025-01-06 22:40:28 -05:00
zot/pkg/meta/common/common_test.go
LaurentiuNiculae 56ad9e6707
refactor(metadb): improve UX by speeding up metadb serialize/deserialize (#1842)
Use protocol buffers and update the metadb interface to better suit our search needs

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
Co-authored-by: Ramkumar Chinchani <rchincha@cisco.com>
2023-10-30 13:06:04 -07:00

111 lines
3.4 KiB
Go

package common_test
import (
"errors"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
"zotregistry.io/zot/pkg/meta/common"
mTypes "zotregistry.io/zot/pkg/meta/types"
)
var ErrTestError = errors.New("test error")
func TestUtils(t *testing.T) {
Convey("MatchesArtifactTypes", t, func() {
res := common.MatchesArtifactTypes("", nil)
So(res, ShouldBeTrue)
res = common.MatchesArtifactTypes("type", []string{"someOtherType"})
So(res, ShouldBeFalse)
})
Convey("CheckImageLastUpdated", t, func() {
Convey("No image checked, it doesn't have time", func() {
repoLastUpdated := time.Time{}
isSigned := false
noImageChecked := true
manifestFilterData := mTypes.FilterData{
DownloadCount: 10,
LastUpdated: time.Time{},
IsSigned: true,
}
repoLastUpdated, noImageChecked, isSigned = common.CheckImageLastUpdated(repoLastUpdated, isSigned, noImageChecked,
manifestFilterData)
So(repoLastUpdated, ShouldResemble, manifestFilterData.LastUpdated)
So(isSigned, ShouldEqual, manifestFilterData.IsSigned)
So(noImageChecked, ShouldEqual, false)
})
Convey("First image checked, it has time", func() {
repoLastUpdated := time.Time{}
isSigned := false
noImageChecked := true
manifestFilterData := mTypes.FilterData{
DownloadCount: 10,
LastUpdated: time.Date(2000, 1, 1, 1, 1, 1, 1, time.UTC),
IsSigned: true,
}
repoLastUpdated, noImageChecked, isSigned = common.CheckImageLastUpdated(repoLastUpdated, isSigned, noImageChecked,
manifestFilterData)
So(repoLastUpdated, ShouldResemble, manifestFilterData.LastUpdated)
So(isSigned, ShouldEqual, manifestFilterData.IsSigned)
So(noImageChecked, ShouldEqual, false)
})
Convey("Not first image checked, current image is newer", func() {
repoLastUpdated := time.Date(2000, 1, 1, 1, 1, 1, 1, time.UTC)
isSigned := true
noImageChecked := false
manifestFilterData := mTypes.FilterData{
DownloadCount: 10,
LastUpdated: time.Date(2023, 1, 1, 1, 1, 1, 1, time.UTC),
IsSigned: false,
}
repoLastUpdated, noImageChecked, isSigned = common.CheckImageLastUpdated(repoLastUpdated, isSigned,
noImageChecked, manifestFilterData)
So(repoLastUpdated, ShouldResemble, manifestFilterData.LastUpdated)
So(isSigned, ShouldEqual, manifestFilterData.IsSigned)
So(noImageChecked, ShouldEqual, false)
})
Convey("Not first image checked, current image is older", func() {
repoLastUpdated := time.Date(2024, 1, 1, 1, 1, 1, 1, time.UTC)
isSigned := false
noImageChecked := false
manifestFilterData := mTypes.FilterData{
DownloadCount: 10,
LastUpdated: time.Date(2022, 1, 1, 1, 1, 1, 1, time.UTC),
IsSigned: true,
}
updatedRepoLastUpdated, noImageChecked, isSigned := common.CheckImageLastUpdated(repoLastUpdated, isSigned,
noImageChecked,
manifestFilterData)
So(updatedRepoLastUpdated, ShouldResemble, repoLastUpdated)
So(isSigned, ShouldEqual, false)
So(noImageChecked, ShouldEqual, false)
})
})
Convey("SignatureAlreadyExists", t, func() {
res := common.SignatureAlreadyExists(
[]mTypes.SignatureInfo{{SignatureManifestDigest: "digest"}},
mTypes.SignatureMetadata{SignatureDigest: "digest"},
)
So(res, ShouldEqual, true)
res = common.SignatureAlreadyExists(
[]mTypes.SignatureInfo{{SignatureManifestDigest: "digest"}},
mTypes.SignatureMetadata{SignatureDigest: "digest2"},
)
So(res, ShouldEqual, false)
})
}