Skip to content

Commit 50a005c

Browse files
committed
Added load config test case
1 parent 9ce1bf4 commit 50a005c

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

handler_test.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ func pt(s string) *string {
1313
}
1414

1515
func TestLangHandler_lint_Integration(t *testing.T) {
16-
_, err := exec.LookPath("golangci-lint")
17-
if err != nil {
16+
if _, err := exec.LookPath("golangci-lint"); err != nil {
1817
t.Fatal("golangci-lint is not installed in this environment")
1918
}
2019

@@ -25,13 +24,13 @@ func TestLangHandler_lint_Integration(t *testing.T) {
2524
want []Diagnostic
2625
}{
2726
{
28-
name: "simple",
27+
name: "no config file",
2928
h: &langHandler{
3029
logger: newStdLogger(false),
3130
command: []string{"golangci-lint", "run", "--out-format", "json", "--issues-exit-code=1"},
32-
rootDir: filepath.Dir("./testdata/simple"),
31+
rootDir: filepath.Dir("./testdata/noconfig"),
3332
},
34-
filePath: "./testdata/simple/main.go",
33+
filePath: "./testdata/noconfig/main.go",
3534
want: []Diagnostic{
3635
{
3736
Range: Range{
@@ -53,7 +52,7 @@ func TestLangHandler_lint_Integration(t *testing.T) {
5352
},
5453
},
5554
{
56-
name: "nolintername",
55+
name: "nolintername option works as expected",
5756
h: &langHandler{
5857
logger: newStdLogger(false),
5958
command: []string{"golangci-lint", "run", "--out-format", "json", "--issues-exit-code=1"},
@@ -81,6 +80,34 @@ func TestLangHandler_lint_Integration(t *testing.T) {
8180
},
8281
},
8382
},
83+
{
84+
name: "config file is loaded successfully",
85+
h: &langHandler{
86+
logger: newStdLogger(false),
87+
command: []string{"golangci-lint", "run", "--out-format", "json", "--issues-exit-code=1"},
88+
rootDir: filepath.Dir("./testdata/nolintername"),
89+
},
90+
filePath: "./testdata/loadconfig/main.go",
91+
want: []Diagnostic{
92+
{
93+
Range: Range{
94+
Start: Position{
95+
Line: 8,
96+
Character: 0,
97+
},
98+
End: Position{
99+
Line: 8,
100+
Character: 0,
101+
},
102+
},
103+
Severity: DSWarning,
104+
Code: nil,
105+
Source: pt("wsl"),
106+
Message: "wsl: block should not end with a whitespace (or comment)",
107+
RelatedInformation: nil,
108+
},
109+
},
110+
},
84111
}
85112

86113
for _, tt := range tests {

testdata/loadconfig/.golangci.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
linters:
2+
enable:
3+
- wsl
4+
disable:
5+
- unused

testdata/loadconfig/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
// unused: var `foo` is unused
4+
var foo = "foo"
5+
6+
func Bar() {
7+
_ = foo
8+
9+
}
File renamed without changes.

0 commit comments

Comments
 (0)