@@ -24,11 +24,18 @@ func TestDiagnosticComparer(t *testing.T) {
24
24
diag2 Diagnostic
25
25
expectDiff bool
26
26
}{
27
+ // Correctly identifying things that match
27
28
"reports that identical diagnostics match" : {
28
29
diag1 : hclDiagnostic {& baseError },
29
30
diag2 : hclDiagnostic {& baseError },
30
31
expectDiff : false ,
31
32
},
33
+ // Correctly identifies when things don't match
34
+ "reports that diagnostics don't match if the concrete type differs" : {
35
+ diag1 : hclDiagnostic {& baseError },
36
+ diag2 : makeRPCFriendlyDiag (hclDiagnostic {& baseError }),
37
+ expectDiff : true ,
38
+ },
32
39
"reports that diagnostics don't match if severity differs" : {
33
40
diag1 : hclDiagnostic {& baseError },
34
41
diag2 : func () Diagnostic {
@@ -65,19 +72,55 @@ func TestDiagnosticComparer(t *testing.T) {
65
72
}(),
66
73
expectDiff : true ,
67
74
},
68
- "reports that diagnostics don't match if attribute path missing from one differs " : {
75
+ "reports that diagnostics don't match if attribute path is missing from one" : {
69
76
diag1 : func () Diagnostic {
70
77
return AttributeValue (Error , "summary here" , "detail here" , cty.Path {cty.GetAttrStep {Name : "foobar1" }})
71
78
}(),
72
79
diag2 : func () Diagnostic {
73
- d := hcl.Diagnostic {
74
- Severity : hcl .DiagError ,
75
- Summary : "summary here" ,
76
- Detail : "detail here" ,
80
+ return AttributeValue (Error , "summary here" , "detail here" , cty.Path {})
81
+ }(),
82
+ expectDiff : true ,
83
+ },
84
+ // Scenarios where diagnostics will be considered equavalent, even if they aren't fully the same
85
+ "reports that diagnostics match even if sources (Subject) are different; ignored in simple comparison" : {
86
+ diag1 : hclDiagnostic {& baseError },
87
+ diag2 : func () Diagnostic {
88
+ d := baseError
89
+ d .Subject = & hcl.Range {
90
+ Filename : "foobar.tf" ,
91
+ Start : hcl.Pos {
92
+ Line : 0 ,
93
+ Column : 0 ,
94
+ Byte : 0 ,
95
+ },
96
+ End : hcl.Pos {
97
+ Line : 1 ,
98
+ Column : 1 ,
99
+ Byte : 1 ,
100
+ },
101
+ }
102
+ return hclDiagnostic {& d }
103
+ }(),
104
+ },
105
+ "reports that diagnostics match even if sources (Context) are different; ignored in simple comparison" : {
106
+ diag1 : hclDiagnostic {& baseError },
107
+ diag2 : func () Diagnostic {
108
+ d := baseError
109
+ d .Context = & hcl.Range {
110
+ Filename : "foobar.tf" ,
111
+ Start : hcl.Pos {
112
+ Line : 0 ,
113
+ Column : 0 ,
114
+ Byte : 0 ,
115
+ },
116
+ End : hcl.Pos {
117
+ Line : 1 ,
118
+ Column : 1 ,
119
+ Byte : 1 ,
120
+ },
77
121
}
78
122
return hclDiagnostic {& d }
79
123
}(),
80
- expectDiff : true ,
81
124
},
82
125
}
83
126
@@ -94,5 +137,4 @@ func TestDiagnosticComparer(t *testing.T) {
94
137
}
95
138
})
96
139
}
97
-
98
140
}
0 commit comments