forked from mweagle/go-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_ref_test.go
41 lines (31 loc) · 1.05 KB
/
func_ref_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
package cloudformation
import (
"encoding/json"
. "gopkg.in/check.v1"
)
type RefFuncTest struct{}
var _ = Suite(&RefFuncTest{})
func (testSuite *RefFuncTest) TestRef(c *C) {
inputBuf := `{"Ref" : "AWS::Region"}`
f, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, IsNil)
c.Assert(f.(StringFunc).String(), DeepEquals, Ref("AWS::Region").String())
// tidy the JSON input
inputStruct := map[string]interface{}{}
_ = json.Unmarshal([]byte(inputBuf), &inputStruct)
expectedBuf, _ := json.Marshal(inputStruct)
buf, err := json.Marshal(f)
c.Assert(err, IsNil)
c.Assert(string(buf), Equals, string(expectedBuf))
}
func (testSuite *RefFuncTest) TestFailures(c *C) {
inputBuf := `{"Ref": {"Ref": "foo"}}`
_, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Ref": ["1"]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Ref": true}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
}