Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -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/stacks" |
| 10 | "github.com/rackspace/gophercloud/pagination" |
| 11 | th "github.com/rackspace/gophercloud/testhelper" |
| 12 | ) |
| 13 | |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 14 | func TestStacks(t *testing.T) { |
| 15 | // Create a provider client for making the HTTP requests. |
| 16 | // See common.go in this directory for more information. |
| 17 | client := newClient(t) |
| 18 | |
| 19 | stackName1 := "gophercloud-test-stack-2" |
| 20 | createOpts := stacks.CreateOpts{ |
| 21 | Name: stackName1, |
| 22 | Template: template, |
| 23 | Timeout: 5, |
| 24 | } |
| 25 | stack, err := stacks.Create(client, createOpts).Extract() |
| 26 | th.AssertNoErr(t, err) |
| 27 | t.Logf("Created stack: %+v\n", stack) |
| 28 | defer func() { |
| 29 | err := stacks.Delete(client, stackName1, stack.ID).ExtractErr() |
| 30 | th.AssertNoErr(t, err) |
| 31 | t.Logf("Deleted stack (%s)", stackName1) |
| 32 | }() |
| 33 | err = gophercloud.WaitFor(60, func() (bool, error) { |
Jon Perritt | 93e02bb | 2014-12-18 11:39:41 -0700 | [diff] [blame] | 34 | getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 35 | if err != nil { |
| 36 | return false, err |
| 37 | } |
Jon Perritt | 93e02bb | 2014-12-18 11:39:41 -0700 | [diff] [blame] | 38 | if getStack.Status == "CREATE_COMPLETE" { |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 39 | return true, nil |
| 40 | } |
| 41 | return false, nil |
| 42 | }) |
| 43 | /* |
| 44 | adoptOpts := stacks.AdoptOpts{} |
| 45 | stack, err := stacks.Adopt(client, adoptOpts).Extract() |
| 46 | th.AssertNoErr(t, err) |
| 47 | t.Logf("Adopted stack: %+v\n", stack) |
| 48 | */ |
| 49 | |
| 50 | updateOpts := stacks.UpdateOpts{ |
| 51 | Template: template, |
| 52 | Timeout: 20, |
| 53 | } |
| 54 | err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr() |
| 55 | th.AssertNoErr(t, err) |
| 56 | t.Logf("Updated stack") |
| 57 | |
| 58 | err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) { |
| 59 | stackList, err := stacks.ExtractStacks(page) |
| 60 | th.AssertNoErr(t, err) |
| 61 | |
| 62 | t.Logf("Got stack list: %+v\n", stackList) |
| 63 | |
| 64 | return true, nil |
| 65 | }) |
| 66 | th.AssertNoErr(t, err) |
| 67 | |
Jon Perritt | 93e02bb | 2014-12-18 11:39:41 -0700 | [diff] [blame] | 68 | getStack, err := stacks.Get(client, stackName1, stack.ID).Extract() |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 69 | th.AssertNoErr(t, err) |
Jon Perritt | 93e02bb | 2014-12-18 11:39:41 -0700 | [diff] [blame] | 70 | t.Logf("Got stack: %+v\n", getStack) |
Jon Perritt | 35e27e4 | 2014-12-05 11:10:46 -0700 | [diff] [blame] | 71 | } |