forked from guregu/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoding_aws_test.go
82 lines (72 loc) · 1.76 KB
/
encoding_aws_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
package dynamo
import (
"reflect"
"testing"
"time"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)
type awsTestWidget struct {
UserID int // Hash key, a.k.a. partition key
Time time.Time // Range key, a.k.a. sort key
Msg string `dynamodbav:"Message"`
Count int `dynamodbav:",omitempty"`
Friends []string `dynamodbav:",stringset"` // Sets
SecretKey string `dynamodbav:"-"` // Ignored
}
func TestAWSEncoding(t *testing.T) {
w := awsTestWidget{
UserID: 555,
Time: time.Now().UTC(),
Msg: "hello",
Count: 0,
Friends: []string{"a", "b"},
SecretKey: "seeeekret",
}
av, err := Marshal(AWSEncoding(w))
if err != nil {
t.Error(err)
}
official, err := dynamodbattribute.Marshal(w)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(av, official) {
t.Error("AWS marshal not equal")
}
blank := awsTestWidget{}
err = Unmarshal(official, AWSEncoding(&blank))
if err != nil {
t.Error(err)
}
w.SecretKey = ""
if !reflect.DeepEqual(w, blank) {
t.Error("AWS unmarshal not equal")
t.Logf("%#v != %#v", w, blank)
}
}
func TestAWSIfaces(t *testing.T) {
unix := dynamodbattribute.UnixTime(time.Now())
av, err := Marshal(unix)
if err != nil {
t.Error(err)
}
official, err := dynamodbattribute.Marshal(unix)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(av, official) {
t.Error("marshal not equal.", av, "≠", official)
}
var result, officialResult dynamodbattribute.UnixTime
err = Unmarshal(official, &result)
if err != nil {
t.Error(err)
}
err = dynamodbattribute.Unmarshal(official, &officialResult)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(result, officialResult) {
t.Error("unmarshal not equal.", result, "≠", officialResult)
}
}