2023-01-30 14:49:44 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRuleResponse_String(t *testing.T) {
|
|
|
|
type fields struct {
|
2023-04-05 10:35:38 +00:00
|
|
|
Name string
|
|
|
|
Type RuleType
|
|
|
|
Message string
|
|
|
|
Status RuleStatus
|
2023-01-30 14:49:44 +00:00
|
|
|
}
|
|
|
|
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) {
|
2023-04-05 10:35:38 +00:00
|
|
|
rr := NewRuleResponse(
|
|
|
|
tt.fields.Name,
|
|
|
|
tt.fields.Type,
|
|
|
|
tt.fields.Message,
|
|
|
|
tt.fields.Status,
|
|
|
|
)
|
2023-01-30 14:49:44 +00:00
|
|
|
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 {
|
2023-04-05 10:35:38 +00:00
|
|
|
Name string
|
|
|
|
Type RuleType
|
|
|
|
Message string
|
|
|
|
Status RuleStatus
|
2023-01-30 14:49:44 +00:00
|
|
|
}
|
|
|
|
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) {
|
2023-04-05 10:35:38 +00:00
|
|
|
r := NewRuleResponse(
|
|
|
|
tt.fields.Name,
|
|
|
|
tt.fields.Type,
|
|
|
|
tt.fields.Message,
|
|
|
|
tt.fields.Status,
|
|
|
|
)
|
2023-01-30 14:49:44 +00:00
|
|
|
if got := r.HasStatus(tt.args.status...); got != tt.want {
|
|
|
|
t.Errorf("RuleResponse.HasStatus() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|