Skip to content

Commit 0ec866f

Browse files
committed
Added single integration test
1 parent 2e2eeac commit 0ec866f

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ module github.com/nametake/golangci-lint-langserver
33
go 1.23.4
44

55
require github.com/sourcegraph/jsonrpc2 v0.0.0-20191222043438-96c4efab7ee2
6+
7+
require github.com/google/go-cmp v0.6.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
2+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
13
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
24
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
35
github.com/sourcegraph/jsonrpc2 v0.0.0-20191222043438-96c4efab7ee2 h1:5VGNYxMxzZ8Jb2bARgVl1DNg8vpcd9S8b4MbbjWQ8/w=

handler_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package main
2+
3+
import (
4+
"os/exec"
5+
"path/filepath"
6+
"testing"
7+
8+
"github.com/google/go-cmp/cmp"
9+
)
10+
11+
func pt(s string) *string {
12+
return &s
13+
}
14+
15+
func TestLangHandler_lint_Integration(t *testing.T) {
16+
_, err := exec.LookPath("golangci-lint")
17+
if err != nil {
18+
t.Fatal("golangci-lint is not installed in this environment")
19+
}
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{
37+
{
38+
Range: Range{
39+
Start: Position{
40+
Line: 2,
41+
Character: 4,
42+
},
43+
End: Position{
44+
Line: 2,
45+
Character: 4,
46+
},
47+
},
48+
Severity: DSWarning,
49+
Code: nil,
50+
Source: pt("unused"),
51+
Message: "unused: var `foo` is unused",
52+
RelatedInformation: nil,
53+
},
54+
}
55+
56+
if diff := cmp.Diff(want, diagnostics); diff != "" {
57+
t.Errorf("lint() mismatch (-want +got):\n%s", diff)
58+
}
59+
}

0 commit comments

Comments
 (0)