github.com/hashicorp/packer@v1.14.3/fix/fixer_virtualbox_gaattach_test.go (about)

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