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
/
multimap_table_test.go
132 lines (126 loc) · 2.44 KB
/
multimap_table_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package gocassa
import (
"reflect"
"testing"
)
type Customer2 struct {
Id string
Name string
Tag string
}
func TestMultimapTableInsertRead(t *testing.T) {
tbl := ns.MultimapTable("customer91", "Tag", "Id", Customer2{})
createIf(tbl.(TableChanger), t)
joe := Customer2{
Id: "33",
Name: "Joe",
Tag: "A",
}
err := tbl.Set(joe).Run()
if err != nil {
t.Fatal(err)
}
res := &Customer2{}
err = tbl.Read("A", "33", res).Run()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(*res, joe) {
t.Fatal(*res, joe)
}
err = tbl.Read("B", "33", res).Run()
if err == nil {
t.Fatal(*res)
}
err = tbl.Update("A", "33", map[string]interface{}{
"Name": "John",
}).Run()
if err != nil {
t.Fatal(err)
}
err = tbl.Read("A", "33", res).Run()
if err != nil {
t.Fatal(err)
}
if res.Name != "John" {
t.Fatal(*res)
}
list := &[]Customer{}
err = tbl.List("A", nil, 20, list).Run()
if err != nil {
t.Fatal(err)
}
if len(*list) != 1 {
t.Fatal(*list)
}
}
func TestMultimapTableDelete(t *testing.T) {
tbl := ns.MultimapTable("customer92", "Tag", "Id", Customer2{})
createIf(tbl.(TableChanger), t)
joe := Customer2{
Id: "33",
Name: "Joe",
Tag: "A",
}
err := tbl.Set(joe).Run()
if err != nil {
t.Fatal(err)
}
res := &Customer2{}
err = tbl.Read("A", "33", res).Run()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(*res, joe) {
t.Fatal(*res, joe)
}
err = tbl.Delete("A", "33").Run()
if err != nil {
t.Fatal(err)
}
err = tbl.Read("A", "33", res).Run()
if err == nil {
t.Fatal(res)
}
}
func TestMultimapTableMultiListOrder(t *testing.T) {
tbl := ns.MultimapTable("customer93", "Tag", "Id", Customer2{})
createIf(tbl.(TableChanger), t)
joe := Customer2{
Id: "33",
Name: "Joe",
Tag: "A",
}
err := tbl.Set(joe).Run()
if err != nil {
t.Fatal(err)
}
jane := Customer2{
Id: "34",
Name: "Jane",
Tag: "A",
}
err = tbl.Set(jane).Run()
if err != nil {
t.Fatal(err)
}
customers := []Customer2{}
op := tbl.List("A", nil, 20, &customers).WithOptions(Options{
ClusteringOrder: []ClusteringOrderColumn{
{DESC, "Id"},
},
})
err = op.Run()
if err != nil {
t.Fatal(err)
}
if len(customers) != 2 {
t.Fatalf("Expected to multiread 2 records, got %d", len(customers))
}
if !reflect.DeepEqual((customers)[0], jane) {
t.Fatalf("Expected to find jane, got %v", (customers)[0])
}
if !reflect.DeepEqual((customers)[1], joe) {
t.Fatalf("Expected to find joe, got %v", (customers)[1])
}
}