forked from gocassa/gocassa
-
Notifications
You must be signed in to change notification settings - Fork 5
/
op_test.go
97 lines (82 loc) · 1.57 KB
/
op_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
package gocassa
import (
"reflect"
"testing"
)
type OpTestStruct struct {
A string `cql:"id,omitempty"`
B int
C int `cql:"-"`
D map[string]interface{}
E []interface{}
F []string
G []OpTestStructAlias
OpTestStructEmbed `cql:",squash"`
}
type OpTestStructEmbed struct {
XA int
XB OpTestStructAlias
XC []string
}
type OpTestStructAlias string
var opTestRow = map[string]interface{}{
"id": "A",
"B": 1,
"C": 1,
"D": map[string]interface{}{
"D1": 1,
"D2": "2",
},
"E": []interface{}{
"E1",
"E2", "E3", 4,
},
"F": []string{
"F1", "F2", "F3",
},
"G": []string{
"F1", "F2", "F3",
},
"XA": 1,
"XB": "XB",
"XC": []string{
"XC1", "XC2",
},
}
var opTestRowExpected = OpTestStruct{
A: "A",
B: 1,
C: 0,
D: map[string]interface{}{"D1": 1, "D2": "2"},
E: []interface{}{"E1", "E2", "E3", 4},
F: []string{"F1", "F2", "F3"},
G: []OpTestStructAlias{"F1", "F2", "F3"},
OpTestStructEmbed: OpTestStructEmbed{
XA: 1,
XB: "XB",
XC: []string{"XC1", "XC2"},
},
}
func TestDecodeRow(t *testing.T) {
var result []OpTestStruct
err := decodeResult([]map[string]interface{}{opTestRow}, &result)
if err != nil {
t.Fatal(err)
}
if len(result) != 1 {
t.Fatalf("Expected 1 results, got %d", len(result))
}
if !reflect.DeepEqual(result, []OpTestStruct{opTestRowExpected}) {
t.Fatalf("Did not get expected result")
}
}
func TestDecodeSingleRow(t *testing.T) {
var result OpTestStruct
err := decodeResult(opTestRow, &result)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(result, opTestRowExpected) {
t.Fatalf("Did not get expected result")
}
}