github.com/vmware/govmomi@v0.51.0/object/host_config_manager_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 object_test
     6  
     7  import (
     8  	"context"
     9  	"reflect"
    10  	"testing"
    11  
    12  	"github.com/vmware/govmomi/object"
    13  	"github.com/vmware/govmomi/simulator"
    14  	"github.com/vmware/govmomi/vim25"
    15  )
    16  
    17  func TestHostConfigManager(t *testing.T) {
    18  	simulator.Test(func(ctx context.Context, c *vim25.Client) {
    19  		obj := simulator.Map(ctx).Any("HostSystem").(*simulator.HostSystem)
    20  		host := object.NewHostSystem(c, obj.Self)
    21  
    22  		m := host.ConfigManager()
    23  		// All should succeed
    24  		funcs := []string{
    25  			"DatastoreSystem",
    26  			"NetworkSystem",
    27  			"FirewallSystem",
    28  			"StorageSystem",
    29  			"VirtualNicManager",
    30  			"VsanSystem",
    31  			"VsanInternalSystem",
    32  			"AccountManager",
    33  			"OptionManager",
    34  			"ServiceSystem",
    35  			"CertificateManager",
    36  			"DateTimeSystem",
    37  		}
    38  
    39  		rm := reflect.ValueOf(m)
    40  		rctx := reflect.ValueOf(ctx)
    41  
    42  		for _, name := range funcs {
    43  			method := rm.MethodByName(name)
    44  			ret := method.Call([]reflect.Value{rctx})
    45  			err := ret[1]
    46  			if !err.IsNil() {
    47  				t.Errorf("%s: %s", name, err.Interface().(error))
    48  			}
    49  		}
    50  
    51  		// Force some errors
    52  
    53  		obj.ConfigManager.NetworkSystem = nil
    54  
    55  		_, err := host.ConfigManager().NetworkSystem(ctx)
    56  		if err == nil {
    57  			t.Error("expected error")
    58  		}
    59  
    60  		obj.ConfigManager.VsanSystem = nil
    61  		_, err = host.ConfigManager().VsanSystem(ctx)
    62  		if err != object.ErrNotSupported {
    63  			t.Errorf("expected %s", object.ErrNotSupported)
    64  		}
    65  	})
    66  }