Ash Wilson | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v3 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Ash Wilson | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 8 | services3 "github.com/rackspace/gophercloud/openstack/identity/v3/services" |
Ash Wilson | 387d1bd | 2014-09-16 11:43:24 -0400 | [diff] [blame^] | 9 | "github.com/rackspace/gophercloud/pagination" |
Ash Wilson | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | func TestListServices(t *testing.T) { |
Ash Wilson | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 13 | // Create a service client. |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 14 | serviceClient := createAuthenticatedClient(t) |
Ash Wilson | 7083d02 | 2014-09-09 14:10:43 -0400 | [diff] [blame] | 15 | if serviceClient == nil { |
| 16 | return |
| 17 | } |
Ash Wilson | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 18 | |
Ash Wilson | 2c0e45b | 2014-09-09 14:52:42 -0400 | [diff] [blame] | 19 | // Use the client to list all available services. |
Ash Wilson | 3be15e1 | 2014-09-12 15:25:21 -0400 | [diff] [blame] | 20 | pager := services3.List(serviceClient, services3.ListOpts{}) |
Ash Wilson | 387d1bd | 2014-09-16 11:43:24 -0400 | [diff] [blame^] | 21 | err := pager.EachPage(func(page pagination.Page) (bool, error) { |
Ash Wilson | 3be15e1 | 2014-09-12 15:25:21 -0400 | [diff] [blame] | 22 | parts, err := services3.ExtractServices(page) |
| 23 | if err != nil { |
| 24 | return false, err |
| 25 | } |
Ash Wilson | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 26 | |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 27 | t.Logf("--- Page ---") |
Ash Wilson | 3be15e1 | 2014-09-12 15:25:21 -0400 | [diff] [blame] | 28 | for _, service := range parts { |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 29 | t.Logf("Service: %32s %15s %10s %s", service.ID, service.Type, service.Name, *service.Description) |
| 30 | } |
Ash Wilson | 3be15e1 | 2014-09-12 15:25:21 -0400 | [diff] [blame] | 31 | return true, nil |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 32 | }) |
| 33 | if err != nil { |
| 34 | t.Errorf("Unexpected error traversing pages: %v", err) |
Ash Wilson | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 35 | } |
| 36 | } |