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