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

     1  //go:build query || 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  	"github.com/vmware/go-vcloud-director/v2/types/v56"
    11  	. "gopkg.in/check.v1"
    12  )
    13  
    14  func (vcd *TestVCD) Test_CheckCumulativeQuery(check *C) {
    15  	vcd.skipIfNotSysAdmin(check)
    16  	pvdcs, err := vcd.client.QueryProviderVdcs()
    17  	check.Assert(err, IsNil)
    18  	var storageProfileMap = make(map[string]bool)
    19  
    20  	for _, pvdcRec := range pvdcs {
    21  		pvdc, err := vcd.client.GetProviderVdcByHref(pvdcRec.HREF)
    22  		check.Assert(err, IsNil)
    23  		for _, sp := range pvdc.ProviderVdc.StorageProfiles.ProviderVdcStorageProfile {
    24  			storageProfileMap[sp.Name] = true
    25  		}
    26  	}
    27  	if len(storageProfileMap) < 2 {
    28  		check.Skip("not enough storage profiles found for this test")
    29  	}
    30  
    31  	checkQuery := func(pageSize string) {
    32  		var foundStorageProfileMap = make(map[string]bool)
    33  		results, err := vcd.client.Client.cumulativeQuery(types.QtProviderVdcStorageProfile, nil, map[string]string{
    34  			"type":     types.QtProviderVdcStorageProfile,
    35  			"pageSize": pageSize,
    36  		})
    37  
    38  		check.Assert(err, IsNil)
    39  		check.Assert(results, NotNil)
    40  		check.Assert(results.Results, NotNil)
    41  		check.Assert(results.Results.ProviderVdcStorageProfileRecord, NotNil)
    42  
    43  		// Removing duplicates from results
    44  		for _, sp := range results.Results.ProviderVdcStorageProfileRecord {
    45  			foundStorageProfileMap[sp.Name] = true
    46  		}
    47  		check.Assert(len(foundStorageProfileMap), Equals, len(storageProfileMap))
    48  	}
    49  	checkQuery("1")
    50  	checkQuery("2")
    51  	checkQuery("25")
    52  }