blob: 5c0e774eae8d3b71a98950abbcc5e8a9a884fd97 [file] [log] [blame]
Ash Wilsondd7188d2014-09-05 14:02:42 -04001// +build acceptance
2
3package v3
4
5import (
6 "testing"
7
Ash Wilson0555c642014-09-05 16:57:17 -04008 "github.com/rackspace/gophercloud"
Ash Wilsondd7188d2014-09-05 14:02:42 -04009 endpoints3 "github.com/rackspace/gophercloud/openstack/identity/v3/endpoints"
Ash Wilson0555c642014-09-05 16:57:17 -040010 services3 "github.com/rackspace/gophercloud/openstack/identity/v3/services"
Ash Wilsondd7188d2014-09-05 14:02:42 -040011)
12
13func TestListEndpoints(t *testing.T) {
14 // Create a service client.
15 serviceClient := createAuthenticatedClient(t)
Ash Wilson7083d022014-09-09 14:10:43 -040016 if serviceClient == nil {
17 return
18 }
Ash Wilsondd7188d2014-09-05 14:02:42 -040019
20 // Use the service to list all available endpoints.
Ash Wilson3be15e12014-09-12 15:25:21 -040021 pager := endpoints3.List(serviceClient, endpoints3.ListOpts{})
22 err := pager.EachPage(func(page gophercloud.Page) (bool, error) {
Ash Wilson0555c642014-09-05 16:57:17 -040023 t.Logf("--- Page ---")
24
Ash Wilson3be15e12014-09-12 15:25:21 -040025 endpoints, err := endpoints3.ExtractEndpoints(page)
26 if err != nil {
27 t.Fatalf("Error extracting endpoings: %v", err)
28 }
29
30 for _, endpoint := range endpoints {
Ash Wilson0555c642014-09-05 16:57:17 -040031 t.Logf("Endpoint: %8s %10s %9s %s",
32 endpoint.ID,
Ash Wilsonefac18b2014-09-10 14:44:42 -040033 endpoint.Availability,
Ash Wilson0555c642014-09-05 16:57:17 -040034 endpoint.Name,
35 endpoint.URL)
36 }
37
Ash Wilson3be15e12014-09-12 15:25:21 -040038 return true, nil
Ash Wilson0555c642014-09-05 16:57:17 -040039 })
40 if err != nil {
41 t.Errorf("Unexpected error while iterating endpoint pages: %v", err)
42 }
43}
44
45func TestNavigateCatalog(t *testing.T) {
46 // Create a service client.
47 client := createAuthenticatedClient(t)
48
Ash Wilson3be15e12014-09-12 15:25:21 -040049 var compute *services3.Service
50 var endpoint *endpoints3.Endpoint
51
Ash Wilson0555c642014-09-05 16:57:17 -040052 // Discover the service we're interested in.
Ash Wilson3be15e12014-09-12 15:25:21 -040053 servicePager := services3.List(client, services3.ListOpts{ServiceType: "compute"})
54 err := servicePager.EachPage(func(page gophercloud.Page) (bool, error) {
55 part, err := services3.ExtractServices(page)
56 if err != nil {
57 return false, err
58 }
59 if compute != nil {
60 t.Fatalf("Expected one service, got more than one page")
61 return false, nil
62 }
63 if len(part) != 1 {
64 t.Fatalf("Expected one service, got %d", len(part))
65 return false, nil
66 }
67
68 compute = &part[0]
69 return true, nil
70 })
Ash Wilson0555c642014-09-05 16:57:17 -040071 if err != nil {
Ash Wilson3be15e12014-09-12 15:25:21 -040072 t.Fatalf("Unexpected error iterating pages: %v", err)
Ash Wilson0555c642014-09-05 16:57:17 -040073 }
74
Ash Wilson3be15e12014-09-12 15:25:21 -040075 if compute == nil {
76 t.Fatalf("No compute service found.")
Ash Wilson0555c642014-09-05 16:57:17 -040077 }
78
Ash Wilson0555c642014-09-05 16:57:17 -040079 // Enumerate the endpoints available for this service.
Ash Wilson3be15e12014-09-12 15:25:21 -040080 computePager := endpoints3.List(client, endpoints3.ListOpts{
Ash Wilsonefac18b2014-09-10 14:44:42 -040081 Availability: gophercloud.AvailabilityPublic,
Ash Wilson3be15e12014-09-12 15:25:21 -040082 ServiceID: compute.ID,
83 })
84 err = computePager.EachPage(func(page gophercloud.Page) (bool, error) {
85 part, err := endpoints3.ExtractEndpoints(page)
86 if err != nil {
87 return false, err
88 }
89 if endpoint != nil {
90 t.Fatalf("Expected one endpoint, got more than one page")
91 return false, nil
92 }
93 if len(part) != 1 {
94 t.Fatalf("Expected one endpoint, got %d", len(part))
95 return false, nil
96 }
97
98 endpoint = &part[0]
99 return true, nil
Ash Wilson0555c642014-09-05 16:57:17 -0400100 })
101
Ash Wilson3be15e12014-09-12 15:25:21 -0400102 if endpoint == nil {
103 t.Fatalf("No endpoint found.")
Ash Wilson0555c642014-09-05 16:57:17 -0400104 }
105
Ash Wilson0555c642014-09-05 16:57:17 -0400106 t.Logf("Success. The compute endpoint is at %s.", endpoint.URL)
Ash Wilsondd7188d2014-09-05 14:02:42 -0400107}