github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/extensions/services/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk/openstack/blockstorage/extensions/services" 7 "github.com/huaweicloud/golangsdk/pagination" 8 "github.com/huaweicloud/golangsdk/testhelper" 9 "github.com/huaweicloud/golangsdk/testhelper/client" 10 ) 11 12 func TestListServices(t *testing.T) { 13 testhelper.SetupHTTP() 14 defer testhelper.TeardownHTTP() 15 HandleListSuccessfully(t) 16 17 pages := 0 18 err := services.List(client.ServiceClient(), services.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { 19 pages++ 20 21 actual, err := services.ExtractServices(page) 22 if err != nil { 23 return false, err 24 } 25 26 if len(actual) != 3 { 27 t.Fatalf("Expected 3 services, got %d", len(actual)) 28 } 29 testhelper.CheckDeepEquals(t, FirstFakeService, actual[0]) 30 testhelper.CheckDeepEquals(t, SecondFakeService, actual[1]) 31 testhelper.CheckDeepEquals(t, ThirdFakeService, actual[2]) 32 33 return true, nil 34 }) 35 36 testhelper.AssertNoErr(t, err) 37 38 if pages != 1 { 39 t.Errorf("Expected 1 page, saw %d", pages) 40 } 41 }