1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-10 01:46:55 +00:00
kyverno/cmd/cleanup-controller/handlers/cleanup/condition_test.go
Charles-Edouard Brétéché 9dc001e758
feat: add conditions matching to cleanup controller (#5626)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: shuting <shuting@nirmata.com>
2022-12-09 10:24:04 +00:00

57 lines
1.3 KiB
Go

package cleanup
import (
"testing"
"github.com/go-logr/logr"
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1"
enginecontext "github.com/kyverno/kyverno/pkg/engine/context"
"github.com/kyverno/kyverno/pkg/logging"
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
)
func Test_checkCondition(t *testing.T) {
ctx := enginecontext.NewContext()
ctx.AddResource(map[string]interface{}{
"name": "dummy",
})
type args struct {
logger logr.Logger
ctx enginecontext.Interface
condition kyvernov2beta1.Condition
}
tests := []struct {
name string
args args
want bool
wantErr bool
}{{
name: "basic",
args: args{
logger: logging.GlobalLogger(),
ctx: ctx,
condition: kyvernov2beta1.Condition{
RawKey: &v1.JSON{
Raw: []byte(`"{{ request.object.name }}"`),
},
Operator: kyvernov2beta1.ConditionOperators["Equals"],
RawValue: &v1.JSON{
Raw: []byte(`"dummy"`),
},
},
},
want: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := checkCondition(tt.args.logger, tt.args.ctx, tt.args.condition)
if (err != nil) != tt.wantErr {
t.Errorf("checkCondition() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("checkCondition() = %v, want %v", got, tt.want)
}
})
}
}