jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 1 | package testing |
Ash Wilson | 61dcb02 | 2014-10-03 08:15:47 -0400 | [diff] [blame] | 2 | |
| 3 | import ( |
Ash Wilson | 61dcb02 | 2014-10-03 08:15:47 -0400 | [diff] [blame] | 4 | "testing" |
| 5 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud/openstack/common/extensions" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 7 | "github.com/gophercloud/gophercloud/pagination" |
| 8 | th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | "github.com/gophercloud/gophercloud/testhelper/client" |
Ash Wilson | 61dcb02 | 2014-10-03 08:15:47 -0400 | [diff] [blame] | 10 | ) |
| 11 | |
Ash Wilson | 61dcb02 | 2014-10-03 08:15:47 -0400 | [diff] [blame] | 12 | func TestList(t *testing.T) { |
| 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
Ash Wilson | ce942a8 | 2014-10-13 11:48:01 -0400 | [diff] [blame] | 15 | HandleListExtensionsSuccessfully(t) |
Ash Wilson | 61dcb02 | 2014-10-03 08:15:47 -0400 | [diff] [blame] | 16 | |
| 17 | count := 0 |
| 18 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 19 | extensions.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
Ash Wilson | 61dcb02 | 2014-10-03 08:15:47 -0400 | [diff] [blame] | 20 | count++ |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 21 | actual, err := extensions.ExtractExtensions(page) |
Ash Wilson | ce942a8 | 2014-10-13 11:48:01 -0400 | [diff] [blame] | 22 | th.AssertNoErr(t, err) |
| 23 | th.AssertDeepEquals(t, ExpectedExtensions, actual) |
Ash Wilson | 61dcb02 | 2014-10-03 08:15:47 -0400 | [diff] [blame] | 24 | |
| 25 | return true, nil |
| 26 | }) |
| 27 | |
Ash Wilson | ce942a8 | 2014-10-13 11:48:01 -0400 | [diff] [blame] | 28 | th.CheckEquals(t, 1, count) |
Ash Wilson | 61dcb02 | 2014-10-03 08:15:47 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | func TestGet(t *testing.T) { |
| 32 | th.SetupHTTP() |
| 33 | defer th.TeardownHTTP() |
Ash Wilson | ce942a8 | 2014-10-13 11:48:01 -0400 | [diff] [blame] | 34 | HandleGetExtensionSuccessfully(t) |
Ash Wilson | 61dcb02 | 2014-10-03 08:15:47 -0400 | [diff] [blame] | 35 | |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 36 | actual, err := extensions.Get(client.ServiceClient(), "agent").Extract() |
Ash Wilson | ce942a8 | 2014-10-13 11:48:01 -0400 | [diff] [blame] | 37 | th.AssertNoErr(t, err) |
| 38 | th.CheckDeepEquals(t, SingleExtension, actual) |
Ash Wilson | 61dcb02 | 2014-10-03 08:15:47 -0400 | [diff] [blame] | 39 | } |