2016-05-22 00:09:55 +02:00
|
|
|
package template
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-04-12 16:48:53 +02:00
|
|
|
"regexp"
|
|
|
|
|
2016-05-22 00:09:55 +02:00
|
|
|
r "github.com/hashicorp/terraform/helper/resource"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRender(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
ResourceBlock string
|
|
|
|
Expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
`data "template_cloudinit_config" "foo" {
|
|
|
|
gzip = false
|
|
|
|
base64_encode = false
|
|
|
|
|
|
|
|
part {
|
|
|
|
content_type = "text/x-shellscript"
|
|
|
|
content = "baz"
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
"Content-Type: multipart/mixed; boundary=\"MIMEBOUNDARY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDARY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDARY--\r\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
`data "template_cloudinit_config" "foo" {
|
|
|
|
gzip = false
|
|
|
|
base64_encode = false
|
|
|
|
|
|
|
|
part {
|
|
|
|
content_type = "text/x-shellscript"
|
|
|
|
content = "baz"
|
|
|
|
filename = "foobar.sh"
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
"Content-Type: multipart/mixed; boundary=\"MIMEBOUNDARY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDARY\r\nContent-Disposition: attachment; filename=\"foobar.sh\"\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDARY--\r\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
`data "template_cloudinit_config" "foo" {
|
|
|
|
gzip = false
|
|
|
|
base64_encode = false
|
|
|
|
|
|
|
|
part {
|
|
|
|
content_type = "text/x-shellscript"
|
|
|
|
content = "baz"
|
|
|
|
}
|
|
|
|
part {
|
|
|
|
content_type = "text/x-shellscript"
|
|
|
|
content = "ffbaz"
|
|
|
|
}
|
|
|
|
}`,
|
|
|
|
"Content-Type: multipart/mixed; boundary=\"MIMEBOUNDARY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDARY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDARY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nffbaz\r\n--MIMEBOUNDARY--\r\n",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range testCases {
|
|
|
|
r.UnitTest(t, r.TestCase{
|
|
|
|
Providers: testProviders,
|
|
|
|
Steps: []r.TestStep{
|
2017-04-12 16:48:53 +02:00
|
|
|
{
|
2016-05-22 00:09:55 +02:00
|
|
|
Config: tt.ResourceBlock,
|
|
|
|
Check: r.ComposeTestCheckFunc(
|
|
|
|
r.TestCheckResourceAttr("data.template_cloudinit_config.foo", "rendered", tt.Expected),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 16:48:53 +02:00
|
|
|
// From GH-13572, Correctly handle panic on a misconfigured cloudinit part
|
|
|
|
func TestRender_handlePanic(t *testing.T) {
|
|
|
|
r.UnitTest(t, r.TestCase{
|
|
|
|
Providers: testProviders,
|
|
|
|
Steps: []r.TestStep{
|
|
|
|
{
|
|
|
|
Config: testCloudInitConfig_misconfiguredParts,
|
|
|
|
ExpectError: regexp.MustCompile("Unable to parse parts in cloudinit resource declaration"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var testCloudInitConfig_misconfiguredParts = `
|
|
|
|
data "template_cloudinit_config" "foo" {
|
2016-05-22 00:09:55 +02:00
|
|
|
part {
|
2017-04-12 16:48:53 +02:00
|
|
|
content = ""
|
2016-05-22 00:09:55 +02:00
|
|
|
}
|
2017-04-12 16:48:53 +02:00
|
|
|
}
|
|
|
|
`
|