This repository has been archived by the owner on Mar 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
client_test.go
104 lines (85 loc) · 2.84 KB
/
client_test.go
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package bblfsh
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func newClient(t testing.TB, endpoint string) *Client {
if testing.Short() {
t.Skip("skipping integration test")
}
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
cli, err := NewClientContext(ctx, endpoint)
if err == context.DeadlineExceeded {
t.Skip("bblfshd is not running")
}
require.Nil(t, err)
return cli
}
var clientTests = []struct {
name string
test func(t *testing.T, cli *Client)
}{
{name: "ParseRequest", test: testParseRequest},
{name: "ParseRequestMode", test: testParseRequestMode},
{name: "NativeParseRequest", test: testNativeParseRequest},
{name: "VersionRequest", test: testVersionRequest},
{name: "SupportedLanguagesRequest", test: testSupportedLanguagesRequest},
}
func TestClient(t *testing.T) {
cli := newClient(t, "localhost:9432")
for _, c := range clientTests {
c := c
t.Run(c.name, func(t *testing.T) {
c.test(t, cli)
})
}
}
func TestMultiConnections(t *testing.T) {
cli := newClient(t, "python=localhost:9432,go=localhost:9432")
// it's not a mistake that we run 2 same requests, it checks the actual map of already initialized connections
testNativeParseRequestCustom(t, cli, "python", "import foo")
testNativeParseRequestCustom(t, cli, "python", "import foo")
testNativeParseRequestCustom(t, cli, "go", "package main")
}
func testParseRequest(t *testing.T, cli *Client) {
res, err := cli.NewParseRequest().Language("python").Content("import foo").Do()
require.NoError(t, err)
require.Equal(t, 0, len(res.Errors))
require.NotNil(t, res)
}
func testParseRequestMode(t *testing.T, cli *Client) {
res, err := cli.NewParseRequest().Language("python").Content("import foo").Mode(Semantic).Do()
require.NoError(t, err)
require.Equal(t, 0, len(res.Errors))
require.NotNil(t, res)
res, err = cli.NewParseRequest().Language("python").Content("import foo").Mode(Annotated).Do()
require.NoError(t, err)
require.Equal(t, 0, len(res.Errors))
require.NotNil(t, res)
t.Log(res)
}
func testNativeParseRequest(t *testing.T, cli *Client) {
testNativeParseRequestCustom(t, cli, "python", "import foo")
}
func testNativeParseRequestCustom(t *testing.T, cli *Client, lang, content string) {
res, err := cli.NewParseRequest().Mode(Native).Language(lang).Content(content).Do()
require.NoError(t, err)
require.Equal(t, 0, len(res.Errors))
require.NotNil(t, res)
}
func testVersionRequest(t *testing.T, cli *Client) {
res, err := cli.NewVersionRequest().Do()
require.NoError(t, err)
require.NotNil(t, res.Version)
}
func testSupportedLanguagesRequest(t *testing.T, cli *Client) {
res, err := cli.NewSupportedLanguagesRequest().Do()
require.NoError(t, err)
require.NotEmpty(t, res)
res2, err := cli.NewSupportedLanguagesRequest().DoV2()
require.NoError(t, err)
require.NotEmpty(t, res2)
}