diff --git a/helper/testing.go b/helper/testing.go index 7f5fd1e..9142006 100644 --- a/helper/testing.go +++ b/helper/testing.go @@ -1,6 +1,7 @@ package helper import ( + "reflect" "testing" "github.com/google/go-cmp/cmp" @@ -30,7 +31,7 @@ func AssertIssues(t *testing.T, expected Issues, actual Issues) { opts := []cmp.Option{ // Byte field will be ignored because it's not important in tests such as positions cmpopts.IgnoreFields(hcl.Pos{}, "Byte"), - cmpopts.IgnoreFields(Issue{}, "Rule"), + ruleComparer(), } if !cmp.Equal(expected, actual, opts...) { t.Fatalf("Expected issues are not matched:\n %s\n", cmp.Diff(expected, actual, opts...)) @@ -41,9 +42,17 @@ func AssertIssues(t *testing.T, expected Issues, actual Issues) { func AssertIssuesWithoutRange(t *testing.T, expected Issues, actual Issues) { opts := []cmp.Option{ cmpopts.IgnoreFields(Issue{}, "Range"), - cmpopts.IgnoreFields(Issue{}, "Rule"), + ruleComparer(), } if !cmp.Equal(expected, actual, opts...) { t.Fatalf("Expected issues are not matched:\n %s\n", cmp.Diff(expected, actual, opts...)) } } + +// ruleComparer returns a Comparer func that checks that two rule interfaces +// have the same underlying type. It does not compare struct fields. +func ruleComparer() cmp.Option { + return cmp.Comparer(func(x, y Rule) bool { + return reflect.TypeOf(x) == reflect.TypeOf(y) + }) +}