github.com/hashicorp/packer@v1.14.3/fix/fixer_vsphere_network_storage_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 TestFixerVSphereNetwork_impl(t *testing.T) { 12 var _ Fixer = new(FixerVSphereNetworkDisk) 13 } 14 15 func TestFixerVSphereNetwork_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": "vsphere-iso", 23 "network": "", 24 "networkCard": "vmxnet3", 25 "disk_size": 5000, 26 }, 27 28 Expected: map[string]interface{}{ 29 "type": "vsphere-iso", 30 "network_adapters": []interface{}{ 31 map[string]interface{}{ 32 "network": "", 33 "network_card": "vmxnet3", 34 }, 35 }, 36 "storage": []interface{}{ 37 map[string]interface{}{ 38 "disk_size": 5000, 39 }, 40 }, 41 }, 42 }, 43 { 44 Input: map[string]interface{}{ 45 "type": "vsphere-iso", 46 "network": "", 47 "network_card": "vmxnet3", 48 "disk_size": 5000, 49 }, 50 51 Expected: map[string]interface{}{ 52 "type": "vsphere-iso", 53 "network_adapters": []interface{}{ 54 map[string]interface{}{ 55 "network": "", 56 "network_card": "vmxnet3", 57 }, 58 }, 59 "storage": []interface{}{ 60 map[string]interface{}{ 61 "disk_size": 5000, 62 }, 63 }, 64 }, 65 }, 66 { 67 Input: map[string]interface{}{ 68 "type": "vsphere-iso", 69 "network": "myNetwork", 70 "networkCard": "vmxnet3", 71 "disk_size": 5000, 72 "disk_thin_provisioned": true, 73 "disk_eagerly_scrub": true, 74 }, 75 76 Expected: map[string]interface{}{ 77 "type": "vsphere-iso", 78 "network_adapters": []interface{}{ 79 map[string]interface{}{ 80 "network": "myNetwork", 81 "network_card": "vmxnet3", 82 }, 83 }, 84 "storage": []interface{}{ 85 map[string]interface{}{ 86 "disk_size": 5000, 87 "disk_thin_provisioned": true, 88 "disk_eagerly_scrub": true, 89 }, 90 }, 91 }, 92 }, 93 { 94 Input: map[string]interface{}{ 95 "type": "vsphere-iso", 96 "network": "myNetwork", 97 "networkCard": "vmxnet3", 98 "disk_size": 5000, 99 "disk_thin_provisioned": true, 100 "disk_eagerly_scrub": true, 101 "network_adapters": []interface{}{ 102 map[string]interface{}{ 103 "network": "net1", 104 "network_card": "vmxnet3", 105 }, 106 }, 107 "storage": []interface{}{ 108 map[string]interface{}{ 109 "disk_size": 5001, 110 "disk_thin_provisioned": true, 111 "disk_eagerly_scrub": true, 112 }, 113 }, 114 }, 115 116 Expected: map[string]interface{}{ 117 "type": "vsphere-iso", 118 "network_adapters": []interface{}{ 119 map[string]interface{}{ 120 "network": "myNetwork", 121 "network_card": "vmxnet3", 122 }, 123 map[string]interface{}{ 124 "network": "net1", 125 "network_card": "vmxnet3", 126 }, 127 }, 128 "storage": []interface{}{ 129 map[string]interface{}{ 130 "disk_size": 5000, 131 "disk_thin_provisioned": true, 132 "disk_eagerly_scrub": true, 133 }, 134 map[string]interface{}{ 135 "disk_size": 5001, 136 "disk_thin_provisioned": true, 137 "disk_eagerly_scrub": true, 138 }, 139 }, 140 }, 141 }, 142 } 143 144 for _, tc := range cases { 145 var f FixerVSphereNetworkDisk 146 147 input := map[string]interface{}{ 148 "builders": []map[string]interface{}{tc.Input}, 149 } 150 151 expected := map[string]interface{}{ 152 "builders": []map[string]interface{}{tc.Expected}, 153 } 154 155 output, err := f.Fix(input) 156 if err != nil { 157 t.Fatalf("err: %s", err) 158 } 159 160 if !reflect.DeepEqual(output, expected) { 161 t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) 162 } 163 } 164 }