github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/template/datasource_cloudinit_config_test.go (about)

     1  package template
     2  
     3  import (
     4  	"testing"
     5  
     6  	r "github.com/hashicorp/terraform/helper/resource"
     7  )
     8  
     9  func TestRender(t *testing.T) {
    10  	testCases := []struct {
    11  		ResourceBlock string
    12  		Expected      string
    13  	}{
    14  		{
    15  			`data "template_cloudinit_config" "foo" {
    16  				gzip = false
    17  				base64_encode = false
    18  
    19  				part {
    20  					content_type = "text/x-shellscript"
    21  					content = "baz"
    22  				}
    23  			}`,
    24  			"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",
    25  		},
    26  		{
    27  			`data "template_cloudinit_config" "foo" {
    28  				gzip = false
    29  				base64_encode = false
    30  
    31  				part {
    32  					content_type = "text/x-shellscript"
    33  					content = "baz"
    34  					filename = "foobar.sh"
    35  				}
    36  			}`,
    37  			"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",
    38  		},
    39  		{
    40  			`data "template_cloudinit_config" "foo" {
    41  				gzip = false
    42  				base64_encode = false
    43  
    44  				part {
    45  					content_type = "text/x-shellscript"
    46  					content = "baz"
    47  				}
    48  				part {
    49  					content_type = "text/x-shellscript"
    50  					content = "ffbaz"
    51  				}
    52  			}`,
    53  			"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",
    54  		},
    55  	}
    56  
    57  	for _, tt := range testCases {
    58  		r.UnitTest(t, r.TestCase{
    59  			Providers: testProviders,
    60  			Steps: []r.TestStep{
    61  				r.TestStep{
    62  					Config: tt.ResourceBlock,
    63  					Check: r.ComposeTestCheckFunc(
    64  						r.TestCheckResourceAttr("data.template_cloudinit_config.foo", "rendered", tt.Expected),
    65  					),
    66  				},
    67  			},
    68  		})
    69  	}
    70  }
    71  
    72  var testCloudInitConfig_basic = `
    73  data "template_cloudinit_config" "config" {
    74    part {
    75      content_type = "text/x-shellscript"
    76      content      = "baz"
    77    }
    78  }`
    79  
    80  var testCloudInitConfig_basic_expected = `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`