Jon Perritt | 4a5c849 | 2015-02-03 13:13:59 -0700 | [diff] [blame] | 1 | package stacks |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 6 | "github.com/rackspace/gophercloud/pagination" |
Jon Perritt | 4a5c849 | 2015-02-03 13:13:59 -0700 | [diff] [blame] | 7 | th "github.com/rackspace/gophercloud/testhelper" |
| 8 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 9 | ) |
| 10 | |
| 11 | func TestCreateStack(t *testing.T) { |
| 12 | th.SetupHTTP() |
| 13 | defer th.TeardownHTTP() |
| 14 | HandleCreateSuccessfully(t, CreateOutput) |
| 15 | |
| 16 | createOpts := CreateOpts{ |
| 17 | Name: "stackcreated", |
| 18 | Timeout: 60, |
| 19 | Template: ` |
| 20 | { |
| 21 | "stack_name": "postman_stack", |
| 22 | "template": { |
| 23 | "heat_template_version": "2013-05-23", |
| 24 | "description": "Simple template to test heat commands", |
| 25 | "parameters": { |
| 26 | "flavor": { |
| 27 | "default": "m1.tiny", |
| 28 | "type": "string" |
| 29 | } |
| 30 | }, |
| 31 | "resources": { |
| 32 | "hello_world": { |
| 33 | "type":"OS::Nova::Server", |
| 34 | "properties": { |
| 35 | "key_name": "heat_key", |
| 36 | "flavor": { |
| 37 | "get_param": "flavor" |
| 38 | }, |
| 39 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 40 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | }`, |
| 46 | DisableRollback: Disable, |
| 47 | } |
| 48 | actual, err := Create(fake.ServiceClient(), createOpts).Extract() |
| 49 | th.AssertNoErr(t, err) |
| 50 | |
| 51 | expected := CreateExpected |
| 52 | th.AssertDeepEquals(t, expected, actual) |
| 53 | } |
Jon Perritt | 9741dd9 | 2015-02-04 12:05:47 -0700 | [diff] [blame] | 54 | |
| 55 | func TestAdoptStack(t *testing.T) { |
| 56 | th.SetupHTTP() |
| 57 | defer th.TeardownHTTP() |
| 58 | HandleCreateSuccessfully(t, CreateOutput) |
| 59 | |
| 60 | adoptOpts := AdoptOpts{ |
| 61 | AdoptStackData: `{environment{parameters{}}}`, |
| 62 | Name: "stackcreated", |
| 63 | Timeout: 60, |
| 64 | Template: ` |
| 65 | { |
| 66 | "stack_name": "postman_stack", |
| 67 | "template": { |
| 68 | "heat_template_version": "2013-05-23", |
| 69 | "description": "Simple template to test heat commands", |
| 70 | "parameters": { |
| 71 | "flavor": { |
| 72 | "default": "m1.tiny", |
| 73 | "type": "string" |
| 74 | } |
| 75 | }, |
| 76 | "resources": { |
| 77 | "hello_world": { |
| 78 | "type":"OS::Nova::Server", |
| 79 | "properties": { |
| 80 | "key_name": "heat_key", |
| 81 | "flavor": { |
| 82 | "get_param": "flavor" |
| 83 | }, |
| 84 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 85 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | }`, |
| 91 | DisableRollback: Disable, |
| 92 | } |
| 93 | actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract() |
| 94 | th.AssertNoErr(t, err) |
| 95 | |
| 96 | expected := CreateExpected |
| 97 | th.AssertDeepEquals(t, expected, actual) |
| 98 | } |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 99 | |
| 100 | func TestListStack(t *testing.T) { |
| 101 | th.SetupHTTP() |
| 102 | defer th.TeardownHTTP() |
| 103 | HandleListSuccessfully(t, FullListOutput) |
| 104 | |
| 105 | count := 0 |
| 106 | err := List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { |
| 107 | count++ |
| 108 | actual, err := ExtractStacks(page) |
| 109 | th.AssertNoErr(t, err) |
| 110 | |
| 111 | th.CheckDeepEquals(t, ListExpected, actual) |
| 112 | |
| 113 | return true, nil |
| 114 | }) |
| 115 | th.AssertNoErr(t, err) |
| 116 | th.CheckEquals(t, count, 1) |
| 117 | } |