Jon Perritt | 4a5c849 | 2015-02-03 13:13:59 -0700 | [diff] [blame] | 1 | package stacks |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
jrperritt | 8ce5e28 | 2016-04-13 14:31:01 -0500 | [diff] [blame] | 6 | "github.com/gophercloud/gophercloud" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 7 | "github.com/gophercloud/gophercloud/pagination" |
| 8 | th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | fake "github.com/gophercloud/gophercloud/testhelper/client" |
Jon Perritt | 4a5c849 | 2015-02-03 13:13:59 -0700 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | func TestCreateStack(t *testing.T) { |
| 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
| 15 | HandleCreateSuccessfully(t, CreateOutput) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 16 | template := new(Template) |
| 17 | template.Bin = []byte(` |
| 18 | { |
| 19 | "heat_template_version": "2013-05-23", |
| 20 | "description": "Simple template to test heat commands", |
| 21 | "parameters": { |
| 22 | "flavor": { |
| 23 | "default": "m1.tiny", |
| 24 | "type": "string" |
| 25 | } |
| 26 | } |
| 27 | }`) |
| 28 | createOpts := CreateOpts{ |
| 29 | Name: "stackcreated", |
| 30 | Timeout: 60, |
| 31 | TemplateOpts: template, |
Jon Perritt | 397ade6 | 2016-03-15 06:55:02 -0500 | [diff] [blame] | 32 | DisableRollback: gophercloud.Disabled, |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 33 | } |
| 34 | actual, err := Create(fake.ServiceClient(), createOpts).Extract() |
| 35 | th.AssertNoErr(t, err) |
| 36 | |
| 37 | expected := CreateExpected |
| 38 | th.AssertDeepEquals(t, expected, actual) |
| 39 | } |
| 40 | |
Jon Perritt | 9741dd9 | 2015-02-04 12:05:47 -0700 | [diff] [blame] | 41 | func TestAdoptStack(t *testing.T) { |
| 42 | th.SetupHTTP() |
| 43 | defer th.TeardownHTTP() |
| 44 | HandleCreateSuccessfully(t, CreateOutput) |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 45 | template := new(Template) |
| 46 | template.Bin = []byte(` |
| 47 | { |
| 48 | "stack_name": "postman_stack", |
| 49 | "template": { |
| 50 | "heat_template_version": "2013-05-23", |
| 51 | "description": "Simple template to test heat commands", |
| 52 | "parameters": { |
| 53 | "flavor": { |
| 54 | "default": "m1.tiny", |
| 55 | "type": "string" |
| 56 | } |
| 57 | }, |
| 58 | "resources": { |
| 59 | "hello_world": { |
| 60 | "type":"OS::Nova::Server", |
| 61 | "properties": { |
| 62 | "key_name": "heat_key", |
| 63 | "flavor": { |
| 64 | "get_param": "flavor" |
| 65 | }, |
| 66 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 67 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | }`) |
| 73 | adoptOpts := AdoptOpts{ |
| 74 | AdoptStackData: `{environment{parameters{}}}`, |
| 75 | Name: "stackcreated", |
| 76 | Timeout: 60, |
| 77 | TemplateOpts: template, |
Jon Perritt | 397ade6 | 2016-03-15 06:55:02 -0500 | [diff] [blame] | 78 | DisableRollback: gophercloud.Disabled, |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 79 | } |
| 80 | actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract() |
| 81 | th.AssertNoErr(t, err) |
| 82 | |
| 83 | expected := CreateExpected |
| 84 | th.AssertDeepEquals(t, expected, actual) |
| 85 | } |
| 86 | |
Jon Perritt | 9cd3d38 | 2015-02-04 15:49:41 -0700 | [diff] [blame] | 87 | func TestListStack(t *testing.T) { |
| 88 | th.SetupHTTP() |
| 89 | defer th.TeardownHTTP() |
| 90 | HandleListSuccessfully(t, FullListOutput) |
| 91 | |
| 92 | count := 0 |
| 93 | err := List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { |
| 94 | count++ |
| 95 | actual, err := ExtractStacks(page) |
| 96 | th.AssertNoErr(t, err) |
| 97 | |
| 98 | th.CheckDeepEquals(t, ListExpected, actual) |
| 99 | |
| 100 | return true, nil |
| 101 | }) |
| 102 | th.AssertNoErr(t, err) |
| 103 | th.CheckEquals(t, count, 1) |
| 104 | } |
Jon Perritt | 7726e49 | 2015-02-04 17:54:28 -0700 | [diff] [blame] | 105 | |
| 106 | func TestGetStack(t *testing.T) { |
| 107 | th.SetupHTTP() |
| 108 | defer th.TeardownHTTP() |
| 109 | HandleGetSuccessfully(t, GetOutput) |
| 110 | |
| 111 | actual, err := Get(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c87").Extract() |
| 112 | th.AssertNoErr(t, err) |
| 113 | |
| 114 | expected := GetExpected |
| 115 | th.AssertDeepEquals(t, expected, actual) |
| 116 | } |
| 117 | |
| 118 | func TestUpdateStack(t *testing.T) { |
| 119 | th.SetupHTTP() |
| 120 | defer th.TeardownHTTP() |
| 121 | HandleUpdateSuccessfully(t) |
| 122 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 123 | template := new(Template) |
| 124 | template.Bin = []byte(` |
| 125 | { |
| 126 | "heat_template_version": "2013-05-23", |
| 127 | "description": "Simple template to test heat commands", |
| 128 | "parameters": { |
| 129 | "flavor": { |
| 130 | "default": "m1.tiny", |
| 131 | "type": "string" |
| 132 | } |
| 133 | } |
| 134 | }`) |
| 135 | updateOpts := UpdateOpts{ |
| 136 | TemplateOpts: template, |
| 137 | } |
| 138 | err := Update(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr() |
| 139 | th.AssertNoErr(t, err) |
| 140 | } |
| 141 | |
Jon Perritt | a433dd9 | 2015-02-04 18:04:13 -0700 | [diff] [blame] | 142 | func TestDeleteStack(t *testing.T) { |
| 143 | th.SetupHTTP() |
| 144 | defer th.TeardownHTTP() |
| 145 | HandleDeleteSuccessfully(t) |
| 146 | |
| 147 | err := Delete(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada").ExtractErr() |
| 148 | th.AssertNoErr(t, err) |
| 149 | } |
Jon Perritt | 37f9774 | 2015-02-04 18:55:05 -0700 | [diff] [blame] | 150 | |
| 151 | func TestPreviewStack(t *testing.T) { |
| 152 | th.SetupHTTP() |
| 153 | defer th.TeardownHTTP() |
| 154 | HandlePreviewSuccessfully(t, GetOutput) |
| 155 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 156 | template := new(Template) |
| 157 | template.Bin = []byte(` |
| 158 | { |
| 159 | "heat_template_version": "2013-05-23", |
| 160 | "description": "Simple template to test heat commands", |
| 161 | "parameters": { |
| 162 | "flavor": { |
| 163 | "default": "m1.tiny", |
| 164 | "type": "string" |
| 165 | } |
| 166 | } |
| 167 | }`) |
| 168 | previewOpts := PreviewOpts{ |
| 169 | Name: "stackcreated", |
| 170 | Timeout: 60, |
| 171 | TemplateOpts: template, |
Jon Perritt | 397ade6 | 2016-03-15 06:55:02 -0500 | [diff] [blame] | 172 | DisableRollback: gophercloud.Disabled, |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 173 | } |
| 174 | actual, err := Preview(fake.ServiceClient(), previewOpts).Extract() |
| 175 | th.AssertNoErr(t, err) |
| 176 | |
| 177 | expected := PreviewExpected |
| 178 | th.AssertDeepEquals(t, expected, actual) |
| 179 | } |
| 180 | |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 181 | func TestAbandonStack(t *testing.T) { |
| 182 | th.SetupHTTP() |
| 183 | defer th.TeardownHTTP() |
| 184 | HandleAbandonSuccessfully(t, AbandonOutput) |
| 185 | |
| 186 | actual, err := Abandon(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c8").Extract() |
| 187 | th.AssertNoErr(t, err) |
| 188 | |
| 189 | expected := AbandonExpected |
| 190 | th.AssertDeepEquals(t, expected, actual) |
| 191 | } |