blob: 6a52f26fce2de5b591f1ed1af452d6d035ab9abe [file] [log] [blame]
Ash Wilsondd7188d2014-09-05 14:02:42 -04001// +build acceptance
2
3package v3
4
5import (
6 "testing"
7
Jon Perritt27249f42016-02-18 10:35:59 -06008 "github.com/gophercloud/gophercloud"
Joe Topjian918f5732016-08-15 08:47:08 -06009 "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 Wilsondd7188d2014-09-05 14:02:42 -040012)
13
Joe Topjian918f5732016-08-15 08:47:08 -060014func TestEndpointsList(t *testing.T) {
15 client, err := clients.NewIdentityV3Client()
16 if err != nil {
17 t.Fatalf("Unable to obtain an identity client: %v")
Ash Wilson7083d022014-09-09 14:10:43 -040018 }
Ash Wilsondd7188d2014-09-05 14:02:42 -040019
Joe Topjian918f5732016-08-15 08:47:08 -060020 allPages, err := endpoints.List(client, nil).AllPages()
Ash Wilson0555c642014-09-05 16:57:17 -040021 if err != nil {
Joe Topjian918f5732016-08-15 08:47:08 -060022 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 Wilson0555c642014-09-05 16:57:17 -040032 }
33}
34
Joe Topjian918f5732016-08-15 08:47:08 -060035func TestEndpointsNavigateCatalog(t *testing.T) {
36 client, err := clients.NewIdentityV3Client()
37 if err != nil {
38 t.Fatalf("Unable to obtain an identity client: %v")
Ash Wilson4b33eea2014-10-22 15:45:45 -040039 }
Ash Wilson0555c642014-09-05 16:57:17 -040040
41 // Discover the service we're interested in.
Joe Topjian918f5732016-08-15 08:47:08 -060042 serviceListOpts := services.ListOpts{
43 ServiceType: "compute",
44 }
Ash Wilson3be15e12014-09-12 15:25:21 -040045
Joe Topjian918f5732016-08-15 08:47:08 -060046 allPages, err := services.List(client, serviceListOpts).AllPages()
Ash Wilson0555c642014-09-05 16:57:17 -040047 if err != nil {
Joe Topjian918f5732016-08-15 08:47:08 -060048 t.Fatalf("Unable to lookup compute service: %v", err)
Ash Wilson0555c642014-09-05 16:57:17 -040049 }
50
Joe Topjian918f5732016-08-15 08:47:08 -060051 allServices, err := services.ExtractServices(allPages)
52 if err != nil {
53 t.Fatalf("Unable to extract service: %v")
Ash Wilson0555c642014-09-05 16:57:17 -040054 }
55
Joe Topjian918f5732016-08-15 08:47:08 -060056 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 Wilson0555c642014-09-05 16:57:17 -040063 // Enumerate the endpoints available for this service.
Joe Topjian918f5732016-08-15 08:47:08 -060064 endpointListOpts := endpoints.ListOpts{
Ash Wilsonefac18b2014-09-10 14:44:42 -040065 Availability: gophercloud.AvailabilityPublic,
Joe Topjian918f5732016-08-15 08:47:08 -060066 ServiceID: computeService.ID,
Ash Wilson0555c642014-09-05 16:57:17 -040067 }
68
Joe Topjian918f5732016-08-15 08:47:08 -060069 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 Wilsondd7188d2014-09-05 14:02:42 -040085}