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 | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud" |
Ash Wilson | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 9 | services3 "github.com/rackspace/gophercloud/openstack/identity/v3/services" |
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 | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 20 | results, err := services3.List(serviceClient, services3.ListOpts{}) |
| 21 | if err != nil { |
Ash Wilson | 2c0e45b | 2014-09-09 14:52:42 -0400 | [diff] [blame^] | 22 | t.Fatalf("Unable to list services: %v", err) |
Ash Wilson | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 23 | } |
| 24 | |
Ash Wilson | dd7188d | 2014-09-05 14:02:42 -0400 | [diff] [blame] | 25 | err = gophercloud.EachPage(results, func(page gophercloud.Collection) bool { |
| 26 | t.Logf("--- Page ---") |
| 27 | for _, service := range services3.AsServices(page) { |
| 28 | t.Logf("Service: %32s %15s %10s %s", service.ID, service.Type, service.Name, *service.Description) |
| 29 | } |
| 30 | return true |
| 31 | }) |
| 32 | if err != nil { |
| 33 | t.Errorf("Unexpected error traversing pages: %v", err) |
Ash Wilson | fd794d5 | 2014-09-03 14:30:43 -0400 | [diff] [blame] | 34 | } |
| 35 | } |