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 | } |
Jon Perritt | 7726e49 | 2015-02-04 17:54:28 -0700 | [diff] [blame] | 118 | |
| 119 | func TestGetStack(t *testing.T) { |
| 120 | th.SetupHTTP() |
| 121 | defer th.TeardownHTTP() |
| 122 | HandleGetSuccessfully(t, GetOutput) |
| 123 | |
| 124 | actual, err := Get(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c87").Extract() |
| 125 | th.AssertNoErr(t, err) |
| 126 | |
| 127 | expected := GetExpected |
| 128 | th.AssertDeepEquals(t, expected, actual) |
| 129 | } |
| 130 | |
| 131 | func TestUpdateStack(t *testing.T) { |
| 132 | th.SetupHTTP() |
| 133 | defer th.TeardownHTTP() |
| 134 | HandleUpdateSuccessfully(t) |
| 135 | |
| 136 | updateOpts := UpdateOpts{ |
| 137 | Template: ` |
| 138 | { |
| 139 | "heat_template_version": "2013-05-23", |
| 140 | "description": "Simple template to test heat commands", |
| 141 | "parameters": { |
| 142 | "flavor": { |
| 143 | "default": "m1.tiny", |
| 144 | "type": "string" |
| 145 | } |
| 146 | }, |
| 147 | "resources": { |
| 148 | "hello_world": { |
| 149 | "type":"OS::Nova::Server", |
| 150 | "properties": { |
| 151 | "key_name": "heat_key", |
| 152 | "flavor": { |
| 153 | "get_param": "flavor" |
| 154 | }, |
| 155 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 156 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | }`, |
| 161 | } |
| 162 | err := Update(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr() |
| 163 | th.AssertNoErr(t, err) |
| 164 | } |
Jon Perritt | a433dd9 | 2015-02-04 18:04:13 -0700 | [diff] [blame^] | 165 | |
| 166 | func TestDeleteStack(t *testing.T) { |
| 167 | th.SetupHTTP() |
| 168 | defer th.TeardownHTTP() |
| 169 | HandleDeleteSuccessfully(t) |
| 170 | |
| 171 | err := Delete(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada").ExtractErr() |
| 172 | th.AssertNoErr(t, err) |
| 173 | } |