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