forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_test.go
52 lines (47 loc) · 1.06 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
package dynamo
import (
"reflect"
"testing"
"time"
)
func TestDelete(t *testing.T) {
if testDB == nil {
t.Skip(offlineSkipMsg)
}
table := testDB.Table(testTable)
// 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()
if err != nil {
t.Error("unexpected error:", err)
}
// fail to delete it
err = table.Delete("UserID", item.UserID).
Range("Time", item.Time).
If("Meta.'color' = ?", "octarine").
If("Msg = ?", "wrong msg").
Run()
if !isConditionalCheckErr(err) {
t.Error("expected ConditionalCheckFailedException, not", err)
}
// delete it
var old widget
var cc ConsumedCapacity
err = table.Delete("UserID", item.UserID).Range("Time", item.Time).ConsumedCapacity(&cc).OldValue(&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)
}
}