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

     1  /*
     2  Copyright (c) 2020 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/google/uuid"
    21  
    22  	"github.com/vmware/govmomi/find"
    23  	"github.com/vmware/govmomi/object"
    24  	"github.com/vmware/govmomi/simulator"
    25  	"github.com/vmware/govmomi/vim25"
    26  )
    27  
    28  func TestOpaqueNetworkEthernetCardBackingInfo(t *testing.T) {
    29  	model := simulator.VPX()
    30  	model.OpaqueNetwork = 1 // Create 1 NSX backed OpaqueNetwork per DC
    31  
    32  	simulator.Test(func(ctx context.Context, c *vim25.Client) {
    33  		finder := find.NewFinder(c)
    34  
    35  		net, err := finder.Network(ctx, "DC0_NSX0")
    36  		if err != nil {
    37  			t.Fatal(err)
    38  		}
    39  
    40  		nsx, ok := net.(*object.OpaqueNetwork)
    41  		if !ok {
    42  			t.Fatalf("network type=%T", net)
    43  		}
    44  
    45  		summary, err := nsx.Summary(ctx)
    46  		if err != nil {
    47  			t.Fatal(err)
    48  		}
    49  
    50  		if net.Reference() != *summary.Network {
    51  			t.Fatal()
    52  		}
    53  
    54  		_, err = uuid.Parse(summary.OpaqueNetworkId)
    55  		if err != nil {
    56  			t.Errorf("parsing %q: %s", summary.OpaqueNetworkId, err)
    57  		}
    58  
    59  		_, err = net.EthernetCardBackingInfo(ctx)
    60  		if err != nil {
    61  			t.Fatal(err)
    62  		}
    63  	}, model)
    64  }