github.com/gdavison/packer@v0.10.1/fix/fixer_parallels_deprections_test.go (about) 1 package fix 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestFixerParallelsDeprecations(t *testing.T) { 9 var _ Fixer = new(FixerParallelsDeprecations) 10 } 11 12 func TestFixerParallelsDeprecations_Fix_parallels_tools_guest_path(t *testing.T) { 13 cases := []struct { 14 Input map[string]interface{} 15 Expected map[string]interface{} 16 }{ 17 // No parallels_tools_host_path field 18 { 19 Input: map[string]interface{}{ 20 "type": "parallels-iso", 21 }, 22 23 Expected: map[string]interface{}{ 24 "type": "parallels-iso", 25 }, 26 }, 27 28 // parallels_tools_host_path field 29 { 30 Input: map[string]interface{}{ 31 "type": "parallels-iso", 32 "parallels_tools_host_path": "/Path...", 33 }, 34 35 Expected: map[string]interface{}{ 36 "type": "parallels-iso", 37 }, 38 }, 39 } 40 41 for _, tc := range cases { 42 var f FixerParallelsDeprecations 43 44 input := map[string]interface{}{ 45 "builders": []map[string]interface{}{tc.Input}, 46 } 47 48 expected := map[string]interface{}{ 49 "builders": []map[string]interface{}{tc.Expected}, 50 } 51 52 output, err := f.Fix(input) 53 if err != nil { 54 t.Fatalf("err: %s", err) 55 } 56 57 if !reflect.DeepEqual(output, expected) { 58 t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) 59 } 60 } 61 } 62 63 func TestFixerParallelsDeprecations_Fix_guest_os_distribution(t *testing.T) { 64 cases := []struct { 65 Input map[string]interface{} 66 Expected map[string]interface{} 67 }{ 68 // No guest_os_distribution field 69 { 70 Input: map[string]interface{}{ 71 "type": "parallels-iso", 72 "guest_os_type": "ubuntu", 73 }, 74 75 Expected: map[string]interface{}{ 76 "type": "parallels-iso", 77 "guest_os_type": "ubuntu", 78 }, 79 }, 80 81 // guest_os_distribution and guest_os_type field 82 { 83 Input: map[string]interface{}{ 84 "type": "parallels-iso", 85 "guest_os_type": "linux", 86 "guest_os_distribution": "ubuntu", 87 }, 88 89 Expected: map[string]interface{}{ 90 "type": "parallels-iso", 91 "guest_os_type": "ubuntu", 92 }, 93 }, 94 95 // guest_os_distribution but no guest_os_type field 96 { 97 Input: map[string]interface{}{ 98 "type": "parallels-iso", 99 "guest_os_distribution": "ubuntu", 100 }, 101 102 Expected: map[string]interface{}{ 103 "type": "parallels-iso", 104 "guest_os_type": "ubuntu", 105 }, 106 }, 107 } 108 109 for _, tc := range cases { 110 var f FixerParallelsDeprecations 111 112 input := map[string]interface{}{ 113 "builders": []map[string]interface{}{tc.Input}, 114 } 115 116 expected := map[string]interface{}{ 117 "builders": []map[string]interface{}{tc.Expected}, 118 } 119 120 output, err := f.Fix(input) 121 if err != nil { 122 t.Fatalf("err: %s", err) 123 } 124 125 if !reflect.DeepEqual(output, expected) { 126 t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) 127 } 128 } 129 }