Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 1 | package stackresources |
| 2 | |
| 3 | import ( |
| 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 | |
| 12 | func 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 | |
| 24 | func 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 | |
| 43 | func 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 | |
| 55 | func 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 | |
| 67 | func 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 Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 85 | |
| 86 | func 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 | } |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame^] | 97 | |
| 98 | func TestGetResourceTemplate(t *testing.T) { |
| 99 | th.SetupHTTP() |
| 100 | defer th.TeardownHTTP() |
| 101 | os.HandleGetTemplateSuccessfully(t, os.GetTemplateOutput) |
| 102 | |
| 103 | actual, err := Template(fake.ServiceClient(), "OS::Heat::AResourceName").Extract() |
| 104 | th.AssertNoErr(t, err) |
| 105 | |
| 106 | expected := os.GetTemplateExpected |
| 107 | th.AssertDeepEquals(t, expected, actual) |
| 108 | } |