forked from crewjam/go-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 2
/
func_join_test.go
49 lines (37 loc) · 1.34 KB
/
func_join_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
package cloudformation
import (
"encoding/json"
. "gopkg.in/check.v1"
)
type JoinFuncTest struct{}
var _ = Suite(&JoinFuncTest{})
func (testSuite *JoinFuncTest) TestRef(c *C) {
inputBuf := `{"Fn::Join":["x",["y",{"Ref":"foo"},"1"]]}`
f, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, IsNil)
c.Assert(f.(StringFunc).String(), DeepEquals,
Join("x", String("y"), Ref("foo"), String("1")))
// old way
c.Assert(f.(StringFunc).String(), DeepEquals,
Join("x", *String("y"), *Ref("foo").String(), *String("1")).String())
buf, err := json.Marshal(f)
c.Assert(err, IsNil)
c.Assert(string(buf), Equals, inputBuf)
}
func (testSuite *JoinFuncTest) TestFailures(c *C) {
inputBuf := `{"Fn::Join": 1}`
_, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::Join": ["1"]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::Join": ["1", [1]]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::Join": ["1", ["2"], "3"]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::Join": [false, ["2"]]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
}