Jamie Hannaford | 2d48037 | 2014-10-22 10:47:09 +0200 | [diff] [blame^] | 1 | // +build acceptance compute images |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud/openstack/compute/v2/images" |
| 9 | "github.com/rackspace/gophercloud/pagination" |
| 10 | ) |
| 11 | |
| 12 | func TestListImages(t *testing.T) { |
| 13 | client, err := newClient() |
| 14 | if err != nil { |
| 15 | t.Fatalf("Unable to create a compute: client: %v", err) |
| 16 | } |
| 17 | |
| 18 | t.Logf("ID\tRegion\tName\tStatus\tCreated") |
| 19 | |
Jon Perritt | ef168e6 | 2014-10-08 11:14:05 -0500 | [diff] [blame] | 20 | pager := images.ListDetail(client, nil) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 21 | count, pages := 0, 0 |
| 22 | pager.EachPage(func(page pagination.Page) (bool, error) { |
| 23 | pages++ |
| 24 | images, err := images.ExtractImages(page) |
| 25 | if err != nil { |
| 26 | return false, err |
| 27 | } |
| 28 | |
| 29 | for _, i := range images { |
| 30 | t.Logf("%s\t%s\t%s\t%s", i.ID, i.Name, i.Status, i.Created) |
| 31 | } |
| 32 | |
| 33 | return true, nil |
| 34 | }) |
| 35 | |
| 36 | t.Logf("--------\n%d images listed on %d pages.", count, pages) |
| 37 | } |