Jon Perritt | 7cbb42c | 2015-02-08 21:13:08 -0700 | [diff] [blame] | 1 | package stackevents |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/pagination" |
| 7 | th "github.com/rackspace/gophercloud/testhelper" |
| 8 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 9 | ) |
| 10 | |
| 11 | func TestFindEvents(t *testing.T) { |
| 12 | th.SetupHTTP() |
| 13 | defer th.TeardownHTTP() |
| 14 | HandleFindSuccessfully(t, FindOutput) |
| 15 | |
| 16 | actual, err := Find(fake.ServiceClient(), "postman_stack").Extract() |
| 17 | th.AssertNoErr(t, err) |
| 18 | |
| 19 | expected := FindExpected |
| 20 | th.AssertDeepEquals(t, expected, actual) |
| 21 | } |
| 22 | |
| 23 | func TestList(t *testing.T) { |
| 24 | th.SetupHTTP() |
| 25 | defer th.TeardownHTTP() |
| 26 | HandleListSuccessfully(t, ListOutput) |
| 27 | |
| 28 | count := 0 |
| 29 | err := List(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", nil).EachPage(func(page pagination.Page) (bool, error) { |
| 30 | count++ |
| 31 | actual, err := ExtractEvents(page) |
| 32 | th.AssertNoErr(t, err) |
| 33 | |
| 34 | th.CheckDeepEquals(t, ListExpected, actual) |
| 35 | |
| 36 | return true, nil |
| 37 | }) |
| 38 | th.AssertNoErr(t, err) |
| 39 | th.CheckEquals(t, count, 1) |
| 40 | } |
| 41 | |
| 42 | func TestListResourceEvents(t *testing.T) { |
| 43 | th.SetupHTTP() |
| 44 | defer th.TeardownHTTP() |
| 45 | HandleListResourceEventsSuccessfully(t, ListResourceEventsOutput) |
| 46 | |
| 47 | count := 0 |
| 48 | err := ListResourceEvents(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", "my_resource", nil).EachPage(func(page pagination.Page) (bool, error) { |
| 49 | count++ |
| 50 | actual, err := ExtractEvents(page) |
| 51 | th.AssertNoErr(t, err) |
| 52 | |
| 53 | th.CheckDeepEquals(t, ListResourceEventsExpected, actual) |
| 54 | |
| 55 | return true, nil |
| 56 | }) |
| 57 | th.AssertNoErr(t, err) |
| 58 | th.CheckEquals(t, count, 1) |
| 59 | } |
| 60 | |
| 61 | func TestGetEvent(t *testing.T) { |
| 62 | th.SetupHTTP() |
| 63 | defer th.TeardownHTTP() |
| 64 | HandleGetSuccessfully(t, GetOutput) |
| 65 | |
| 66 | actual, err := Get(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", "my_resource", "93940999-7d40-44ae-8de4-19624e7b8d18").Extract() |
| 67 | th.AssertNoErr(t, err) |
| 68 | |
| 69 | expected := GetExpected |
| 70 | th.AssertDeepEquals(t, expected, actual) |
| 71 | } |