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
/
Copy pathfunc_base64_test.go
71 lines (61 loc) · 2.55 KB
/
func_base64_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
63
64
65
66
67
68
69
70
71
package cloudformation
import (
"encoding/json"
. "gopkg.in/check.v1"
)
type Base64FuncTest struct{}
var _ = Suite(&Base64FuncTest{})
func (testSuite *Base64FuncTest) TestRef(c *C) {
inputBuf := `{ "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash -xe\n",
"yum update -y aws-cfn-bootstrap\n",
"# Install the files and packages from the metadata\n",
"/opt/aws/bin/cfn-init -v ",
" --stack ", { "Ref" : "AWS::StackName" },
" --resource LaunchConfig ",
" --region ", { "Ref" : "AWS::Region" }, "\n",
"# Signal the status from cfn-init\n",
"/opt/aws/bin/cfn-signal -e $? ",
" --stack ", { "Ref" : "AWS::StackName" },
" --resource WebServerGroup ",
" --region ", { "Ref" : "AWS::Region" }, "\n"
]]}}`
f, err := unmarshalFunc([]byte(inputBuf))
c.Assert(err, IsNil)
c.Assert(f.(Stringable).String(), DeepEquals, Base64(Join("",
String("#!/bin/bash -xe\n"),
String("yum update -y aws-cfn-bootstrap\n"),
String("# Install the files and packages from the metadata\n"),
String("/opt/aws/bin/cfn-init -v "),
String(" --stack "), Ref("AWS::StackName").String(),
String(" --resource LaunchConfig "),
String(" --region "), Ref("AWS::Region").String(), String("\n"),
String("# Signal the status from cfn-init\n"),
String("/opt/aws/bin/cfn-signal -e $? "),
String(" --stack "), Ref("AWS::StackName").String(),
String(" --resource WebServerGroup "),
String(" --region "), Ref("AWS::Region").String(), String("\n"),
)))
// old way still compiles
c.Assert(f.(StringFunc).String(), DeepEquals, Base64(*Join("",
*String("#!/bin/bash -xe\n"),
*String("yum update -y aws-cfn-bootstrap\n"),
*String("# Install the files and packages from the metadata\n"),
*String("/opt/aws/bin/cfn-init -v "),
*String(" --stack "), *Ref("AWS::StackName").String(),
*String(" --resource LaunchConfig "),
*String(" --region "), *Ref("AWS::Region").String(), *String("\n"),
*String("# Signal the status from cfn-init\n"),
*String("/opt/aws/bin/cfn-signal -e $? "),
*String(" --stack "), *Ref("AWS::StackName").String(),
*String(" --resource WebServerGroup "),
*String(" --region "), *Ref("AWS::Region").String(), *String("\n"),
).String()).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))
}