forked from crewjam/go-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunc_getatt_test.go
45 lines (35 loc) · 1.24 KB
/
func_getatt_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 GetAttFuncTest struct{}
var _ = Suite(&GetAttFuncTest{})
func (testSuite *GetAttFuncTest) TestBasics(c *C) {
inputBuf := `{"Fn::GetAtt" : ["MySQLDatabase", "Endpoint.Address"]}`
f, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, IsNil)
c.Assert(f.(StringFunc).String(), DeepEquals,
GetAtt("MySQLDatabase", "Endpoint.Address"))
// old way
c.Assert(f.(StringFunc).String(), DeepEquals,
GetAtt("MySQLDatabase", "Endpoint.Address").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 *GetAttFuncTest) TestFailures(c *C) {
inputBuf := `{"Fn::GetAtt": 1}`
_, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::GetAtt": ["1"]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::GetAtt": ["1", "2", "3"]}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
}