github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/vsphere_storage_profile_test.go (about)

     1  //go:build vsphere || functional || ALL
     2  
     3  /*
     4   * Copyright 2023 VMware, Inc.  All rights reserved.  Licensed under the Apache v2 License.
     5   */
     6  
     7  package govcd
     8  
     9  import (
    10  	"fmt"
    11  	"github.com/kr/pretty"
    12  	. "gopkg.in/check.v1"
    13  	"strings"
    14  )
    15  
    16  func (vcd *TestVCD) Test_GetStorageProfiles(check *C) {
    17  	if !vcd.client.Client.IsSysAdmin {
    18  		check.Skip("this test requires system administrator privileges")
    19  	}
    20  	vcenters, err := vcd.client.GetAllVCenters(nil)
    21  	check.Assert(err, IsNil)
    22  
    23  	check.Assert(len(vcenters) > 0, Equals, true)
    24  
    25  	vc := vcenters[0]
    26  
    27  	if vcd.config.Vsphere.ResourcePoolForVcd1 == "" {
    28  		check.Skip("no resource pool found for this VCD")
    29  	}
    30  
    31  	resourcePool, err := vc.GetResourcePoolByName(vcd.config.Vsphere.ResourcePoolForVcd1)
    32  	check.Assert(err, IsNil)
    33  
    34  	allStorageProfiles, err := vc.GetAllStorageProfiles(resourcePool.ResourcePool.Moref, nil)
    35  	check.Assert(err, IsNil)
    36  
    37  	for i, sp := range allStorageProfiles {
    38  		spById, err := vc.GetStorageProfileById(resourcePool.ResourcePool.Moref, sp.StorageProfile.Moref)
    39  		check.Assert(err, IsNil)
    40  		check.Assert(spById.StorageProfile.Moref, Equals, sp.StorageProfile.Moref)
    41  		check.Assert(spById.StorageProfile.Name, Equals, sp.StorageProfile.Name)
    42  		spByName, err := vc.GetStorageProfileByName(resourcePool.ResourcePool.Moref, sp.StorageProfile.Name)
    43  		if err != nil && strings.Contains(err.Error(), "more than one") {
    44  			fmt.Printf("%s\n", err)
    45  			continue
    46  		}
    47  		check.Assert(err, IsNil)
    48  		check.Assert(spByName.StorageProfile.Moref, Equals, sp.StorageProfile.Moref)
    49  		check.Assert(spByName.StorageProfile.Name, Equals, sp.StorageProfile.Name)
    50  		if testVerbose {
    51  			fmt.Printf("%2d %# v\n", i, pretty.Formatter(sp.StorageProfile))
    52  		}
    53  	}
    54  }