blob: b614f1cef5f27098284e52f715b52ff47f22d8a3 [file] [log] [blame]
Jon Perritt3711cd02014-12-22 22:20:15 -07001// +build acceptance
2
3package v1
4
5import (
6 "testing"
7
8 "github.com/rackspace/gophercloud"
9 "github.com/rackspace/gophercloud/openstack/orchestration/v1/stackresources"
10 "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacks"
11 "github.com/rackspace/gophercloud/pagination"
12 th "github.com/rackspace/gophercloud/testhelper"
13)
14
15func TestStackResources(t *testing.T) {
16 // Create a provider client for making the HTTP requests.
17 // See common.go in this directory for more information.
18 client := newClient(t)
19
20 stackName := "postman_stack_2"
21
22 createOpts := stacks.CreateOpts{
23 Name: stackName,
24 Template: template,
25 Timeout: 5,
26 }
27 stack, err := stacks.Create(client, createOpts).Extract()
28 th.AssertNoErr(t, err)
29 t.Logf("Created stack: %+v\n", stack)
30 defer func() {
31 err := stacks.Delete(client, stackName, stack.ID).ExtractErr()
32 th.AssertNoErr(t, err)
33 t.Logf("Deleted stack (%s)", stackName)
34 }()
35 err = gophercloud.WaitFor(60, func() (bool, error) {
36 getStack, err := stacks.Get(client, stackName, stack.ID).Extract()
37 if err != nil {
38 return false, err
39 }
40 if getStack.Status == "CREATE_COMPLETE" {
41 return true, nil
42 }
43 return false, nil
44 })
45
Jon Perritt6dbf9a52015-02-09 14:36:01 -070046 resourceName := "hello_world"
Jon Perritt3711cd02014-12-22 22:20:15 -070047 resource, err := stackresources.Get(client, stackName, stack.ID, resourceName).Extract()
48 th.AssertNoErr(t, err)
49 t.Logf("Got stack resource: %+v\n", resource)
50
51 metadata, err := stackresources.Metadata(client, stackName, stack.ID, resourceName).Extract()
52 th.AssertNoErr(t, err)
53 t.Logf("Got stack resource metadata: %+v\n", metadata)
54
Jon Perritt6dbf9a52015-02-09 14:36:01 -070055 err = stackresources.List(client, stackName, stack.ID, stackresources.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
56 resources, err := stackresources.ExtractResources(page)
57 th.AssertNoErr(t, err)
58 t.Logf("resources: %+v\n", resources)
59 return false, nil
60 })
61 th.AssertNoErr(t, err)
Jon Perritt3711cd02014-12-22 22:20:15 -070062}