github.com/hashicorp/packer@v1.14.3/fix/fixer_virtualbox_rename_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 TestFixerVirtualBoxRename_impl(t *testing.T) { 12 var _ Fixer = new(FixerVirtualBoxRename) 13 } 14 15 func TestFixerVirtualBoxRename_Fix(t *testing.T) { 16 cases := []struct { 17 Input map[string]interface{} 18 Expected map[string]interface{} 19 }{ 20 { 21 Input: map[string]interface{}{ 22 "type": "virtualbox", 23 }, 24 25 Expected: map[string]interface{}{ 26 "type": "virtualbox-iso", 27 }, 28 }, 29 } 30 31 for _, tc := range cases { 32 var f FixerVirtualBoxRename 33 34 input := map[string]interface{}{ 35 "builders": []map[string]interface{}{tc.Input}, 36 } 37 38 expected := map[string]interface{}{ 39 "builders": []map[string]interface{}{tc.Expected}, 40 } 41 42 output, err := f.Fix(input) 43 if err != nil { 44 t.Fatalf("err: %s", err) 45 } 46 47 if !reflect.DeepEqual(output, expected) { 48 t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) 49 } 50 } 51 } 52 53 func TestFixerVirtualBoxRenameFix_provisionerOverride(t *testing.T) { 54 cases := []struct { 55 Input map[string]interface{} 56 Expected map[string]interface{} 57 }{ 58 { 59 Input: map[string]interface{}{ 60 "provisioners": []interface{}{ 61 map[string]interface{}{ 62 "override": map[string]interface{}{ 63 "virtualbox": map[string]interface{}{}, 64 }, 65 }, 66 }, 67 }, 68 69 Expected: map[string]interface{}{ 70 "provisioners": []interface{}{ 71 map[string]interface{}{ 72 "override": map[string]interface{}{ 73 "virtualbox-iso": map[string]interface{}{}, 74 }, 75 }, 76 }, 77 }, 78 }, 79 } 80 81 for _, tc := range cases { 82 var f FixerVirtualBoxRename 83 84 output, err := f.Fix(tc.Input) 85 if err != nil { 86 t.Fatalf("err: %s", err) 87 } 88 89 if !reflect.DeepEqual(output, tc.Expected) { 90 t.Fatalf("unexpected:\n\n%#v\nexpected:\n\n%#v\n", output, tc.Expected) 91 } 92 } 93 }