github.com/vmware/govmomi@v0.51.0/simulator/vm_provisioning_checker_test.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package simulator_test 6 7 import ( 8 "context" 9 "testing" 10 11 "github.com/vmware/govmomi/find" 12 "github.com/vmware/govmomi/object" 13 "github.com/vmware/govmomi/simulator" 14 "github.com/vmware/govmomi/vim25" 15 "github.com/vmware/govmomi/vim25/types" 16 ) 17 18 func TestVmProvisioningChecker(t *testing.T) { 19 simulator.Test(func(ctx context.Context, c *vim25.Client) { 20 finder := find.NewFinder(c, true) 21 datacenter, err := finder.DefaultDatacenter(ctx) 22 if err != nil { 23 t.Fatalf("default datacenter not found: %s", err) 24 } 25 finder.SetDatacenter(datacenter) 26 vmList, err := finder.VirtualMachineList(ctx, "*") 27 if len(vmList) == 0 { 28 t.Fatal("vmList == 0") 29 } 30 vm := vmList[0] 31 32 vmpc := object.NewVmProvisioningChecker(c) 33 34 t.Run("CheckRelocate", func(t *testing.T) { 35 results, err := vmpc.CheckRelocate( 36 ctx, 37 vm.Reference(), 38 types.VirtualMachineRelocateSpec{}) 39 40 for _, result := range results { 41 if err != nil { 42 t.Fatal(err) 43 } 44 if len(result.Error) > 0 { 45 t.Fatal("result has errors") 46 } 47 if len(result.Warning) > 0 { 48 t.Fatal("result has warnings") 49 } 50 } 51 }) 52 }) 53 }