github.com/vmware/govmomi@v0.37.2/object/host_config_manager_test.go (about)

     1  /*
     2  Copyright (c) 2019 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  	"reflect"
    22  	"testing"
    23  
    24  	"github.com/vmware/govmomi/object"
    25  	"github.com/vmware/govmomi/simulator"
    26  	"github.com/vmware/govmomi/vim25"
    27  )
    28  
    29  func TestHostConfigManager(t *testing.T) {
    30  	simulator.Test(func(ctx context.Context, c *vim25.Client) {
    31  		obj := simulator.Map.Any("HostSystem").(*simulator.HostSystem)
    32  		host := object.NewHostSystem(c, obj.Self)
    33  
    34  		m := host.ConfigManager()
    35  		// All should succeed
    36  		funcs := []string{
    37  			"DatastoreSystem",
    38  			"NetworkSystem",
    39  			"FirewallSystem",
    40  			"StorageSystem",
    41  			"VirtualNicManager",
    42  			"VsanSystem",
    43  			"VsanInternalSystem",
    44  			"AccountManager",
    45  			"OptionManager",
    46  			"ServiceSystem",
    47  			"CertificateManager",
    48  			"DateTimeSystem",
    49  		}
    50  
    51  		rm := reflect.ValueOf(m)
    52  		rctx := reflect.ValueOf(ctx)
    53  
    54  		for _, name := range funcs {
    55  			method := rm.MethodByName(name)
    56  			ret := method.Call([]reflect.Value{rctx})
    57  			err := ret[1]
    58  			if !err.IsNil() {
    59  				t.Errorf("%s: %s", name, err.Interface().(error))
    60  			}
    61  		}
    62  
    63  		// Force some errors
    64  
    65  		obj.ConfigManager.NetworkSystem = nil
    66  
    67  		_, err := host.ConfigManager().NetworkSystem(ctx)
    68  		if err == nil {
    69  			t.Error("expected error")
    70  		}
    71  
    72  		obj.ConfigManager.VsanSystem = nil
    73  		_, err = host.ConfigManager().VsanSystem(ctx)
    74  		if err != object.ErrNotSupported {
    75  			t.Errorf("expected %s", object.ErrNotSupported)
    76  		}
    77  	})
    78  }