github.com/homburg/packer@v0.6.1-0.20140528012651-1dcaf1716848/command/fix/fixer_virtualbox_gaattach_test.go (about)

     1  package fix
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestFixerVirtualBoxGAAttach_Impl(t *testing.T) {
     9  	var _ Fixer = new(FixerVirtualBoxGAAttach)
    10  }
    11  
    12  func TestFixerVirtualBoxGAAttach_Fix(t *testing.T) {
    13  	cases := []struct {
    14  		Input    map[string]interface{}
    15  		Expected map[string]interface{}
    16  	}{
    17  		// No attach field
    18  		{
    19  			Input: map[string]interface{}{
    20  				"type": "virtualbox",
    21  			},
    22  
    23  			Expected: map[string]interface{}{
    24  				"type": "virtualbox",
    25  			},
    26  		},
    27  
    28  		// Attach field == false
    29  		{
    30  			Input: map[string]interface{}{
    31  				"type": "virtualbox",
    32  				"guest_additions_attach": false,
    33  			},
    34  
    35  			Expected: map[string]interface{}{
    36  				"type":                 "virtualbox",
    37  				"guest_additions_mode": "upload",
    38  			},
    39  		},
    40  
    41  		// Attach field == true
    42  		{
    43  			Input: map[string]interface{}{
    44  				"type": "virtualbox",
    45  				"guest_additions_attach": true,
    46  			},
    47  
    48  			Expected: map[string]interface{}{
    49  				"type":                 "virtualbox",
    50  				"guest_additions_mode": "attach",
    51  			},
    52  		},
    53  
    54  		// Attach field is not a bool
    55  		{
    56  			Input: map[string]interface{}{
    57  				"type": "virtualbox",
    58  				"guest_additions_attach": "what",
    59  			},
    60  
    61  			Expected: map[string]interface{}{
    62  				"type": "virtualbox",
    63  				"guest_additions_attach": "what",
    64  			},
    65  		},
    66  	}
    67  
    68  	for _, tc := range cases {
    69  		var f FixerVirtualBoxGAAttach
    70  
    71  		input := map[string]interface{}{
    72  			"builders": []map[string]interface{}{tc.Input},
    73  		}
    74  
    75  		expected := map[string]interface{}{
    76  			"builders": []map[string]interface{}{tc.Expected},
    77  		}
    78  
    79  		output, err := f.Fix(input)
    80  		if err != nil {
    81  			t.Fatalf("err: %s", err)
    82  		}
    83  
    84  		if !reflect.DeepEqual(output, expected) {
    85  			t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
    86  		}
    87  	}
    88  }