Bring acceptance tests up to date.
diff --git a/acceptance/openstack/identity/v3/endpoint_test.go b/acceptance/openstack/identity/v3/endpoint_test.go
index 14783b5..5c0e774 100644
--- a/acceptance/openstack/identity/v3/endpoint_test.go
+++ b/acceptance/openstack/identity/v3/endpoint_test.go
@@ -18,15 +18,16 @@
}
// Use the service to list all available endpoints.
- results, err := endpoints3.List(serviceClient, endpoints3.ListOpts{})
- if err != nil {
- t.Fatalf("Unexpected error while listing endpoints: %v", err)
- }
-
- err = gophercloud.EachPage(results, func(page gophercloud.Collection) bool {
+ pager := endpoints3.List(serviceClient, endpoints3.ListOpts{})
+ err := pager.EachPage(func(page gophercloud.Page) (bool, error) {
t.Logf("--- Page ---")
- for _, endpoint := range endpoints3.AsEndpoints(page) {
+ endpoints, err := endpoints3.ExtractEndpoints(page)
+ if err != nil {
+ t.Fatalf("Error extracting endpoings: %v", err)
+ }
+
+ for _, endpoint := range endpoints {
t.Logf("Endpoint: %8s %10s %9s %s",
endpoint.ID,
endpoint.Availability,
@@ -34,7 +35,7 @@
endpoint.URL)
}
- return true
+ return true, nil
})
if err != nil {
t.Errorf("Unexpected error while iterating endpoint pages: %v", err)
@@ -45,43 +46,62 @@
// Create a service client.
client := createAuthenticatedClient(t)
+ var compute *services3.Service
+ var endpoint *endpoints3.Endpoint
+
// Discover the service we're interested in.
- computeResults, err := services3.List(client, services3.ListOpts{ServiceType: "compute"})
+ servicePager := services3.List(client, services3.ListOpts{ServiceType: "compute"})
+ err := servicePager.EachPage(func(page gophercloud.Page) (bool, error) {
+ part, err := services3.ExtractServices(page)
+ if err != nil {
+ return false, err
+ }
+ if compute != nil {
+ t.Fatalf("Expected one service, got more than one page")
+ return false, nil
+ }
+ if len(part) != 1 {
+ t.Fatalf("Expected one service, got %d", len(part))
+ return false, nil
+ }
+
+ compute = &part[0]
+ return true, nil
+ })
if err != nil {
- t.Fatalf("Unexpected error while listing services: %v", err)
+ t.Fatalf("Unexpected error iterating pages: %v", err)
}
- allServices, err := gophercloud.AllPages(computeResults)
- if err != nil {
- t.Fatalf("Unexpected error while traversing service results: %v", err)
+ if compute == nil {
+ t.Fatalf("No compute service found.")
}
- computeServices := services3.AsServices(allServices)
-
- if len(computeServices) != 1 {
- t.Logf("%d compute services are available at this endpoint.", len(computeServices))
- return
- }
- computeService := computeServices[0]
-
// Enumerate the endpoints available for this service.
- endpointResults, err := endpoints3.List(client, endpoints3.ListOpts{
+ computePager := endpoints3.List(client, endpoints3.ListOpts{
Availability: gophercloud.AvailabilityPublic,
- ServiceID: computeService.ID,
+ ServiceID: compute.ID,
+ })
+ err = computePager.EachPage(func(page gophercloud.Page) (bool, error) {
+ part, err := endpoints3.ExtractEndpoints(page)
+ if err != nil {
+ return false, err
+ }
+ if endpoint != nil {
+ t.Fatalf("Expected one endpoint, got more than one page")
+ return false, nil
+ }
+ if len(part) != 1 {
+ t.Fatalf("Expected one endpoint, got %d", len(part))
+ return false, nil
+ }
+
+ endpoint = &part[0]
+ return true, nil
})
- allEndpoints, err := gophercloud.AllPages(endpointResults)
- if err != nil {
- t.Fatalf("Unexpected error while listing endpoints: %v", err)
+ if endpoint == nil {
+ t.Fatalf("No endpoint found.")
}
- endpoints := endpoints3.AsEndpoints(allEndpoints)
-
- if len(endpoints) != 1 {
- t.Logf("%d endpoints are available for the service %v.", len(endpoints), computeService.Name)
- return
- }
-
- endpoint := endpoints[0]
t.Logf("Success. The compute endpoint is at %s.", endpoint.URL)
}
diff --git a/acceptance/openstack/identity/v3/service_test.go b/acceptance/openstack/identity/v3/service_test.go
index 00375e2..11f039d 100644
--- a/acceptance/openstack/identity/v3/service_test.go
+++ b/acceptance/openstack/identity/v3/service_test.go
@@ -17,17 +17,18 @@
}
// Use the client to list all available services.
- results, err := services3.List(serviceClient, services3.ListOpts{})
- if err != nil {
- t.Fatalf("Unable to list services: %v", err)
- }
+ pager := services3.List(serviceClient, services3.ListOpts{})
+ err := pager.EachPage(func(page gophercloud.Page) (bool, error) {
+ parts, err := services3.ExtractServices(page)
+ if err != nil {
+ return false, err
+ }
- err = gophercloud.EachPage(results, func(page gophercloud.Collection) bool {
t.Logf("--- Page ---")
- for _, service := range services3.AsServices(page) {
+ for _, service := range parts {
t.Logf("Service: %32s %15s %10s %s", service.ID, service.Type, service.Name, *service.Description)
}
- return true
+ return true, nil
})
if err != nil {
t.Errorf("Unexpected error traversing pages: %v", err)