1
1
package helper
2
2
3
3
import (
4
+ "reflect"
4
5
"testing"
5
6
6
7
"github.com/google/go-cmp/cmp"
7
8
"github.com/google/go-cmp/cmp/cmpopts"
8
9
"github.com/hashicorp/hcl/v2"
9
10
"github.com/hashicorp/hcl/v2/hclparse"
11
+ "github.com/terraform-linters/tflint-plugin-sdk/tflint"
10
12
)
11
13
12
14
// TestRunner returns a pseudo Runner for testing
@@ -30,7 +32,7 @@ func AssertIssues(t *testing.T, expected Issues, actual Issues) {
30
32
opts := []cmp.Option {
31
33
// Byte field will be ignored because it's not important in tests such as positions
32
34
cmpopts .IgnoreFields (hcl.Pos {}, "Byte" ),
33
- cmpopts . IgnoreFields ( Issue {}, "Rule" ),
35
+ ruleComparer ( ),
34
36
}
35
37
if ! cmp .Equal (expected , actual , opts ... ) {
36
38
t .Fatalf ("Expected issues are not matched:\n %s\n " , cmp .Diff (expected , actual , opts ... ))
@@ -41,9 +43,17 @@ func AssertIssues(t *testing.T, expected Issues, actual Issues) {
41
43
func AssertIssuesWithoutRange (t * testing.T , expected Issues , actual Issues ) {
42
44
opts := []cmp.Option {
43
45
cmpopts .IgnoreFields (Issue {}, "Range" ),
44
- cmpopts . IgnoreFields ( Issue {}, "Rule" ),
46
+ ruleComparer ( ),
45
47
}
46
48
if ! cmp .Equal (expected , actual , opts ... ) {
47
49
t .Fatalf ("Expected issues are not matched:\n %s\n " , cmp .Diff (expected , actual , opts ... ))
48
50
}
49
51
}
52
+
53
+ // ruleComparer returns a Comparer func that checks that two rule interfaces
54
+ // have the same underlying type. It does not compare struct fields.
55
+ func ruleComparer () cmp.Option {
56
+ return cmp .Comparer (func (x , y tflint.Rule ) bool {
57
+ return reflect .TypeOf (x ) == reflect .TypeOf (y )
58
+ })
59
+ }
0 commit comments