github.com/paultyng/terraform@v0.6.11-0.20180227224804-66ff8f8bed40/command/hcl_printer_test.go (about)

     1  package command
     2  
     3  import "testing"
     4  
     5  // The command package has it's own HCL encoder to encode variables to push.
     6  // Make sure the variable we encode parse correctly
     7  func TestHCLEncoder_parse(t *testing.T) {
     8  	cases := []struct {
     9  		Name  string
    10  		Val   interface{}
    11  		Error bool
    12  	}{
    13  		{
    14  			Name: "int",
    15  			Val:  12345,
    16  		},
    17  		{
    18  			Name: "float",
    19  			Val:  1.2345,
    20  		},
    21  		{
    22  			Name: "string",
    23  			Val:  "terraform",
    24  		},
    25  		{
    26  			Name: "list",
    27  			Val:  []interface{}{"a", "b", "c"},
    28  		},
    29  		{
    30  			Name: "map",
    31  			Val: map[string]interface{}{
    32  				"a": 1,
    33  			},
    34  		},
    35  		// a numeric looking identifier requires quotes
    36  		{
    37  			Name: "map_with_quoted_key",
    38  			Val: map[string]interface{}{
    39  				"0.0.0.0/24": "mask",
    40  			},
    41  		},
    42  	}
    43  
    44  	for _, c := range cases {
    45  		t.Run(c.Name, func(t *testing.T) {
    46  			_, err := encodeHCL(c.Val)
    47  			if err != nil {
    48  				t.Fatal(err)
    49  			}
    50  		})
    51  	}
    52  }