blob: 7932873827a82673407342f486cd7543e48d873a [file] [log] [blame]
Jon Perritta065da12015-02-06 10:20:16 -07001package stackresources
2
3import (
Pratik Mallya827c03e2015-09-17 00:10:47 -05004 "sort"
Jon Perritta065da12015-02-06 10:20:16 -07005 "testing"
6
Jon Perritt27249f42016-02-18 10:35:59 -06007 "github.com/gophercloud/gophercloud/pagination"
8 th "github.com/gophercloud/gophercloud/testhelper"
9 fake "github.com/gophercloud/gophercloud/testhelper/client"
Jon Perritta065da12015-02-06 10:20:16 -070010)
11
12func TestFindResources(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15 HandleFindSuccessfully(t, FindOutput)
16
17 actual, err := Find(fake.ServiceClient(), "hello_world").Extract()
18 th.AssertNoErr(t, err)
19
20 expected := FindExpected
21 th.AssertDeepEquals(t, expected, actual)
22}
23
24func TestListResources(t *testing.T) {
25 th.SetupHTTP()
26 defer th.TeardownHTTP()
27 HandleListSuccessfully(t, 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 := ExtractResources(page)
33 th.AssertNoErr(t, err)
34
35 th.CheckDeepEquals(t, 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 HandleGetSuccessfully(t, 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 := GetExpected
52 th.AssertDeepEquals(t, expected, actual)
53}
54
55func TestResourceMetadata(t *testing.T) {
56 th.SetupHTTP()
57 defer th.TeardownHTTP()
58 HandleMetadataSuccessfully(t, 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 := MetadataExpected
64 th.AssertDeepEquals(t, expected, actual)
65}
66
67func TestListResourceTypes(t *testing.T) {
68 th.SetupHTTP()
69 defer th.TeardownHTTP()
70 HandleListTypesSuccessfully(t, ListTypesOutput)
71
72 count := 0
73 err := ListTypes(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
74 count++
75 actual, err := ExtractResourceTypes(page)
76 th.AssertNoErr(t, err)
77
78 th.CheckDeepEquals(t, ListTypesExpected, actual)
Pratik Mallya827c03e2015-09-17 00:10:47 -050079 // test if sorting works
80 sort.Sort(actual)
81 th.CheckDeepEquals(t, SortedListTypesExpected, actual)
Jon Perritta065da12015-02-06 10:20:16 -070082
83 return true, nil
84 })
85 th.AssertNoErr(t, err)
86 th.CheckEquals(t, 1, count)
87}
Jon Perritt1d4aca02015-02-06 12:29:16 -070088
89func TestGetResourceSchema(t *testing.T) {
90 th.SetupHTTP()
91 defer th.TeardownHTTP()
92 HandleGetSchemaSuccessfully(t, GetSchemaOutput)
93
94 actual, err := Schema(fake.ServiceClient(), "OS::Heat::AResourceName").Extract()
95 th.AssertNoErr(t, err)
96
97 expected := GetSchemaExpected
98 th.AssertDeepEquals(t, expected, actual)
99}
Jon Perrittb1e303a2015-02-06 22:15:44 -0700100
101func TestGetResourceTemplate(t *testing.T) {
102 th.SetupHTTP()
103 defer th.TeardownHTTP()
104 HandleGetTemplateSuccessfully(t, GetTemplateOutput)
105
106 actual, err := Template(fake.ServiceClient(), "OS::Heat::AResourceName").Extract()
107 th.AssertNoErr(t, err)
108
109 expected := GetTemplateExpected
Pratik Mallya827c03e2015-09-17 00:10:47 -0500110 th.AssertDeepEquals(t, expected, string(actual))
Jon Perrittb1e303a2015-02-06 22:15:44 -0700111}