github.com/vmware/govmomi@v0.37.1/object/host_system_test.go (about)

     1  /*
     2  Copyright (c) 2019 VMware, Inc. All Rights Reserved.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6      http://www.apache.org/licenses/LICENSE-2.0
     7  Unless required by applicable law or agreed to in writing, software
     8  distributed under the License is distributed on an "AS IS" BASIS,
     9  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    10  See the License for the specific language governing permissions and
    11  limitations under the License.
    12  */
    13  
    14  package object_test
    15  
    16  import (
    17  	"context"
    18  	"testing"
    19  
    20  	"github.com/vmware/govmomi/find"
    21  	"github.com/vmware/govmomi/simulator"
    22  	"github.com/vmware/govmomi/vim25"
    23  )
    24  
    25  func TestHostSystemManagementIPs(t *testing.T) {
    26  	simulator.Test(func(ctx context.Context, c *vim25.Client) {
    27  		host, err := find.NewFinder(c).HostSystem(ctx, "DC0_C0_H0")
    28  		if err != nil {
    29  			t.Fatal(err)
    30  		}
    31  
    32  		ips, err := host.ManagementIPs(ctx)
    33  		if err != nil {
    34  			t.Fatal(err)
    35  		}
    36  		if len(ips) != 1 {
    37  			t.Fatal("no mgmt ip found")
    38  		}
    39  		if ips[0].String() != "127.0.0.1" {
    40  			t.Fatalf("Expected management ip %s, got %s", "127.0.0.1", ips[0].String())
    41  		}
    42  
    43  		// These fields can be nil while ESX is being upgraded
    44  		hs := simulator.Map.Get(host.Reference()).(*simulator.HostSystem)
    45  		tests := []func(){
    46  			func() { hs.Config.VirtualNicManagerInfo = nil },
    47  			func() { hs.Config = nil },
    48  		}
    49  
    50  		for _, f := range tests {
    51  			f()
    52  			ips, err = host.ManagementIPs(ctx)
    53  			if err != nil {
    54  				t.Fatal(err)
    55  			}
    56  			if len(ips) != 0 {
    57  				t.Fatal("expected zero ips")
    58  			}
    59  		}
    60  	})
    61  }