Jon Perritt | ff2116c | 2015-02-09 15:42:57 -0700 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | "github.com/rackspace/gophercloud/openstack/orchestration/v1/stackevents" |
| 10 | "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacks" |
| 11 | "github.com/rackspace/gophercloud/pagination" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | ) |
| 14 | |
| 15 | func TestStackEvents(t *testing.T) { |
| 16 | // Create a provider client for making the HTTP requests. |
| 17 | // See common.go in this directory for more information. |
| 18 | client := newClient(t) |
| 19 | |
| 20 | stackName := "postman_stack_2" |
| 21 | resourceName := "hello_world" |
| 22 | var eventID string |
| 23 | |
| 24 | createOpts := stacks.CreateOpts{ |
| 25 | Name: stackName, |
| 26 | Template: template, |
| 27 | Timeout: 5, |
| 28 | } |
| 29 | stack, err := stacks.Create(client, createOpts).Extract() |
| 30 | th.AssertNoErr(t, err) |
| 31 | t.Logf("Created stack: %+v\n", stack) |
| 32 | defer func() { |
| 33 | err := stacks.Delete(client, stackName, stack.ID).ExtractErr() |
| 34 | th.AssertNoErr(t, err) |
| 35 | t.Logf("Deleted stack (%s)", stackName) |
| 36 | }() |
| 37 | err = gophercloud.WaitFor(60, func() (bool, error) { |
| 38 | getStack, err := stacks.Get(client, stackName, stack.ID).Extract() |
| 39 | if err != nil { |
| 40 | return false, err |
| 41 | } |
| 42 | if getStack.Status == "CREATE_COMPLETE" { |
| 43 | return true, nil |
| 44 | } |
| 45 | return false, nil |
| 46 | }) |
| 47 | |
| 48 | err = stackevents.List(client, stackName, stack.ID, nil).EachPage(func(page pagination.Page) (bool, error) { |
| 49 | events, err := stackevents.ExtractEvents(page) |
| 50 | th.AssertNoErr(t, err) |
| 51 | t.Logf("listed events: %+v\n", events) |
| 52 | eventID = events[0].ID |
| 53 | return false, nil |
| 54 | }) |
| 55 | th.AssertNoErr(t, err) |
| 56 | |
| 57 | err = stackevents.ListResourceEvents(client, stackName, stack.ID, resourceName, nil).EachPage(func(page pagination.Page) (bool, error) { |
| 58 | resourceEvents, err := stackevents.ExtractEvents(page) |
| 59 | th.AssertNoErr(t, err) |
| 60 | t.Logf("listed resource events: %+v\n", resourceEvents) |
| 61 | return false, nil |
| 62 | }) |
| 63 | th.AssertNoErr(t, err) |
| 64 | |
| 65 | event, err := stackevents.Get(client, stackName, stack.ID, resourceName, eventID).Extract() |
| 66 | th.AssertNoErr(t, err) |
| 67 | t.Logf("retrieved event: %+v\n", event) |
| 68 | } |