github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/services/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk/openstack/compute/v2/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()).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) != 4 { 27 t.Fatalf("Expected 4 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 testhelper.CheckDeepEquals(t, FourthFakeService, actual[3]) 33 34 return true, nil 35 }) 36 37 testhelper.AssertNoErr(t, err) 38 39 if pages != 1 { 40 t.Errorf("Expected 1 page, saw %d", pages) 41 } 42 }