forked from crewjam/go-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 2
/
integer_test.go
45 lines (34 loc) · 1.11 KB
/
integer_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
package cloudformation
import (
"encoding/json"
. "gopkg.in/check.v1"
)
type IntegerTest struct{}
var _ = Suite(&IntegerTest{})
func (testSuite *IntegerTest) TestInteger(c *C) {
inputBuf := `{"B": 1, "C": 2, "D": {"Ref": "foo"}, "E": "1"}`
v := struct {
A *IntegerExpr `json:",omitempty"`
B *IntegerExpr `json:",omitempty"`
C *IntegerExpr `json:",omitempty"`
D *IntegerExpr `json:",omitempty"`
E *IntegerExpr `json:",omitempty"`
}{}
err := json.Unmarshal([]byte(inputBuf), &v)
c.Assert(err, IsNil)
c.Assert(v.A, IsNil)
c.Assert(v.B, DeepEquals, Integer(1))
c.Assert(v.C, DeepEquals, Integer(2))
c.Assert(v.D, DeepEquals, Ref("foo").Integer())
c.Assert(v.E, DeepEquals, Integer(1))
buf, err := json.Marshal(v)
c.Assert(err, IsNil)
c.Assert(string(buf), Equals,
`{"B":1,"C":2,"D":{"Ref":"foo"},"E":1}`)
inputBuf = `{"A": "invalid"}`
err = json.Unmarshal([]byte(inputBuf), &v)
c.Assert(err, ErrorMatches, "json: cannot unmarshal string.*")
inputBuf = `{"A": {"Fn::Missing": "invalid"}}`
err = json.Unmarshal([]byte(inputBuf), &v)
c.Assert(err, ErrorMatches, "unknown function Fn::Missing")
}