blob: 5800d7cc1b124fb6c822f60595fe6c99051f3c13 [file] [log] [blame]
Jon Perritta065da12015-02-06 10:20:16 -07001package stackresources
2
3import (
4 "testing"
5
6 os "github.com/rackspace/gophercloud/openstack/orchestration/v1/stackresources"
7 "github.com/rackspace/gophercloud/pagination"
8 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
10)
11
12func TestFindResources(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15 os.HandleFindSuccessfully(t, os.FindOutput)
16
17 actual, err := Find(fake.ServiceClient(), "hello_world").Extract()
18 th.AssertNoErr(t, err)
19
20 expected := os.FindExpected
21 th.AssertDeepEquals(t, expected, actual)
22}
23
24func TestListResources(t *testing.T) {
25 th.SetupHTTP()
26 defer th.TeardownHTTP()
27 os.HandleListSuccessfully(t, os.ListOutput)
28
29 count := 0
30 err := List(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", nil).EachPage(func(page pagination.Page) (bool, error) {
31 count++
32 actual, err := os.ExtractResources(page)
33 th.AssertNoErr(t, err)
34
35 th.CheckDeepEquals(t, os.ListExpected, actual)
36
37 return true, nil
38 })
39 th.AssertNoErr(t, err)
40 th.CheckEquals(t, count, 1)
41}
42
43func TestGetResource(t *testing.T) {
44 th.SetupHTTP()
45 defer th.TeardownHTTP()
46 os.HandleGetSuccessfully(t, os.GetOutput)
47
48 actual, err := Get(fake.ServiceClient(), "teststack", "0b1771bd-9336-4f2b-ae86-a80f971faf1e", "wordpress_instance").Extract()
49 th.AssertNoErr(t, err)
50
51 expected := os.GetExpected
52 th.AssertDeepEquals(t, expected, actual)
53}
54
55func TestResourceMetadata(t *testing.T) {
56 th.SetupHTTP()
57 defer th.TeardownHTTP()
58 os.HandleMetadataSuccessfully(t, os.MetadataOutput)
59
60 actual, err := Metadata(fake.ServiceClient(), "teststack", "0b1771bd-9336-4f2b-ae86-a80f971faf1e", "wordpress_instance").Extract()
61 th.AssertNoErr(t, err)
62
63 expected := os.MetadataExpected
64 th.AssertDeepEquals(t, expected, actual)
65}
66
67func TestListResourceTypes(t *testing.T) {
68 th.SetupHTTP()
69 defer th.TeardownHTTP()
70 os.HandleListTypesSuccessfully(t, os.ListTypesOutput)
71
72 count := 0
73 err := ListTypes(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
74 count++
75 actual, err := os.ExtractResourceTypes(page)
76 th.AssertNoErr(t, err)
77
78 th.CheckDeepEquals(t, os.ListTypesExpected, actual)
79
80 return true, nil
81 })
82 th.AssertNoErr(t, err)
83 th.CheckEquals(t, 1, count)
84}
Jon Perritt1d4aca02015-02-06 12:29:16 -070085
86func TestGetResourceSchema(t *testing.T) {
87 th.SetupHTTP()
88 defer th.TeardownHTTP()
89 os.HandleGetSchemaSuccessfully(t, os.GetSchemaOutput)
90
91 actual, err := Schema(fake.ServiceClient(), "OS::Heat::AResourceName").Extract()
92 th.AssertNoErr(t, err)
93
94 expected := os.GetSchemaExpected
95 th.AssertDeepEquals(t, expected, actual)
96}