Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v3 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame^] | 8 | "github.com/rackspace/gophercloud" |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 9 | endpoints3 "github.com/rackspace/gophercloud/openstack/identity/v3/endpoints" |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame^] | 10 | services3 "github.com/rackspace/gophercloud/openstack/identity/v3/services" |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func TestListEndpoints(t *testing.T) { |
| 14 | // Create a service client. |
| 15 | serviceClient := createAuthenticatedClient(t) |
| 16 | |
| 17 | // Use the service to list all available endpoints. |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame^] | 18 | results, err := endpoints3.List(serviceClient, endpoints3.ListOpts{}) |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 19 | if err != nil { |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame^] | 20 | t.Fatalf("Unexpected error while listing endpoints: %v", err) |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 21 | } |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame^] | 22 | |
| 23 | err = gophercloud.EachPage(results, func(page gophercloud.Collection) bool { |
| 24 | t.Logf("--- Page ---") |
| 25 | |
| 26 | for _, endpoint := range endpoints3.AsEndpoints(page) { |
| 27 | t.Logf("Endpoint: %8s %10s %9s %s", |
| 28 | endpoint.ID, |
| 29 | endpoint.Interface, |
| 30 | endpoint.Name, |
| 31 | endpoint.URL) |
| 32 | } |
| 33 | |
| 34 | return true |
| 35 | }) |
| 36 | if err != nil { |
| 37 | t.Errorf("Unexpected error while iterating endpoint pages: %v", err) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func TestNavigateCatalog(t *testing.T) { |
| 42 | // Create a service client. |
| 43 | client := createAuthenticatedClient(t) |
| 44 | |
| 45 | // Discover the service we're interested in. |
| 46 | computeResults, err := services3.List(client, services3.ListOpts{ServiceType: "compute"}) |
| 47 | if err != nil { |
| 48 | t.Fatalf("Unexpected error while listing services: %v", err) |
| 49 | } |
| 50 | |
| 51 | allServices, err := gophercloud.AllPages(computeResults) |
| 52 | if err != nil { |
| 53 | t.Fatalf("Unexpected error while traversing service results: %v", err) |
| 54 | } |
| 55 | |
| 56 | computeServices := services3.AsServices(allServices) |
| 57 | |
| 58 | if len(computeServices) != 1 { |
| 59 | t.Logf("%d compute services are available at this endpoint.", len(computeServices)) |
| 60 | return |
| 61 | } |
| 62 | computeService := computeServices[0] |
| 63 | |
| 64 | // Enumerate the endpoints available for this service. |
| 65 | endpointResults, err := endpoints3.List(client, endpoints3.ListOpts{ |
| 66 | Interface: endpoints3.InterfacePublic, |
| 67 | ServiceID: computeService.ID, |
| 68 | }) |
| 69 | |
| 70 | allEndpoints, err := gophercloud.AllPages(endpointResults) |
| 71 | if err != nil { |
| 72 | t.Fatalf("Unexpected error while listing endpoints: %v", err) |
| 73 | } |
| 74 | |
| 75 | endpoints := endpoints3.AsEndpoints(allEndpoints) |
| 76 | |
| 77 | if len(endpoints) != 1 { |
| 78 | t.Logf("%d endpoints are available for the service %v.", len(endpoints), computeService.Name) |
| 79 | return |
| 80 | } |
| 81 | |
| 82 | endpoint := endpoints[0] |
| 83 | t.Logf("Success. The compute endpoint is at %s.", endpoint.URL) |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 84 | } |