This repository has been archived by the owner on Jan 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
func_select_test.go
62 lines (48 loc) · 1.75 KB
/
func_select_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
package cloudformation
import (
"encoding/json"
. "gopkg.in/check.v1"
)
type SelectFuncTest struct{}
var _ = Suite(&SelectFuncTest{})
func (testSuite *SelectFuncTest) TestRef(c *C) {
inputBuf := `{"Fn::Select":["2",{"Fn::GetAZs":{"Ref":"AWS::Region"}}]}`
f, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, IsNil)
c.Assert(f.(StringFunc).String(), DeepEquals,
Select("2", GetAZs(Ref("AWS::Region"))))
// old way
c.Assert(f.(StringFunc).String(), DeepEquals,
SelectFunc{Selector: "2",
Items: *GetAZs(*Ref("AWS::Region").String()).StringList()}.String())
buf, err := json.Marshal(f)
c.Assert(err, IsNil)
c.Assert(string(buf), Equals, inputBuf)
}
func (testSuite *SelectFuncTest) TestRef2(c *C) {
inputBuf := `{"Fn::Select":["2",["1","2","3"]]}`
f, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, IsNil)
c.Assert(f.(StringFunc).String(), DeepEquals,
Select("2", *String("1"), *String("2"), *String("3")).String())
buf, err := json.Marshal(f)
c.Assert(err, IsNil)
c.Assert(string(buf), Equals, inputBuf)
}
func (testSuite *SelectFuncTest) TestFailures(c *C) {
inputBuf := `{"Fn::Select": 1}`
_, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::Select": ["1"]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::Select": ["1", [1]]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::Select": ["1", ["2"], "3"]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::Select": [false, ["2"]]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
}