-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
delete_test.go
58 lines (53 loc) · 1.18 KB
/
delete_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
package dynamo
import (
"context"
"reflect"
"testing"
"time"
)
func TestDelete(t *testing.T) {
if testDB == nil {
t.Skip(offlineSkipMsg)
}
ctx := context.TODO()
table := testDB.Table(testTableWidgets)
// first, add an item to delete later
item := widget{
UserID: 42,
Time: time.Now().UTC(),
Msg: "hello",
Meta: map[string]string{
"color": "octarine",
},
}
err := table.Put(item).Run(ctx)
if err != nil {
t.Error("unexpected error:", err)
}
// fail to delete it
var curr widget
wrote, err := table.Delete("UserID", item.UserID).
Range("Time", item.Time).
If("Meta.'color' = ?", "octarine").
If("Msg = ?", "wrong msg").
CurrentValue(ctx, &curr)
if wrote {
t.Error("wrote should be false")
}
if !reflect.DeepEqual(curr, item) {
t.Errorf("bad value. %#v ≠ %#v", curr, item)
}
// delete it
var old widget
var cc ConsumedCapacity
err = table.Delete("UserID", item.UserID).Range("Time", item.Time).ConsumedCapacity(&cc).OldValue(ctx, &old)
if err != nil {
t.Error("unexpected error:", err)
}
if !reflect.DeepEqual(old, item) {
t.Errorf("bad old value. %#v ≠ %#v", old, item)
}
if cc.Total < 1 {
t.Error("invalid ConsumedCapacity", cc)
}
}