1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 15:37:19 +00:00
kyverno/pkg/engine/api/ruleresponse_test.go
Vishal Choudhary 95f54a1cb6
feat: enable custom data in policy reports using properties (#10933)
* feat: enable custom data in policy reports using properties

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>

* fix: dont throw error in variable substitution for properties

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>

---------

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
2024-09-03 17:36:07 +00:00

130 lines
2.4 KiB
Go

package api
import (
"testing"
)
func TestRuleResponse_String(t *testing.T) {
type fields struct {
Name string
Type RuleType
Message string
Status RuleStatus
}
tests := []struct {
name string
fields fields
want string
}{{
fields: fields{
Name: "test-mutation",
Type: Mutation,
Message: "message",
},
want: "rule test-mutation (Mutation): message",
}, {
fields: fields{
Name: "test-validation",
Type: Validation,
Message: "message",
},
want: "rule test-validation (Validation): message",
}, {
fields: fields{
Name: "test-generation",
Type: Generation,
Message: "message",
},
want: "rule test-generation (Generation): message",
}, {
fields: fields{
Name: "test-image-verify",
Type: ImageVerify,
Message: "message",
},
want: "rule test-image-verify (ImageVerify): message",
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rr := NewRuleResponse(
tt.fields.Name,
tt.fields.Type,
tt.fields.Message,
tt.fields.Status,
nil,
)
if got := rr.String(); got != tt.want {
t.Errorf("RuleResponse.ToString() = %v, want %v", got, tt.want)
}
})
}
}
func TestRuleResponse_HasStatus(t *testing.T) {
type fields struct {
Name string
Type RuleType
Message string
Status RuleStatus
}
type args struct {
status []RuleStatus
}
tests := []struct {
name string
fields fields
args args
want bool
}{{
fields: fields{
Status: RuleStatusFail,
},
args: args{
status: []RuleStatus{RuleStatusFail},
},
want: true,
}, {
fields: fields{
Status: RuleStatusFail,
},
args: args{
status: []RuleStatus{RuleStatusError},
},
want: false,
}, {
fields: fields{
Status: RuleStatusFail,
},
args: args{
status: []RuleStatus{RuleStatusError, RuleStatusPass, RuleStatusFail},
},
want: true,
}, {
fields: fields{
Status: RuleStatusFail,
},
args: args{
status: []RuleStatus{},
},
want: false,
}, {
fields: fields{
Status: RuleStatusFail,
},
want: false,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := NewRuleResponse(
tt.fields.Name,
tt.fields.Type,
tt.fields.Message,
tt.fields.Status,
nil,
)
if got := r.HasStatus(tt.args.status...); got != tt.want {
t.Errorf("RuleResponse.HasStatus() = %v, want %v", got, tt.want)
}
})
}
}