1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-04-15 16:56:56 +00:00

feat: improve assertion and error messages (#8489)

This commit is contained in:
Vishal Choudhary 2023-09-21 18:09:54 +05:30 committed by GitHub
parent 86b752e2fb
commit e6bebeae9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1118,7 +1118,7 @@ func Test_ImageVerifyCacheExpiredCosign(t *testing.T) {
opts := []imageverifycache.Option{
imageverifycache.WithCacheEnableFlag(true),
imageverifycache.WithMaxSize(1000),
imageverifycache.WithTTLDuration(5 * time.Second),
imageverifycache.WithTTLDuration(2 * time.Second),
}
imageVerifyCache, err := imageverifycache.New(opts...)
assert.NilError(t, err)
@ -1137,7 +1137,7 @@ func Test_ImageVerifyCacheExpiredCosign(t *testing.T) {
er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg)
secondOperationTime := time.Since(start)
errorAssertionUtil(t, image, ivm, er)
assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry is expired, so image verification should not be from cache.")
assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry is expired, so image verification should not be from cache.", firstOperationTime, secondOperationTime)
}
func Test_changePolicyCacheVerificationCosign(t *testing.T) {
@ -1162,7 +1162,7 @@ func Test_changePolicyCacheVerificationCosign(t *testing.T) {
er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg)
secondOperationTime := time.Since(start)
errorAssertionUtil(t, image, ivm, er)
assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry not found, so image verification should not be from cache.")
assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry not found, so image verification should not be from cache.", firstOperationTime, secondOperationTime)
}
var verifyImageNotaryPolicy = `{
@ -1289,7 +1289,6 @@ var verifyImageNotaryResource = `{
}`
func Test_ImageVerifyCacheNotary(t *testing.T) {
opts := []imageverifycache.Option{
imageverifycache.WithCacheEnableFlag(true),
imageverifycache.WithMaxSize(1000),
@ -1313,11 +1312,10 @@ func Test_ImageVerifyCacheNotary(t *testing.T) {
}
func Test_ImageVerifyCacheExpiredNotary(t *testing.T) {
opts := []imageverifycache.Option{
imageverifycache.WithCacheEnableFlag(true),
imageverifycache.WithMaxSize(1000),
imageverifycache.WithTTLDuration(5 * time.Second),
imageverifycache.WithTTLDuration(2 * time.Second),
}
imageVerifyCache, err := imageverifycache.New(opts...)
assert.NilError(t, err)
@ -1325,19 +1323,18 @@ func Test_ImageVerifyCacheExpiredNotary(t *testing.T) {
policyContext := buildContext(t, verifyImageNotaryPolicy, verifyImageNotaryResource, "")
assert.NilError(t, err)
start := time.Now()
er, ivm := testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg)
firstOperationTime := time.Since(start)
errorAssertionUtil(t, image, ivm, er)
time.Sleep(5 * time.Second)
start = time.Now()
er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg)
secondOperationTime := time.Since(start)
errorAssertionUtil(t, image, ivm, er)
assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry is expired, so image verification should not be from cache.")
assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry is expired, so image verification should not be from cache.", firstOperationTime, secondOperationTime)
}
func Test_changePolicyCacheVerificationNotary(t *testing.T) {
@ -1361,6 +1358,5 @@ func Test_changePolicyCacheVerificationNotary(t *testing.T) {
er, ivm = testImageVerifyCache(imageVerifyCache, context.TODO(), registryclient.NewOrDie(), nil, policyContext, cfg)
secondOperationTime := time.Since(start)
errorAssertionUtil(t, image, ivm, er)
assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry not found, so image verification should not be from cache.")
assert.Check(t, secondOperationTime > firstOperationTime/10 && secondOperationTime < firstOperationTime*10, "cache entry not found, so image verification should not be from cache.", firstOperationTime, secondOperationTime)
}