blob: 4f1d24cc48fd088868bce0f9b1caa0bb4113a37d [file] [log] [blame]
Ash Wilsondd7188d2014-09-05 14:02:42 -04001// +build acceptance
2
3package v3
4
5import (
6 "testing"
7
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02008 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02009 "gerrit.mcp.mirantis.net/debian/gophercloud.git/acceptance/clients"
10 "gerrit.mcp.mirantis.net/debian/gophercloud.git/acceptance/tools"
11 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/identity/v3/endpoints"
12 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/identity/v3/services"
Ash Wilsondd7188d2014-09-05 14:02:42 -040013)
14
Joe Topjian918f5732016-08-15 08:47:08 -060015func TestEndpointsList(t *testing.T) {
16 client, err := clients.NewIdentityV3Client()
17 if err != nil {
18 t.Fatalf("Unable to obtain an identity client: %v")
Ash Wilson7083d022014-09-09 14:10:43 -040019 }
Ash Wilsondd7188d2014-09-05 14:02:42 -040020
Joe Topjian918f5732016-08-15 08:47:08 -060021 allPages, err := endpoints.List(client, nil).AllPages()
Ash Wilson0555c642014-09-05 16:57:17 -040022 if err != nil {
Joe Topjian918f5732016-08-15 08:47:08 -060023 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 Topjian66a046c2017-01-19 22:07:26 -070032 tools.PrintResource(t, endpoint)
Ash Wilson0555c642014-09-05 16:57:17 -040033 }
34}
35
Joe Topjian918f5732016-08-15 08:47:08 -060036func TestEndpointsNavigateCatalog(t *testing.T) {
37 client, err := clients.NewIdentityV3Client()
38 if err != nil {
39 t.Fatalf("Unable to obtain an identity client: %v")
Ash Wilson4b33eea2014-10-22 15:45:45 -040040 }
Ash Wilson0555c642014-09-05 16:57:17 -040041
42 // Discover the service we're interested in.
Joe Topjian918f5732016-08-15 08:47:08 -060043 serviceListOpts := services.ListOpts{
44 ServiceType: "compute",
45 }
Ash Wilson3be15e12014-09-12 15:25:21 -040046
Joe Topjian918f5732016-08-15 08:47:08 -060047 allPages, err := services.List(client, serviceListOpts).AllPages()
Ash Wilson0555c642014-09-05 16:57:17 -040048 if err != nil {
Joe Topjian918f5732016-08-15 08:47:08 -060049 t.Fatalf("Unable to lookup compute service: %v", err)
Ash Wilson0555c642014-09-05 16:57:17 -040050 }
51
Joe Topjian918f5732016-08-15 08:47:08 -060052 allServices, err := services.ExtractServices(allPages)
53 if err != nil {
54 t.Fatalf("Unable to extract service: %v")
Ash Wilson0555c642014-09-05 16:57:17 -040055 }
56
Joe Topjian918f5732016-08-15 08:47:08 -060057 if len(allServices) != 1 {
58 t.Fatalf("Expected one service, got %d", len(allServices))
59 }
60
61 computeService := allServices[0]
Joe Topjian66a046c2017-01-19 22:07:26 -070062 tools.PrintResource(t, computeService)
Joe Topjian918f5732016-08-15 08:47:08 -060063
Ash Wilson0555c642014-09-05 16:57:17 -040064 // Enumerate the endpoints available for this service.
Joe Topjian918f5732016-08-15 08:47:08 -060065 endpointListOpts := endpoints.ListOpts{
Ash Wilsonefac18b2014-09-10 14:44:42 -040066 Availability: gophercloud.AvailabilityPublic,
Joe Topjian918f5732016-08-15 08:47:08 -060067 ServiceID: computeService.ID,
Ash Wilson0555c642014-09-05 16:57:17 -040068 }
69
Joe Topjian918f5732016-08-15 08:47:08 -060070 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 Topjian66a046c2017-01-19 22:07:26 -070084 tools.PrintResource(t, allEndpoints[0])
Joe Topjian918f5732016-08-15 08:47:08 -060085
Ash Wilsondd7188d2014-09-05 14:02:42 -040086}