forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
put_test.go
52 lines (44 loc) · 1.03 KB
/
put_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 TestPut(t *testing.T) {
if testDB == nil {
t.Skip(offlineSkipMsg)
}
table := testDB.Table(testTable)
now := time.Now().UTC()
item := widget{
UserID: 42,
Time: now,
Msg: "old",
}
err := table.Put(item).Run()
if err != nil {
t.Error("unexpected error:", err)
}
newItem := widget{
UserID: 42,
Time: now,
Msg: "new",
}
var oldValue widget
var cc ConsumedCapacity
err = table.Put(newItem).ConsumedCapacity(&cc).OldValue(&oldValue)
if err != nil {
t.Error("unexpected error:", err)
}
if !reflect.DeepEqual(oldValue, item) {
t.Errorf("bad old value. %#v ≠ %#v", oldValue, item)
}
if cc.Total != 1 || cc.Table != 1 || cc.TableName != testTable {
t.Errorf("bad consumed capacity: %#v", cc)
}
// putting the same item: this should fail
err = table.Put(newItem).If("attribute_not_exists(UserID)").If("attribute_not_exists('Time')").Run()
if !isConditionalCheckErr(err) {
t.Error("expected ConditionalCheckFailedException, not", err)
}
}