This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
forked from gocassa/gocassa
-
Notifications
You must be signed in to change notification settings - Fork 13
/
op_test.go
103 lines (89 loc) · 1.65 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
98
99
100
101
102
103
package gocassa
import (
"strconv"
"strings"
"github.com/gocql/gocql"
)
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"},
},
}
type OpTestCompositeType struct {
Num int
Str string
}
func (t *OpTestCompositeType) UnmarshalCQL(_ gocql.TypeInfo, data []byte) error {
parts := strings.Split(string(data), " ")
num, err := strconv.Atoi(parts[0])
if err != nil {
return err
}
t.Num = num
t.Str = parts[1]
return nil
}
type OpTestEnumType int32
const (
OpTestEnumOne OpTestEnumType = 1
OpTestEnumTwo OpTestEnumType = 2
OpTestEnumThree OpTestEnumType = 3
)
func (t *OpTestEnumType) UnmarshalCQL(_ gocql.TypeInfo, data []byte) error {
values := map[string]OpTestEnumType{
"EnumOne": 1,
"EnumTwo": 2,
"EnumThree": 3,
}
*t = values[string(data)]
return nil
}