Skip to content

Commit 77933e4

Browse files
committed
Changed table test
1 parent 0ec866f commit 77933e4

File tree

1 file changed

+45
-31
lines changed

1 file changed

+45
-31
lines changed

handler_test.go

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,56 @@ func TestLangHandler_lint_Integration(t *testing.T) {
1818
t.Fatal("golangci-lint is not installed in this environment")
1919
}
2020

21-
testFilePath, _ := filepath.Abs("./testdata/simple/main.go")
22-
23-
h := &langHandler{
24-
logger: newStdLogger(false),
25-
command: []string{"golangci-lint", "run", "--out-format", "json", "--issues-exit-code=1"},
26-
rootDir: filepath.Dir(testFilePath),
27-
}
28-
29-
testURI := DocumentURI("file://" + testFilePath)
30-
31-
diagnostics, err := h.lint(testURI)
32-
if err != nil {
33-
t.Fatalf("lint() returned unexpected error: %v", err)
34-
}
35-
36-
want := []Diagnostic{
21+
tests := []struct {
22+
name string
23+
h *langHandler
24+
filePath string
25+
want []Diagnostic
26+
}{
3727
{
38-
Range: Range{
39-
Start: Position{
40-
Line: 2,
41-
Character: 4,
42-
},
43-
End: Position{
44-
Line: 2,
45-
Character: 4,
28+
name: "simple",
29+
h: &langHandler{
30+
logger: newStdLogger(false),
31+
command: []string{"golangci-lint", "run", "--out-format", "json", "--issues-exit-code=1"},
32+
rootDir: filepath.Dir("./testdata/simple"),
33+
},
34+
filePath: "./testdata/simple/main.go",
35+
want: []Diagnostic{
36+
{
37+
Range: Range{
38+
Start: Position{
39+
Line: 2,
40+
Character: 4,
41+
},
42+
End: Position{
43+
Line: 2,
44+
Character: 4,
45+
},
46+
},
47+
Severity: DSWarning,
48+
Code: nil,
49+
Source: pt("unused"),
50+
Message: "unused: var `foo` is unused",
51+
RelatedInformation: nil,
4652
},
4753
},
48-
Severity: DSWarning,
49-
Code: nil,
50-
Source: pt("unused"),
51-
Message: "unused: var `foo` is unused",
52-
RelatedInformation: nil,
5354
},
5455
}
5556

56-
if diff := cmp.Diff(want, diagnostics); diff != "" {
57-
t.Errorf("lint() mismatch (-want +got):\n%s", diff)
57+
for _, tt := range tests {
58+
t.Run(tt.name, func(t *testing.T) {
59+
testFilePath, err := filepath.Abs(tt.filePath)
60+
if err != nil {
61+
t.Fatalf("filepath.Abs() returned unexpected error: %v", err)
62+
}
63+
testURI := DocumentURI("file://" + testFilePath)
64+
diagnostics, err := tt.h.lint(testURI)
65+
if err != nil {
66+
t.Fatalf("lint() returned unexpected error: %v", err)
67+
}
68+
if diff := cmp.Diff(tt.want, diagnostics); diff != "" {
69+
t.Errorf("lint() mismatch (-want +got):\n%s", diff)
70+
}
71+
})
5872
}
5973
}

0 commit comments

Comments
 (0)