-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathrequest_test.go
More file actions
65 lines (55 loc) · 1.3 KB
/
request_test.go
File metadata and controls
65 lines (55 loc) · 1.3 KB
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
package handler
import (
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/google/go-cmp/cmp"
)
func TestUnmarshal(t *testing.T) {
type Detail struct {
Build *int
IsProduction *bool
}
type Model struct {
Name *string
Version *float64
Detail *Detail `json:"detail,omitempty"`
}
req := Request{
LogicalResourceID: "foo",
previousResourcePropertiesBody: []byte(`{"Name":"bar","Version":"0.1","detail":{"Build":"57","IsProduction":"false"}}`),
resourcePropertiesBody: []byte(`{"Name":"baz","Version":"2.3","detail":{"Build":"69","IsProduction":"true"}}`),
}
expectedPrevious := Model{
Name: aws.String("bar"),
Version: aws.Float64(0.1),
Detail: &Detail{
Build: aws.Int(57),
IsProduction: aws.Bool(false),
},
}
expectedCurrent := Model{
Name: aws.String("baz"),
Version: aws.Float64(2.3),
Detail: &Detail{
Build: aws.Int(69),
IsProduction: aws.Bool(true),
},
}
actual := Model{}
// Previous body
err := req.UnmarshalPrevious(&actual)
if err != nil {
t.Error(err)
}
if diff := cmp.Diff(actual, expectedPrevious); diff != "" {
t.Errorf(diff)
}
// Current body
err = req.Unmarshal(&actual)
if err != nil {
t.Error(err)
}
if diff := cmp.Diff(actual, expectedCurrent); diff != "" {
t.Errorf(diff)
}
}