-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalls_integration_test.go
More file actions
81 lines (69 loc) · 2.22 KB
/
Copy pathcalls_integration_test.go
File metadata and controls
81 lines (69 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package repomap
import (
"context"
"encoding/json"
"os/exec"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestExpandCallers_RealLspq runs an actual lspq invocation against a known
// symbol in this repository. Gated by testing.Short() — skipped in CI / -short mode.
func TestExpandCallers_RealLspq(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("integration test: requires lspq on PATH and a live gopls server")
}
// Verify lspq is available.
if _, err := exec.LookPath("lspq"); err != nil {
t.Skip("lspq not found on PATH; skipping integration test")
}
fs, err := ParseGoFile(filepath.Join(".", "ranker.go"), ".")
require.NoError(t, err)
line := 0
for _, sym := range fs.Symbols {
if sym.Name == "RankFiles" {
line = sym.Line
break
}
}
require.NotZero(t, line, "RankFiles line should be discovered from ranker.go")
// We query lspq directly and verify the JSON shape.
q := lspqQuerier{}
locs, err := q.Refs(context.Background(), "ranker.go", line, "RankFiles")
if err != nil {
t.Skipf("lspq refs unavailable: %v", err)
}
assert.NotEmpty(t, locs, "RankFiles should have at least one reference")
// Verify each location has the expected fields.
for _, loc := range locs {
assert.NotEmpty(t, loc.File, "location file should be non-empty")
assert.Greater(t, loc.Line, 0, "location line should be positive")
}
}
// TestLspqOutputShape verifies that the JSON output of lspq --json refs
// matches the shape we parse in lspqRefsOutput.
func TestLspqOutputShape(t *testing.T) {
t.Parallel()
if testing.Short() {
t.Skip("integration test: requires lspq")
}
if _, err := exec.LookPath("lspq"); err != nil {
t.Skip("lspq not found on PATH")
}
// Build the fixture programmatically to avoid raw JSON string literals.
fixture := lspqRefsOutput{
References: []Location{
{File: "ranker.go", Line: 23, Column: 6},
},
}
data, err := json.Marshal(fixture)
require.NoError(t, err)
var out lspqRefsOutput
require.NoError(t, json.Unmarshal(data, &out))
require.Len(t, out.References, 1)
assert.Equal(t, "ranker.go", out.References[0].File)
assert.Equal(t, 23, out.References[0].Line)
assert.Equal(t, 6, out.References[0].Column)
}