Skip to content

Commit 4bf61fc

Browse files
committed
Add more test coverage
1 parent c2cb012 commit 4bf61fc

3 files changed

Lines changed: 112 additions & 4 deletions

File tree

internal/reporter/comments_test.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,41 @@ bar warning
159159
meta: nil,
160160
}
161161

162+
infoReport := Report{
163+
Path: discovery.Path{
164+
SymlinkTarget: "info.txt",
165+
Name: "info.txt",
166+
},
167+
Changes: discovery.Changes{
168+
OldPath: "",
169+
Lines: git.LineNumbers{{Before: 0, After: 1}},
170+
},
171+
Rule: mockFile.Groups[0].Rules[0],
172+
Problem: checks.Problem{
173+
Reporter: "info",
174+
Summary: "info note",
175+
Details: "",
176+
Lines: diags.LineRange{First: 1, Last: 1},
177+
Severity: checks.Information,
178+
Anchor: checks.AnchorAfter,
179+
},
180+
}
181+
infoComment := ExistingComment{
182+
path: "info.txt",
183+
line: 1,
184+
text: `:information_source: **Information** reported by [pint](https://cloudflare.github.io/pint/) **info** check.
185+
186+
------
187+
188+
info note
189+
190+
------
191+
192+
:information_source: To see documentation covering this check and instructions on how to resolve it [click here](https://cloudflare.github.io/pint/checks/info.html).
193+
`,
194+
meta: nil,
195+
}
196+
162197
type testCaseT struct {
163198
commenter Commenter
164199
checkErr func(t *testing.T, err error)
@@ -203,7 +238,7 @@ bar warning
203238
},
204239
{
205240
description: "no-op when all comments already exist",
206-
reports: []Report{fooReport, barReport},
241+
reports: []Report{fooReport, barReport, infoReport},
207242
commenter: testCommenter{
208243
destinations: func(_ context.Context) ([]any, error) {
209244
return []any{1}, nil
@@ -215,7 +250,7 @@ bar warning
215250
return nil
216251
},
217252
list: func(_ context.Context, _ any) ([]ExistingComment, error) {
218-
return []ExistingComment{fooComment, barComment}, nil
253+
return []ExistingComment{fooComment, barComment, infoComment}, nil
219254
},
220255
create: func(_ context.Context, _ any, p PendingComment) error {
221256
return fmt.Errorf("shouldn't try to create %s:%d", p.path, p.line)

internal/reporter/reporter_test.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ func TestReportIsEqual(t *testing.T) {
2828
b: Report{Path: discovery.Path{Name: "bar"}, Rule: parser.Rule{}},
2929
expected: false,
3030
},
31+
{
32+
a: Report{Path: discovery.Path{Name: "foo", SymlinkTarget: "a"}, Rule: parser.Rule{}},
33+
b: Report{Path: discovery.Path{Name: "foo", SymlinkTarget: "b"}, Rule: parser.Rule{}},
34+
expected: false,
35+
},
3136
{
3237
a: Report{Path: discovery.Path{Name: "foo"}, Rule: parser.Rule{}, Owner: "bob"},
3338
b: Report{Path: discovery.Path{Name: "foo"}, Rule: parser.Rule{}},
@@ -48,6 +53,18 @@ func TestReportIsEqual(t *testing.T) {
4853
b: Report{Path: discovery.Path{Name: "foo"}, Rule: parser.Rule{Lines: diags.LineRange{Last: 1}}, Problem: checks.Problem{Lines: diags.LineRange{Last: 1}}},
4954
expected: false,
5055
},
56+
{
57+
a: Report{Path: discovery.Path{Name: "foo"}, Rule: parser.Rule{Lines: diags.LineRange{Last: 1}}, Problem: checks.Problem{Lines: diags.LineRange{Last: 2}}},
58+
b: Report{Path: discovery.Path{Name: "foo"}, Rule: parser.Rule{Lines: diags.LineRange{Last: 1}}, Problem: checks.Problem{Lines: diags.LineRange{Last: 1}}},
59+
expected: false,
60+
},
61+
{
62+
a: Report{Path: discovery.Path{Name: "foo"}, Rule: parser.Rule{}, Problem: checks.Problem{
63+
Diagnostics: []diags.Diagnostic{{Message: "a"}},
64+
}},
65+
b: Report{Path: discovery.Path{Name: "foo"}, Rule: parser.Rule{}, Problem: checks.Problem{}},
66+
expected: false,
67+
},
5168
{
5269
a: Report{Path: discovery.Path{Name: "foo"}, Rule: parser.Rule{}, Problem: checks.Problem{Reporter: "a"}},
5370
b: Report{Path: discovery.Path{Name: "foo"}, Rule: parser.Rule{}, Problem: checks.Problem{Reporter: "b"}},
@@ -216,6 +233,62 @@ func TestReportIsSameIssue(t *testing.T) {
216233
},
217234
expected: false,
218235
},
236+
{
237+
name: "different summary",
238+
a: Report{
239+
Problem: checks.Problem{
240+
Reporter: "promql/series",
241+
Summary: "a",
242+
Severity: checks.Warning,
243+
},
244+
},
245+
b: Report{
246+
Problem: checks.Problem{
247+
Reporter: "promql/series",
248+
Summary: "b",
249+
Severity: checks.Warning,
250+
},
251+
},
252+
expected: false,
253+
},
254+
{
255+
name: "different severity",
256+
a: Report{
257+
Problem: checks.Problem{
258+
Reporter: "promql/series",
259+
Summary: "a",
260+
Severity: checks.Warning,
261+
},
262+
},
263+
b: Report{
264+
Problem: checks.Problem{
265+
Reporter: "promql/series",
266+
Summary: "a",
267+
Severity: checks.Bug,
268+
},
269+
},
270+
expected: false,
271+
},
272+
{
273+
name: "different diagnostics",
274+
a: Report{
275+
Problem: checks.Problem{
276+
Reporter: "promql/series",
277+
Summary: "a",
278+
Severity: checks.Warning,
279+
Diagnostics: []diags.Diagnostic{{Message: "x"}},
280+
},
281+
},
282+
b: Report{
283+
Problem: checks.Problem{
284+
Reporter: "promql/series",
285+
Summary: "a",
286+
Severity: checks.Warning,
287+
Diagnostics: []diags.Diagnostic{{Message: "y"}},
288+
},
289+
},
290+
expected: false,
291+
},
219292
}
220293

221294
for _, tc := range testCases {

internal/reporter/summary_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package reporter
33
import (
44
"testing"
55

6-
"github.com/cloudflare/pint/internal/checks"
7-
86
"github.com/stretchr/testify/require"
7+
8+
"github.com/cloudflare/pint/internal/checks"
99
)
1010

1111
func TestNewSummary(t *testing.T) {

0 commit comments

Comments
 (0)