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