github.com/Hashicorp/packer@v1.3.2/fix/fixer_amazon_private_ip_test.go (about)

     1  package fix
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestFixerAmazonPrivateIP_Impl(t *testing.T) {
     9  	var _ Fixer = new(FixerAmazonPrivateIP)
    10  }
    11  
    12  func TestFixerAmazonPrivateIP(t *testing.T) {
    13  	cases := []struct {
    14  		Input    map[string]interface{}
    15  		Expected map[string]interface{}
    16  	}{
    17  		// Attach field == false
    18  		{
    19  			Input: map[string]interface{}{
    20  				"type":           "amazon-ebs",
    21  				"ssh_private_ip": false,
    22  			},
    23  
    24  			Expected: map[string]interface{}{
    25  				"type":          "amazon-ebs",
    26  				"ssh_interface": "public_ip",
    27  			},
    28  		},
    29  
    30  		// Attach field == true
    31  		{
    32  			Input: map[string]interface{}{
    33  				"type":           "amazon-ebs",
    34  				"ssh_private_ip": true,
    35  			},
    36  
    37  			Expected: map[string]interface{}{
    38  				"type":          "amazon-ebs",
    39  				"ssh_interface": "private_ip",
    40  			},
    41  		},
    42  
    43  		// ssh_private_ip specified as string
    44  		{
    45  			Input: map[string]interface{}{
    46  				"type":           "amazon-ebs",
    47  				"ssh_private_ip": "true",
    48  			},
    49  
    50  			Expected: map[string]interface{}{
    51  				"type":          "amazon-ebs",
    52  				"ssh_interface": "private_ip",
    53  			},
    54  		},
    55  	}
    56  
    57  	for _, tc := range cases {
    58  		var f FixerAmazonPrivateIP
    59  
    60  		input := map[string]interface{}{
    61  			"builders": []map[string]interface{}{tc.Input},
    62  		}
    63  
    64  		expected := map[string]interface{}{
    65  			"builders": []map[string]interface{}{tc.Expected},
    66  		}
    67  
    68  		output, err := f.Fix(input)
    69  		if err != nil {
    70  			t.Fatalf("err: %s", err)
    71  		}
    72  
    73  		if !reflect.DeepEqual(output, expected) {
    74  			t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
    75  		}
    76  	}
    77  }