blob: 74df24ea562e7ceda3b1975490e424147961e202 [file] [log] [blame]
Jon Perritt4a5c8492015-02-03 13:13:59 -07001package stacks
2
3import (
4 "testing"
5
6 th "github.com/rackspace/gophercloud/testhelper"
7 fake "github.com/rackspace/gophercloud/testhelper/client"
8)
9
10func TestCreateStack(t *testing.T) {
11 th.SetupHTTP()
12 defer th.TeardownHTTP()
13 HandleCreateSuccessfully(t, CreateOutput)
14
15 createOpts := CreateOpts{
16 Name: "stackcreated",
17 Timeout: 60,
18 Template: `
19 {
20 "stack_name": "postman_stack",
21 "template": {
22 "heat_template_version": "2013-05-23",
23 "description": "Simple template to test heat commands",
24 "parameters": {
25 "flavor": {
26 "default": "m1.tiny",
27 "type": "string"
28 }
29 },
30 "resources": {
31 "hello_world": {
32 "type":"OS::Nova::Server",
33 "properties": {
34 "key_name": "heat_key",
35 "flavor": {
36 "get_param": "flavor"
37 },
38 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
39 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
40 }
41 }
42 }
43 }
44 }`,
45 DisableRollback: Disable,
46 }
47 actual, err := Create(fake.ServiceClient(), createOpts).Extract()
48 th.AssertNoErr(t, err)
49
50 expected := CreateExpected
51 th.AssertDeepEquals(t, expected, actual)
52}
Jon Perritt9741dd92015-02-04 12:05:47 -070053
54func TestAdoptStack(t *testing.T) {
55 th.SetupHTTP()
56 defer th.TeardownHTTP()
57 HandleCreateSuccessfully(t, CreateOutput)
58
59 adoptOpts := AdoptOpts{
60 AdoptStackData: `{environment{parameters{}}}`,
61 Name: "stackcreated",
62 Timeout: 60,
63 Template: `
64 {
65 "stack_name": "postman_stack",
66 "template": {
67 "heat_template_version": "2013-05-23",
68 "description": "Simple template to test heat commands",
69 "parameters": {
70 "flavor": {
71 "default": "m1.tiny",
72 "type": "string"
73 }
74 },
75 "resources": {
76 "hello_world": {
77 "type":"OS::Nova::Server",
78 "properties": {
79 "key_name": "heat_key",
80 "flavor": {
81 "get_param": "flavor"
82 },
83 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743",
84 "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n"
85 }
86 }
87 }
88 }
89 }`,
90 DisableRollback: Disable,
91 }
92 actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract()
93 th.AssertNoErr(t, err)
94
95 expected := CreateExpected
96 th.AssertDeepEquals(t, expected, actual)
97}