forked from crewjam/go-cloudformation
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
478 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.scraper-cache | ||
.scraper-cache | ||
coverage.html | ||
coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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.(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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cloudformation | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
. "gopkg.in/check.v1" | ||
) | ||
|
||
type FindInMapFuncTest struct{} | ||
|
||
var _ = Suite(&FindInMapFuncTest{}) | ||
|
||
func (testSuite *FindInMapFuncTest) TestBasics(c *C) { | ||
inputBuf := `{ "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, | ||
{ "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }` | ||
f, err := unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, IsNil) | ||
c.Assert(f.(StringFunc).String(), DeepEquals, FindInMap( | ||
"AWSRegionArch2AMI", *Ref("AWS::Region").String(), | ||
*FindInMap("AWSInstanceType2Arch", *Ref("InstanceType").String(), | ||
*String("Arch")).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)) | ||
} | ||
|
||
func (testSuite *FindInMapFuncTest) TestFailures(c *C) { | ||
inputBuf := `{"Fn::FindInMap": 1}` | ||
_, err := unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, ErrorMatches, "cannot decode function") | ||
|
||
inputBuf = `{"Fn::FindInMap": [1, "2", "3"]}` | ||
_, err = unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, ErrorMatches, "cannot decode function") | ||
|
||
inputBuf = `{"Fn::FindInMap": ["1", 2, "3"]}` | ||
_, err = unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, ErrorMatches, "cannot decode function") | ||
|
||
inputBuf = `{"Fn::FindInMap": ["1", "2", 3]}` | ||
_, err = unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, ErrorMatches, "cannot decode function") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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").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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cloudformation | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
. "gopkg.in/check.v1" | ||
) | ||
|
||
type GetAZsFuncTest struct{} | ||
|
||
var _ = Suite(&GetAZsFuncTest{}) | ||
|
||
func (testSuite *GetAZsFuncTest) TestBasics(c *C) { | ||
inputBuf := `{"Fn::GetAZs" : {"Ref": "AWS::Region"}}` | ||
f, err := unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, IsNil) | ||
c.Assert(f.(StringListFunc).StringList(), DeepEquals, | ||
GetAZs(*Ref("AWS::Region").String()).StringList()) | ||
|
||
// 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 *GetAZsFuncTest) TestFailures(c *C) { | ||
inputBuf := `{"Fn::GetAZs": 1}` | ||
_, err := unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, ErrorMatches, "cannot decode function") | ||
|
||
inputBuf = `{"Fn::GetAZs": ["1"]}` | ||
_, err = unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, ErrorMatches, "cannot decode function") | ||
|
||
inputBuf = `{"Fn::GetAZs": ["1", "2", "3"]}` | ||
_, err = unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, ErrorMatches, "cannot decode function") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cloudformation | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
. "gopkg.in/check.v1" | ||
) | ||
|
||
type RefFuncTest struct{} | ||
|
||
var _ = Suite(&RefFuncTest{}) | ||
|
||
func (testSuite *RefFuncTest) TestRef(c *C) { | ||
inputBuf := `{"Ref" : "AWS::Region"}` | ||
f, err := unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, IsNil) | ||
c.Assert(f.(StringFunc).String(), DeepEquals, Ref("AWS::Region").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 *RefFuncTest) TestFailures(c *C) { | ||
inputBuf := `{"Ref": {"Ref": "foo"}}` | ||
_, err := unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, ErrorMatches, "cannot decode function") | ||
|
||
inputBuf = `{"Ref": ["1"]}` | ||
_, err = unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, ErrorMatches, "cannot decode function") | ||
|
||
inputBuf = `{"Ref": true}` | ||
_, err = unmarshalFunc([]byte(inputBuf)) | ||
c.Assert(err, ErrorMatches, "cannot decode function") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.