Jon Perritt | 3711cd0 | 2014-12-22 22:20:15 -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/stackresources" |
| 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 TestStackResources(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 | |
| 22 | createOpts := stacks.CreateOpts{ |
| 23 | Name: stackName, |
| 24 | Template: template, |
| 25 | Timeout: 5, |
| 26 | } |
| 27 | stack, err := stacks.Create(client, createOpts).Extract() |
| 28 | th.AssertNoErr(t, err) |
| 29 | t.Logf("Created stack: %+v\n", stack) |
| 30 | defer func() { |
| 31 | err := stacks.Delete(client, stackName, stack.ID).ExtractErr() |
| 32 | th.AssertNoErr(t, err) |
| 33 | t.Logf("Deleted stack (%s)", stackName) |
| 34 | }() |
| 35 | err = gophercloud.WaitFor(60, func() (bool, error) { |
| 36 | getStack, err := stacks.Get(client, stackName, stack.ID).Extract() |
| 37 | if err != nil { |
| 38 | return false, err |
| 39 | } |
| 40 | if getStack.Status == "CREATE_COMPLETE" { |
| 41 | return true, nil |
| 42 | } |
| 43 | return false, nil |
| 44 | }) |
| 45 | |
| 46 | var resourceName string |
| 47 | pager := stackresources.List(client, stackName, stack.ID, stackresources.ListOpts{}) |
| 48 | pager.EachPage(func(page pagination.Page) (bool, error) { |
| 49 | resources, err := stackresources.ExtractResources(page) |
| 50 | if err != nil { |
| 51 | return false, err |
| 52 | } |
| 53 | |
| 54 | t.Logf("%+v\n", resources) |
| 55 | |
| 56 | resourceName = resources[0].Name |
| 57 | |
| 58 | return true, nil |
| 59 | }) |
| 60 | |
| 61 | /* |
| 62 | resource, err := stackresources.Find(client, stackName).Extract() |
| 63 | th.AssertNoErr(t, err) |
| 64 | t.Logf("Got stack resource: %+v\n", resource) |
| 65 | */ |
| 66 | |
| 67 | resource, err := stackresources.Get(client, stackName, stack.ID, resourceName).Extract() |
| 68 | th.AssertNoErr(t, err) |
| 69 | t.Logf("Got stack resource: %+v\n", resource) |
| 70 | |
| 71 | metadata, err := stackresources.Metadata(client, stackName, stack.ID, resourceName).Extract() |
| 72 | th.AssertNoErr(t, err) |
| 73 | t.Logf("Got stack resource metadata: %+v\n", metadata) |
| 74 | |
| 75 | } |