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