Skip to content

Commit

Permalink
chore: Small rules test updates
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Zawada <atzawada@gmail.com>
  • Loading branch information
atzawada committed Sep 26, 2023
1 parent 4a9c7e7 commit c954f76
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions pkg/rules/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func TestFetchRules(t *testing.T) {
}
return nil
})
if err != nil {
t.Errorf("Failed to filenames with: %s", err)
}

rules, err := FetchRegoRules([]schema.GroupVersionKind{})
if err != nil {
Expand All @@ -39,14 +42,8 @@ func TestFetchRulesWithAdditionalResources(t *testing.T) {
}
return nil
})

additionalKindsStr := []string{
"ManagedCertificate.v1.networking.gke.io",
"Fake.v1beta.example.com"}
var additionalKinds []schema.GroupVersionKind
for _, ar := range additionalKindsStr {
gvr, _ := schema.ParseKindArg(ar)
additionalKinds = append(additionalKinds, *gvr)
if err != nil {
t.Errorf("Failed to filenames with: %s", err)
}

rules, err := FetchRegoRules([]schema.GroupVersionKind{})
Expand All @@ -69,14 +66,14 @@ func TestRenderRuleRego(t *testing.T) {
t.Errorf("Failed to render rule %s: %s", fileName, err)
}

if bytes.Compare(inputData, outputData) != 0 {
if !bytes.Equal(inputData, outputData) {
t.Errorf("expected the input to be same as output")
}
}

func TestRenderRuleTmpl(t *testing.T) {
additionalResources := []schema.GroupVersionKind{
schema.GroupVersionKind{
{
Group: "example.com",
Version: "v2",
Kind: "Test",
Expand All @@ -93,7 +90,7 @@ func TestRenderRuleTmpl(t *testing.T) {
t.Errorf("failed to render rule %s: %s", fileName, err)
}

if bytes.Compare(expectedData, outputData) != 0 {
if !bytes.Equal(expectedData, outputData) {
t.Errorf("result does not match expected output, expected: %s, got: %s", expectedData, outputData)
}
}
Expand All @@ -112,17 +109,17 @@ func TestRenderRuleTmplFail(t *testing.T) {

func TestRenderMultipleResources(t *testing.T) {
additionalResources := []schema.GroupVersionKind{
schema.GroupVersionKind{
{
Group: "example.com",
Version: "v2",
Kind: "Test",
},
schema.GroupVersionKind{
{
Group: "example.com",
Version: "v3",
Kind: "Test",
},
schema.GroupVersionKind{
{
Group: "example.com",
Version: "v2",
Kind: "Result",
Expand All @@ -141,7 +138,7 @@ func TestRenderMultipleResources(t *testing.T) {

outputData = []byte(strings.TrimSpace(string(outputData)))

if bytes.Compare(expectedData, outputData) != 0 {
if !bytes.Equal(expectedData, outputData) {
t.Errorf("result does not match expected output, expected: %s, got: %s", expectedData, outputData)
}
}
Expand Down

0 comments on commit c954f76

Please sign in to comment.