github.com/vmware/govmomi@v0.37.1/eam/object/object_test.go (about) 1 /* 2 Copyright (c) 2021 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package object_test 18 19 import ( 20 "context" 21 "log" 22 "os" 23 "testing" 24 25 "github.com/vmware/govmomi" 26 "github.com/vmware/govmomi/eam" 27 "github.com/vmware/govmomi/eam/object" 28 "github.com/vmware/govmomi/eam/simulator" 29 vcsim "github.com/vmware/govmomi/simulator" 30 "github.com/vmware/govmomi/vim25" 31 ) 32 33 var ( 34 client struct { 35 *eam.Client 36 ctx context.Context 37 eam object.EsxAgentManager 38 vim *vim25.Client 39 } 40 ) 41 42 func TestMain(m *testing.M) { 43 client.ctx = context.Background() 44 45 // Define a new model for vC Sim. 46 model := vcsim.VPX() 47 defer model.Remove() 48 49 // Create the resources from the model. 50 if err := model.Create(); err != nil { 51 log.Fatal(err) 52 } 53 54 // Register the EAM endpoint. 55 model.Service.RegisterSDK(simulator.New()) 56 57 // Start the simulator. 58 server := model.Service.NewServer() 59 defer server.Close() 60 61 // Get a vCenter client to the simulator. 62 govmomiClient, err := govmomi.NewClient(client.ctx, server.URL, true) 63 if err != nil { 64 log.Fatal(err) 65 } 66 client.vim = govmomiClient.Client 67 68 // Get an EAM client. 69 client.Client = eam.NewClient(client.vim) 70 71 // Get the EAM root object. 72 client.eam = object.NewEsxAgentManager(client.Client, eam.EsxAgentManager) 73 74 // Run the tests. 75 os.Exit(m.Run()) 76 }