Jon Perritt | 5a0ddd8 | 2015-02-09 17:07:21 -0700 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | osStackResources "github.com/rackspace/gophercloud/openstack/orchestration/v1/stackresources" |
| 10 | osStacks "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacks" |
| 11 | "github.com/rackspace/gophercloud/pagination" |
| 12 | "github.com/rackspace/gophercloud/rackspace/orchestration/v1/stackresources" |
| 13 | "github.com/rackspace/gophercloud/rackspace/orchestration/v1/stacks" |
| 14 | th "github.com/rackspace/gophercloud/testhelper" |
| 15 | ) |
| 16 | |
| 17 | func TestStackResources(t *testing.T) { |
| 18 | // Create a provider client for making the HTTP requests. |
| 19 | // See common.go in this directory for more information. |
| 20 | client := newClient(t) |
| 21 | |
| 22 | stackName := "postman_stack_2" |
| 23 | |
| 24 | createOpts := osStacks.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 | resourceName := "hello_world" |
| 49 | resource, err := stackresources.Get(client, stackName, stack.ID, resourceName).Extract() |
| 50 | th.AssertNoErr(t, err) |
| 51 | t.Logf("Got stack resource: %+v\n", resource) |
| 52 | |
| 53 | metadata, err := stackresources.Metadata(client, stackName, stack.ID, resourceName).Extract() |
| 54 | th.AssertNoErr(t, err) |
| 55 | t.Logf("Got stack resource metadata: %+v\n", metadata) |
| 56 | |
| 57 | err = stackresources.List(client, stackName, stack.ID, nil).EachPage(func(page pagination.Page) (bool, error) { |
| 58 | resources, err := osStackResources.ExtractResources(page) |
| 59 | th.AssertNoErr(t, err) |
| 60 | t.Logf("resources: %+v\n", resources) |
| 61 | return false, nil |
| 62 | }) |
| 63 | th.AssertNoErr(t, err) |
| 64 | } |