forked from crewjam/go-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunc_getazs_test.go
46 lines (35 loc) · 1.22 KB
/
func_getazs_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
package cloudformation
import (
"encoding/json"
. "gopkg.in/check.v1"
)
type GetAZsFuncTest struct{}
var _ = Suite(&GetAZsFuncTest{})
func (testSuite *GetAZsFuncTest) TestBasics(c *C) {
inputBuf := `{"Fn::GetAZs" : {"Ref": "AWS::Region"}}`
f, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, IsNil)
c.Assert(f.(StringListFunc).StringList(), DeepEquals,
GetAZs(Ref("AWS::Region")))
// old way
c.Assert(f.(StringListFunc).StringList(), DeepEquals,
GetAZs(*Ref("AWS::Region").String()).StringList())
// 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 *GetAZsFuncTest) TestFailures(c *C) {
inputBuf := `{"Fn::GetAZs": 1}`
_, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::GetAZs": ["1"]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::GetAZs": ["1", "2", "3"]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
}