Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 1 | package stackresources |
| 2 | |
| 3 | import ( |
Pratik Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 4 | "sort" |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 5 | "testing" |
| 6 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 7 | "github.com/gophercloud/gophercloud/pagination" |
| 8 | th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | fake "github.com/gophercloud/gophercloud/testhelper/client" |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | func 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 | |
| 24 | func 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 | |
| 43 | func 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 | |
| 55 | func 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 | |
| 67 | func 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 Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 79 | // test if sorting works |
| 80 | sort.Sort(actual) |
| 81 | th.CheckDeepEquals(t, SortedListTypesExpected, actual) |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 82 | |
| 83 | return true, nil |
| 84 | }) |
| 85 | th.AssertNoErr(t, err) |
| 86 | th.CheckEquals(t, 1, count) |
| 87 | } |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 88 | |
| 89 | func 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 Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 100 | |
| 101 | func 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 Mallya | 827c03e | 2015-09-17 00:10:47 -0500 | [diff] [blame] | 110 | th.AssertDeepEquals(t, expected, string(actual)) |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 111 | } |