Skip to content

Commit

Permalink
test: add common test helper (#238)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gillson <[email protected]>
  • Loading branch information
TylerGillson authored Mar 12, 2024
1 parent ca18e2b commit 85e012c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/util/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package util

import (
"errors"
"reflect"
"testing"

"github.com/spectrocloud-labs/validator/pkg/types"
)

func CheckTestCase(t *testing.T, res *types.ValidationRuleResult, expectedResult types.ValidationRuleResult, err, expectedError error) {
if !reflect.DeepEqual(res.State, expectedResult.State) {
t.Errorf("expected state (%+v), got (%+v)", expectedResult.State, res.State)
}
if !reflect.DeepEqual(res.Condition.ValidationType, expectedResult.Condition.ValidationType) {
t.Errorf("expected validation type (%s), got (%s)", expectedResult.Condition.ValidationType, res.Condition.ValidationType)
}
if !reflect.DeepEqual(res.Condition.ValidationRule, expectedResult.Condition.ValidationRule) {
t.Errorf("expected validation rule (%s), got (%s)", expectedResult.Condition.ValidationRule, res.Condition.ValidationRule)
}
if !reflect.DeepEqual(res.Condition.Message, expectedResult.Condition.Message) {
t.Errorf("expected message (%s), got (%s)", expectedResult.Condition.Message, res.Condition.Message)
}
if !reflect.DeepEqual(res.Condition.Details, expectedResult.Condition.Details) {
t.Errorf("expected details (%s), got (%s)", expectedResult.Condition.Details, res.Condition.Details)
}
if !reflect.DeepEqual(res.Condition.Failures, expectedResult.Condition.Failures) {
t.Errorf("expected failures (%s), got (%s)", expectedResult.Condition.Failures, res.Condition.Failures)
}
if !reflect.DeepEqual(res.Condition.Status, expectedResult.Condition.Status) {
t.Errorf("expected status (%s), got (%s)", expectedResult.Condition.Status, res.Condition.Status)
}
if !errors.Is(err, expectedError) {
t.Errorf("expected error (%v), got (%v)", expectedError, err)
}
}

0 comments on commit 85e012c

Please sign in to comment.