-
Notifications
You must be signed in to change notification settings - Fork 7
/
gotsrpc_test.go
51 lines (48 loc) · 1019 Bytes
/
gotsrpc_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
package gotsrpc
import (
"testing"
)
func TestLoadArgs(t *testing.T) {
jsonBytes := []byte(`["a", ["a", "b", "c"]]`)
foo := ""
bar := []string{}
args := []interface{}{&foo, &bar}
errLoad := loadArgs(&args, jsonBytes)
if errLoad != nil {
t.Fatal(errLoad)
}
if foo != "a" {
t.Fatal("foo should have been a")
}
if len(bar) != 3 {
t.Fatal("bar len wrong", len(bar), "!=", len(bar))
}
if bar[1] != "b" {
t.Fatal("bar[1] (", bar[1], ") != b")
}
}
func TestLoadInterfaceArgs(t *testing.T) {
jsonBytes := []byte(`["a", ["a", "b", "c"], 1.3]`)
var (
foo interface{}
bar []interface{}
floaty interface{}
)
args := []interface{}{&foo, &bar, &floaty}
errLoad := loadArgs(&args, jsonBytes)
if errLoad != nil {
t.Fatal(errLoad)
}
if foo != "a" {
t.Fatal("foo should have been a")
}
if len(bar) != 3 {
t.Fatal("bar len wrong", len(bar), "!=", len(bar))
}
if bar[1] != "b" {
t.Fatal("bar[1] (", bar[1], ") != b")
}
if floaty != 1.3 {
t.Fatal("floaty mismatch", floaty)
}
}