Identity Acceptance Test Cleanup (#49)
diff --git a/acceptance/openstack/identity/v3/endpoint_test.go b/acceptance/openstack/identity/v3/endpoint_test.go
index f575649..6a52f26 100644
--- a/acceptance/openstack/identity/v3/endpoint_test.go
+++ b/acceptance/openstack/identity/v3/endpoint_test.go
@@ -6,106 +6,80 @@
"testing"
"github.com/gophercloud/gophercloud"
- endpoints3 "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints"
- services3 "github.com/gophercloud/gophercloud/openstack/identity/v3/services"
- "github.com/gophercloud/gophercloud/pagination"
+ "github.com/gophercloud/gophercloud/acceptance/clients"
+ "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints"
+ "github.com/gophercloud/gophercloud/openstack/identity/v3/services"
)
-func TestListEndpoints(t *testing.T) {
- // Create a service client.
- serviceClient := createAuthenticatedClient(t)
- if serviceClient == nil {
- return
+func TestEndpointsList(t *testing.T) {
+ client, err := clients.NewIdentityV3Client()
+ if err != nil {
+ t.Fatalf("Unable to obtain an identity client: %v")
}
- // Use the service to list all available endpoints.
- pager := endpoints3.List(serviceClient, endpoints3.ListOpts{})
- err := pager.EachPage(func(page pagination.Page) (bool, error) {
- t.Logf("--- 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,
- endpoint.Name,
- endpoint.URL)
- }
-
- return true, nil
- })
+ allPages, err := endpoints.List(client, nil).AllPages()
if err != nil {
- t.Errorf("Unexpected error while iterating endpoint pages: %v", err)
+ t.Fatalf("Unable to list endpoints: %v", err)
+ }
+
+ allEndpoints, err := endpoints.ExtractEndpoints(allPages)
+ if err != nil {
+ t.Fatalf("Unable to extract endpoints: %v", err)
+ }
+
+ for _, endpoint := range allEndpoints {
+ PrintEndpoint(t, &endpoint)
}
}
-func TestNavigateCatalog(t *testing.T) {
- // Create a service client.
- client := createAuthenticatedClient(t)
- if client == nil {
- return
+func TestEndpointsNavigateCatalog(t *testing.T) {
+ client, err := clients.NewIdentityV3Client()
+ if err != nil {
+ t.Fatalf("Unable to obtain an identity client: %v")
}
- var compute *services3.Service
- var endpoint *endpoints3.Endpoint
-
// Discover the service we're interested in.
- servicePager := services3.List(client, services3.ListOpts{ServiceType: "compute"})
- err := servicePager.EachPage(func(page pagination.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
- }
+ serviceListOpts := services.ListOpts{
+ ServiceType: "compute",
+ }
- compute = &part[0]
- return true, nil
- })
+ allPages, err := services.List(client, serviceListOpts).AllPages()
if err != nil {
- t.Fatalf("Unexpected error iterating pages: %v", err)
+ t.Fatalf("Unable to lookup compute service: %v", err)
}
- if compute == nil {
- t.Fatalf("No compute service found.")
+ allServices, err := services.ExtractServices(allPages)
+ if err != nil {
+ t.Fatalf("Unable to extract service: %v")
}
+ if len(allServices) != 1 {
+ t.Fatalf("Expected one service, got %d", len(allServices))
+ }
+
+ computeService := allServices[0]
+ PrintService(t, &computeService)
+
// Enumerate the endpoints available for this service.
- computePager := endpoints3.List(client, endpoints3.ListOpts{
+ endpointListOpts := endpoints.ListOpts{
Availability: gophercloud.AvailabilityPublic,
- ServiceID: compute.ID,
- })
- err = computePager.EachPage(func(page pagination.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
- })
-
- if endpoint == nil {
- t.Fatalf("No endpoint found.")
+ ServiceID: computeService.ID,
}
- t.Logf("Success. The compute endpoint is at %s.", endpoint.URL)
+ allPages, err = endpoints.List(client, endpointListOpts).AllPages()
+ if err != nil {
+ t.Fatalf("Unable to lookup compute endpoint: %v", err)
+ }
+
+ allEndpoints, err := endpoints.ExtractEndpoints(allPages)
+ if err != nil {
+ t.Fatalf("Unable to extract endpoint: %v")
+ }
+
+ if len(allEndpoints) != 1 {
+ t.Fatalf("Expected one endpoint, got %d", len(allEndpoints))
+ }
+
+ PrintEndpoint(t, &allEndpoints[0])
+
}