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