github.com/erriapo/terraform@v0.6.12-0.20160203182612-0340ea72354f/builtin/providers/template/resource_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  			`resource "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=\"MIMEBOUNDRY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDRY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDRY--\r\n",
    25  		},
    26  		{
    27  			`resource "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=\"MIMEBOUNDRY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDRY\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--MIMEBOUNDRY--\r\n",
    38  		},
    39  		{
    40  			`resource "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=\"MIMEBOUNDRY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDRY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDRY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nffbaz\r\n--MIMEBOUNDRY--\r\n",
    54  		},
    55  		{
    56  			`resource "template_cloudinit_config" "foo" {
    57  				gzip = true
    58  				base64_encode = false
    59  
    60  				part {
    61  					content_type = "text/x-shellscript"
    62  					content = "baz"
    63  					filename = "ah"
    64  				}
    65  				part {
    66  					content_type = "text/x-shellscript"
    67  					content = "ffbaz"
    68  				}
    69  			}`,
    70  			"\x1f\x8b\b\x00\x00\tn\x88\x00\xff\xac\xce\xc1J\x031\x10\xc6\xf1{`\xdf!\xe4>VO\u0096^\xb4=xX\x05\xa9\x82\xc7\xd9݉;\x90LB2\x85\xadOo-\x88\x8b\xe2\xadDŽ\x1f\xf3\xfd\xef\x93(\x89\xc2\xfe\x98\xa9\xb5\xf1\x10\x943\x16]E\x9ei\\\xdb>\x1dd\xc4rܸ\xee\xa1\xdb\xdd=\xbd<n\x9fߜ\xf9z\xc0+\x95\xcaIZ{su\xdd\x18\x80\x85h\xcc\xf7\xdd-ל*\xeb\x19\xa2*\x0eS<\xfd\xaf\xad\xe7@\x82\x916\x0e'\xf7\xe3\xf7\x05\xa5z*\xb0\x93!\x8d,ﭽ\xedY\x17\xe0\x1c\xaa4\xebj\x86:Q\bu(\x9cO\xa2\xe3H\xbf\xa2\x1a\xd3\xe3ǿm\x97\xde\xf2\xfe\xef\x1a@c>\x03\x00\x00\xff\xffmB\x8c\xeed\x01\x00\x00",
    71  		},
    72  	}
    73  
    74  	for _, tt := range testCases {
    75  		r.Test(t, r.TestCase{
    76  			Providers: testProviders,
    77  			Steps: []r.TestStep{
    78  				r.TestStep{
    79  					Config: tt.ResourceBlock,
    80  					Check: r.ComposeTestCheckFunc(
    81  						r.TestCheckResourceAttr("template_cloudinit_config.foo", "rendered", tt.Expected),
    82  					),
    83  				},
    84  			},
    85  		})
    86  	}
    87  }
    88  
    89  func TestCloudConfig_update(t *testing.T) {
    90  	r.Test(t, r.TestCase{
    91  		Providers: testProviders,
    92  		Steps: []r.TestStep{
    93  			r.TestStep{
    94  				Config: testCloudInitConfig_basic,
    95  				Check: r.ComposeTestCheckFunc(
    96  					r.TestCheckResourceAttr("template_cloudinit_config.config", "rendered", testCloudInitConfig_basic_expected),
    97  				),
    98  			},
    99  
   100  			r.TestStep{
   101  				Config: testCloudInitConfig_update,
   102  				Check: r.ComposeTestCheckFunc(
   103  					r.TestCheckResourceAttr("template_cloudinit_config.config", "rendered", testCloudInitConfig_update_expected),
   104  				),
   105  			},
   106  		},
   107  	})
   108  }
   109  
   110  var testCloudInitConfig_basic = `
   111  resource "template_cloudinit_config" "config" {
   112    part {
   113      content_type = "text/x-shellscript"
   114      content      = "baz"
   115    }
   116  }`
   117  
   118  var testCloudInitConfig_basic_expected = `Content-Type: multipart/mixed; boundary=\"MIMEBOUNDRY\"\nMIME-Version: 1.0\r\n--MIMEBOUNDRY\r\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nbaz\r\n--MIMEBOUNDRY--\r\n`
   119  
   120  var testCloudInitConfig_update = `
   121  resource "template_cloudinit_config" "config" {
   122    part {
   123      content_type = "text/x-shellscript"
   124      content      = "baz"
   125    }
   126  
   127    part {
   128      content_type = "text/x-shellscript"
   129      content      = "ffbaz"
   130    }
   131  }`
   132  
   133  var testCloudInitConfig_update_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\nContent-Transfer-Encoding: 7bit\r\nContent-Type: text/x-shellscript\r\nMime-Version: 1.0\r\n\r\nffbaz\r\n--MIMEBOUNDARY--\r\n`