forked from crewjam/go-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_importvalue_test.go
37 lines (28 loc) · 1.01 KB
/
func_importvalue_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
package cloudformation
import (
"encoding/json"
. "gopkg.in/check.v1"
)
type ImportValueFuncTest struct{}
var _ = Suite(&ImportValueFuncTest{})
func (testSuite *ImportValueFuncTest) TestRef(c *C) {
inputBuf := `{"Fn::ImportValue" : "sharedValueToImport"}`
f, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, IsNil)
c.Assert(f.(StringFunc).String(), DeepEquals, ImportValue(String("sharedValueToImport")).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 *ImportValueFuncTest) TestFailures(c *C) {
inputBuf := `{"Fn::ImportValue": ["1"]}`
_, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
inputBuf = `{"Fn::ImportValue": true}`
_, err = unmarshalFunc([]byte(inputBuf))
c.Assert(err, ErrorMatches, "cannot decode function")
}