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
/
map_table_test.go
104 lines (100 loc) · 1.94 KB
/
map_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
package gocassa
import (
"reflect"
"testing"
)
func TestMapTable(t *testing.T) {
tbl := ns.MapTable("customer81", "Id", Customer{})
createIf(tbl.(TableChanger), t)
joe := Customer{
Id: "33",
Name: "Joe",
}
err := tbl.Set(joe).Run()
if err != nil {
t.Fatal(err)
}
res := &Customer{}
err = tbl.Read("33", res).Run()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(*res, joe) {
t.Fatal(*res, joe)
}
err = tbl.Delete("33").Run()
if err != nil {
t.Fatal(err)
}
err = tbl.Read("33", res).Run()
if err == nil {
t.Fatal(res)
}
}
func TestMapTableUpdate(t *testing.T) {
tbl := ns.MapTable("customer82", "Id", Customer{})
createIf(tbl.(TableChanger), t)
joe := Customer{
Id: "33",
Name: "Joe",
}
err := tbl.Set(joe).Run()
if err != nil {
t.Fatal(err)
}
res := &Customer{}
err = tbl.Read("33", res).Run()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(*res, joe) {
t.Fatal(*res, joe)
}
err = tbl.Update("33", map[string]interface{}{
"Name": "John",
}).Run()
if err != nil {
t.Fatal(err)
}
err = tbl.Read("33", res).Run()
if err != nil {
t.Fatal(res, err)
}
if res.Name != "John" {
t.Fatal(res)
}
}
func TestMapTableMultiRead(t *testing.T) {
tbl := ns.MapTable("customer83", "Id", Customer{})
createIf(tbl.(TableChanger), t)
joe := Customer{
Id: "33",
Name: "Joe",
}
err := tbl.Set(joe).Run()
if err != nil {
t.Fatal(err)
}
jane := Customer{
Id: "34",
Name: "Jane",
}
err = tbl.Set(jane).Run()
if err != nil {
t.Fatal(err)
}
customers := &[]Customer{}
err = tbl.MultiRead([]interface{}{"33", "34"}, customers).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], joe) {
t.Fatalf("Expected to find joe, got %v", (*customers)[0])
}
if !reflect.DeepEqual((*customers)[1], jane) {
t.Fatalf("Expected to find jane, got %v", (*customers)[1])
}
}