github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/extensions/schedulerstats/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/huaweicloud/golangsdk/openstack/blockstorage/extensions/schedulerstats"
     7  	"github.com/huaweicloud/golangsdk/pagination"
     8  	"github.com/huaweicloud/golangsdk/testhelper"
     9  	"github.com/huaweicloud/golangsdk/testhelper/client"
    10  )
    11  
    12  func TestListStoragePoolsDetail(t *testing.T) {
    13  	testhelper.SetupHTTP()
    14  	defer testhelper.TeardownHTTP()
    15  	HandleStoragePoolsListSuccessfully(t)
    16  
    17  	pages := 0
    18  	err := schedulerstats.List(client.ServiceClient(), schedulerstats.ListOpts{Detail: true}).EachPage(func(page pagination.Page) (bool, error) {
    19  		pages++
    20  
    21  		actual, err := schedulerstats.ExtractStoragePools(page)
    22  		testhelper.AssertNoErr(t, err)
    23  
    24  		if len(actual) != 2 {
    25  			t.Fatalf("Expected 2 backends, got %d", len(actual))
    26  		}
    27  		testhelper.CheckDeepEquals(t, StoragePoolFake1, actual[0])
    28  		testhelper.CheckDeepEquals(t, StoragePoolFake2, actual[1])
    29  
    30  		return true, nil
    31  	})
    32  
    33  	testhelper.AssertNoErr(t, err)
    34  
    35  	if pages != 1 {
    36  		t.Errorf("Expected 1 page, saw %d", pages)
    37  	}
    38  }