forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotocol_test.go
More file actions
51 lines (48 loc) · 1.35 KB
/
protocol_test.go
File metadata and controls
51 lines (48 loc) · 1.35 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
package opencodegraph
import (
"encoding/json"
"reflect"
"strconv"
"strings"
"testing"
"github.com/sourcegraph/sourcegraph/schema"
)
func TestDecodeRequestMessage(t *testing.T) {
tests := []struct {
input string
wantMethod string
wantCapabilities *schema.CapabilitiesParams
wantAnnotations *schema.AnnotationsParams
}{
{
input: `{"method":"capabilities","params":{}}`,
wantMethod: "capabilities",
wantCapabilities: &schema.CapabilitiesParams{},
},
{
input: `{"method":"annotations","params":{"file":"file:///a","content":"c"}}`,
wantMethod: "annotations",
wantAnnotations: &schema.AnnotationsParams{
File: "file:///a",
Content: "c",
},
},
}
for i, test := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {
method, capabilities, annotations, err := DecodeRequestMessage(json.NewDecoder(strings.NewReader(test.input)))
if err != nil {
t.Fatal(err)
}
if method != test.wantMethod {
t.Errorf("got method %q, want %q", method, test.wantMethod)
}
if !reflect.DeepEqual(capabilities, test.wantCapabilities) {
t.Errorf("got capabilities %+v, want %+v", capabilities, test.wantCapabilities)
}
if !reflect.DeepEqual(annotations, test.wantAnnotations) {
t.Errorf("got annotations %+v, want %+v", annotations, test.wantAnnotations)
}
})
}
}