blob: 082bd11e742fa92c8c5f4fcab27daf97328f6b70 [file] [log] [blame]
Ash Wilsonfd794d52014-09-03 14:30:43 -04001// +build acceptance
2
3package v3
4
5import (
6 "testing"
7
Ash Wilsonfd794d52014-09-03 14:30:43 -04008 services3 "github.com/rackspace/gophercloud/openstack/identity/v3/services"
Ash Wilson387d1bd2014-09-16 11:43:24 -04009 "github.com/rackspace/gophercloud/pagination"
Ash Wilsonfd794d52014-09-03 14:30:43 -040010)
11
12func TestListServices(t *testing.T) {
Ash Wilsonfd794d52014-09-03 14:30:43 -040013 // Create a service client.
Ash Wilsondd7188d2014-09-05 14:02:42 -040014 serviceClient := createAuthenticatedClient(t)
Ash Wilson7083d022014-09-09 14:10:43 -040015 if serviceClient == nil {
16 return
17 }
Ash Wilsonfd794d52014-09-03 14:30:43 -040018
Ash Wilson2c0e45b2014-09-09 14:52:42 -040019 // Use the client to list all available services.
Ash Wilson3be15e12014-09-12 15:25:21 -040020 pager := services3.List(serviceClient, services3.ListOpts{})
Ash Wilson387d1bd2014-09-16 11:43:24 -040021 err := pager.EachPage(func(page pagination.Page) (bool, error) {
Ash Wilson3be15e12014-09-12 15:25:21 -040022 parts, err := services3.ExtractServices(page)
23 if err != nil {
24 return false, err
25 }
Ash Wilsonfd794d52014-09-03 14:30:43 -040026
Ash Wilsondd7188d2014-09-05 14:02:42 -040027 t.Logf("--- Page ---")
Ash Wilson3be15e12014-09-12 15:25:21 -040028 for _, service := range parts {
Ash Wilsondd7188d2014-09-05 14:02:42 -040029 t.Logf("Service: %32s %15s %10s %s", service.ID, service.Type, service.Name, *service.Description)
30 }
Ash Wilson3be15e12014-09-12 15:25:21 -040031 return true, nil
Ash Wilsondd7188d2014-09-05 14:02:42 -040032 })
33 if err != nil {
34 t.Errorf("Unexpected error traversing pages: %v", err)
Ash Wilsonfd794d52014-09-03 14:30:43 -040035 }
36}