Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 1 | package datastores |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 6 | os "github.com/rackspace/gophercloud/openstack/db/v1/datastores" |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/pagination" |
| 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | "github.com/rackspace/gophercloud/testhelper/fixture" |
| 11 | ) |
| 12 | |
| 13 | func TestList(t *testing.T) { |
| 14 | th.SetupHTTP() |
| 15 | defer th.TeardownHTTP() |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 16 | fixture.SetupHandler(t, "/datastores", "GET", "", os.ListDSResp, 200) |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 17 | |
| 18 | pages := 0 |
| 19 | |
| 20 | err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
| 21 | pages++ |
| 22 | |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 23 | actual, err := os.ExtractDatastores(page) |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 24 | if err != nil { |
| 25 | return false, err |
| 26 | } |
| 27 | |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 28 | th.CheckDeepEquals(t, []os.Datastore{os.ExampleDatastore}, actual) |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 29 | |
| 30 | return true, nil |
| 31 | }) |
| 32 | |
| 33 | th.AssertNoErr(t, err) |
| 34 | th.AssertEquals(t, 1, pages) |
| 35 | } |
| 36 | |
| 37 | func TestGet(t *testing.T) { |
| 38 | th.SetupHTTP() |
| 39 | defer th.TeardownHTTP() |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 40 | fixture.SetupHandler(t, "/datastores/{dsID}", "GET", "", os.GetDSResp, 200) |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 41 | |
| 42 | ds, err := Get(fake.ServiceClient(), "{dsID}").Extract() |
| 43 | th.AssertNoErr(t, err) |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 44 | th.AssertDeepEquals(t, &os.ExampleDatastore, ds) |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | func TestListVersions(t *testing.T) { |
| 48 | th.SetupHTTP() |
| 49 | defer th.TeardownHTTP() |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 50 | fixture.SetupHandler(t, "/datastores/{dsID}/versions", "GET", "", os.ListVersionsResp, 200) |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 51 | |
| 52 | pages := 0 |
| 53 | |
| 54 | err := ListVersions(fake.ServiceClient(), "{dsID}").EachPage(func(page pagination.Page) (bool, error) { |
| 55 | pages++ |
| 56 | |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 57 | actual, err := os.ExtractVersions(page) |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 58 | if err != nil { |
| 59 | return false, err |
| 60 | } |
| 61 | |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 62 | th.CheckDeepEquals(t, os.ExampleVersions, actual) |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 63 | |
| 64 | return true, nil |
| 65 | }) |
| 66 | |
| 67 | th.AssertNoErr(t, err) |
| 68 | th.AssertEquals(t, 1, pages) |
| 69 | } |
| 70 | |
| 71 | func TestGetVersion(t *testing.T) { |
| 72 | th.SetupHTTP() |
| 73 | defer th.TeardownHTTP() |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 74 | fixture.SetupHandler(t, "/datastores/{dsID}/versions/{versionID}", "GET", "", os.GetVersionResp, 200) |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 75 | |
| 76 | ds, err := GetVersion(fake.ServiceClient(), "{dsID}", "{versionID}").Extract() |
| 77 | th.AssertNoErr(t, err) |
Jamie Hannaford | 52dbcee | 2015-10-06 16:09:56 +0200 | [diff] [blame] | 78 | th.AssertDeepEquals(t, &os.ExampleVersion1, ds) |
Jamie Hannaford | 8252352 | 2015-02-17 16:53:29 +0100 | [diff] [blame] | 79 | } |