forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_test.go
58 lines (53 loc) · 1.19 KB
/
update_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 (
"reflect"
"testing"
"time"
)
func TestUpdate(t *testing.T) {
if testDB == nil {
t.Skip(offlineSkipMsg)
}
table := testDB.Table(testTable)
// first, add an item to make sure there is at least one
item := widget{
UserID: 42,
Time: time.Now().UTC(),
Msg: "hello",
Count: 0,
}
err := table.Put(item).Run()
if err != nil {
t.Error("unexpected error:", err)
}
// change it a bit and check the result
var result widget
err = table.Update("UserID", item.UserID).
Range("Time", item.Time).
Set("Msg", "changed").
Add("Count", 1).
Add("Test", []string{"A", "B"}).
Value(&result)
expected := widget{
UserID: item.UserID,
Time: item.Time,
Msg: "changed",
Count: 1,
}
if err != nil {
t.Error("unexpected error:", err)
}
if !reflect.DeepEqual(result, expected) {
t.Errorf("bad result. %+v ≠ %+v", result, expected)
}
// send an update with a failing condition
err = table.Update("UserID", item.UserID).
Range("Time", item.Time).
Set("Msg", "shouldn't happen").
Add("Count", 1).
If("'Count' > ?", 100).
Value(&result)
if !isConditionalCheckErr(err) {
t.Error("expected ConditionalCheckFailedException, not", err)
}
}