-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello_test.go
38 lines (32 loc) · 887 Bytes
/
hello_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
package nu
import (
"bytes"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/vmihailenco/msgpack/v5"
)
func Test_Hello_DeEncode_happy(t *testing.T) {
// encode Hello as message pack, then decode the binary
// and see did we get back (the same) struct
testCases := []hello{
{Protocol: "nu-plugin", Version: "0.90.2"},
{Protocol: "nu-plugin", Version: "0.93.0", Features: features{LocalSocket: true}},
}
for x, tc := range testCases {
bin, err := msgpack.Marshal(&tc)
if err != nil {
t.Errorf("[%d] encoding %#v: %v", x, tc, err)
continue
}
dec := msgpack.NewDecoder(bytes.NewBuffer(bin))
dec.SetMapDecoder(decodeInputMsg)
dv, err := dec.DecodeInterface()
if err != nil {
t.Errorf("[%d] decoding %#v: %v", x, tc, err)
continue
}
if diff := cmp.Diff(tc, dv); diff != "" {
t.Errorf("[%d] mismatch (-want +got):\n%s", x, diff)
}
}
}