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 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud" |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/acceptance/clients" |
| 10 | "github.com/gophercloud/gophercloud/openstack/identity/v3/endpoints" |
| 11 | "github.com/gophercloud/gophercloud/openstack/identity/v3/services" |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 12 | ) |
| 13 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 14 | func TestEndpointsList(t *testing.T) { |
| 15 | client, err := clients.NewIdentityV3Client() |
| 16 | if err != nil { |
| 17 | t.Fatalf("Unable to obtain an identity client: %v") |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 18 | } |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 19 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 20 | allPages, err := endpoints.List(client, nil).AllPages() |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame] | 21 | if err != nil { |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 22 | t.Fatalf("Unable to list endpoints: %v", err) |
| 23 | } |
| 24 | |
| 25 | allEndpoints, err := endpoints.ExtractEndpoints(allPages) |
| 26 | if err != nil { |
| 27 | t.Fatalf("Unable to extract endpoints: %v", err) |
| 28 | } |
| 29 | |
| 30 | for _, endpoint := range allEndpoints { |
| 31 | PrintEndpoint(t, &endpoint) |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame] | 32 | } |
| 33 | } |
| 34 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 35 | func TestEndpointsNavigateCatalog(t *testing.T) { |
| 36 | client, err := clients.NewIdentityV3Client() |
| 37 | if err != nil { |
| 38 | t.Fatalf("Unable to obtain an identity client: %v") |
Ash Wilson | 4b33eea | 2014-10-22 15:45:45 -0400 | [diff] [blame] | 39 | } |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame] | 40 | |
| 41 | // Discover the service we're interested in. |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 42 | serviceListOpts := services.ListOpts{ |
| 43 | ServiceType: "compute", |
| 44 | } |
Ash Wilson | 3be15e1 | 2014-09-12 15:25:21 -0400 | [diff] [blame] | 45 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 46 | allPages, err := services.List(client, serviceListOpts).AllPages() |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame] | 47 | if err != nil { |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 48 | t.Fatalf("Unable to lookup compute service: %v", err) |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 51 | allServices, err := services.ExtractServices(allPages) |
| 52 | if err != nil { |
| 53 | t.Fatalf("Unable to extract service: %v") |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame] | 54 | } |
| 55 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 56 | if len(allServices) != 1 { |
| 57 | t.Fatalf("Expected one service, got %d", len(allServices)) |
| 58 | } |
| 59 | |
| 60 | computeService := allServices[0] |
| 61 | PrintService(t, &computeService) |
| 62 | |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame] | 63 | // Enumerate the endpoints available for this service. |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 64 | endpointListOpts := endpoints.ListOpts{ |
Ash Wilson | efac18b | 2014-09-10 14:44:42 -0400 | [diff] [blame] | 65 | Availability: gophercloud.AvailabilityPublic, |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 66 | ServiceID: computeService.ID, |
Ash Wilson | 0555c64 | 2014-09-05 16:57:17 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Joe Topjian | 918f573 | 2016-08-15 08:47:08 -0600 | [diff] [blame] | 69 | allPages, err = endpoints.List(client, endpointListOpts).AllPages() |
| 70 | if err != nil { |
| 71 | t.Fatalf("Unable to lookup compute endpoint: %v", err) |
| 72 | } |
| 73 | |
| 74 | allEndpoints, err := endpoints.ExtractEndpoints(allPages) |
| 75 | if err != nil { |
| 76 | t.Fatalf("Unable to extract endpoint: %v") |
| 77 | } |
| 78 | |
| 79 | if len(allEndpoints) != 1 { |
| 80 | t.Fatalf("Expected one endpoint, got %d", len(allEndpoints)) |
| 81 | } |
| 82 | |
| 83 | PrintEndpoint(t, &allEndpoints[0]) |
| 84 | |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 85 | } |