forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
74 lines (65 loc) · 1.54 KB
/
helpers_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
package gocql
import (
"reflect"
"testing"
)
func TestGetCassandraType_Set(t *testing.T) {
typ := getCassandraType("set<text>")
set, ok := typ.(CollectionType)
if !ok {
t.Fatalf("expected CollectionType got %T", typ)
} else if set.typ != TypeSet {
t.Fatalf("expected type %v got %v", TypeSet, set.typ)
}
inner, ok := set.Elem.(NativeType)
if !ok {
t.Fatalf("expected to get NativeType got %T", set.Elem)
} else if inner.typ != TypeText {
t.Fatalf("expected to get %v got %v for set value", TypeText, set.typ)
}
}
func TestGetCassandraType(t *testing.T) {
tests := []struct {
input string
exp TypeInfo
}{
{
"set<text>", CollectionType{
NativeType: NativeType{typ: TypeSet},
Elem: NativeType{typ: TypeText},
},
},
{
"map<text, varchar>", CollectionType{
NativeType: NativeType{typ: TypeMap},
Key: NativeType{typ: TypeText},
Elem: NativeType{typ: TypeVarchar},
},
},
{
"list<int>", CollectionType{
NativeType: NativeType{typ: TypeList},
Elem: NativeType{typ: TypeInt},
},
},
{
"tuple<int, int, text>", TupleTypeInfo{
NativeType: NativeType{typ: TypeTuple},
Elems: []TypeInfo{
NativeType{typ: TypeInt},
NativeType{typ: TypeInt},
NativeType{typ: TypeText},
},
},
},
}
for _, test := range tests {
t.Run(test.input, func(t *testing.T) {
got := getCassandraType(test.input)
// TODO(zariel): define an equal method on the types?
if !reflect.DeepEqual(got, test.exp) {
t.Fatalf("expected %v got %v", test.exp, got)
}
})
}
}