@@ -18,42 +18,56 @@ func TestLangHandler_lint_Integration(t *testing.T) {
18
18
t .Fatal ("golangci-lint is not installed in this environment" )
19
19
}
20
20
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
+ }{
37
27
{
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 ,
46
52
},
47
53
},
48
- Severity : DSWarning ,
49
- Code : nil ,
50
- Source : pt ("unused" ),
51
- Message : "unused: var `foo` is unused" ,
52
- RelatedInformation : nil ,
53
54
},
54
55
}
55
56
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
+ })
58
72
}
59
73
}
0 commit comments