github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/vsphere/resource_vsphere_virtual_machine_migrate_test.go (about) 1 package vsphere 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/terraform/terraform" 7 ) 8 9 func TestVSphereVirtualMachineMigrateState(t *testing.T) { 10 cases := map[string]struct { 11 StateVersion int 12 Attributes map[string]string 13 Expected map[string]string 14 Meta interface{} 15 }{ 16 "skip_customization before 0.6.16": { 17 StateVersion: 0, 18 Attributes: map[string]string{}, 19 Expected: map[string]string{ 20 "skip_customization": "false", 21 }, 22 }, 23 "enable_disk_uuid before 0.6.16": { 24 StateVersion: 0, 25 Attributes: map[string]string{}, 26 Expected: map[string]string{ 27 "enable_disk_uuid": "false", 28 }, 29 }, 30 "disk controller_type": { 31 StateVersion: 0, 32 Attributes: map[string]string{ 33 "disk.1234.size": "0", 34 "disk.5678.size": "0", 35 "disk.9999.size": "0", 36 "disk.9999.controller_type": "ide", 37 }, 38 Expected: map[string]string{ 39 "disk.1234.size": "0", 40 "disk.1234.controller_type": "scsi", 41 "disk.5678.size": "0", 42 "disk.5678.controller_type": "scsi", 43 "disk.9999.size": "0", 44 "disk.9999.controller_type": "ide", 45 }, 46 }, 47 } 48 49 for tn, tc := range cases { 50 is := &terraform.InstanceState{ 51 ID: "i-abc123", 52 Attributes: tc.Attributes, 53 } 54 is, err := resourceVSphereVirtualMachineMigrateState( 55 tc.StateVersion, is, tc.Meta) 56 57 if err != nil { 58 t.Fatalf("bad: %s, err: %#v", tn, err) 59 } 60 61 for k, v := range tc.Expected { 62 if is.Attributes[k] != v { 63 t.Fatalf( 64 "bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", 65 tn, k, v, k, is.Attributes[k], is.Attributes) 66 } 67 } 68 } 69 } 70 71 func TestComputeInstanceMigrateState_empty(t *testing.T) { 72 var is *terraform.InstanceState 73 var meta interface{} 74 75 // should handle nil 76 is, err := resourceVSphereVirtualMachineMigrateState(0, is, meta) 77 78 if err != nil { 79 t.Fatalf("err: %#v", err) 80 } 81 if is != nil { 82 t.Fatalf("expected nil instancestate, got: %#v", is) 83 } 84 85 // should handle non-nil but empty 86 is = &terraform.InstanceState{} 87 is, err = resourceVSphereVirtualMachineMigrateState(0, is, meta) 88 89 if err != nil { 90 t.Fatalf("err: %#v", err) 91 } 92 }