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