blob: b4ce871c4ad4914789208dc18c4b3168f95d3060 [file] [log] [blame]
Jamie Hannaford82523522015-02-17 16:53:29 +01001package datastores
2
3import (
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
12func TestList(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020015 fixture.SetupHandler(t, "/datastores", "GET", "", ListDSResp, 200)
Jamie Hannaford82523522015-02-17 16:53:29 +010016
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 Hannaford52dbcee2015-10-06 16:09:56 +020027 th.CheckDeepEquals(t, []Datastore{ExampleDatastore}, actual)
Jamie Hannaford82523522015-02-17 16:53:29 +010028
29 return true, nil
30 })
31
32 th.AssertNoErr(t, err)
33 th.AssertEquals(t, 1, pages)
34}
35
36func TestGet(t *testing.T) {
37 th.SetupHTTP()
38 defer th.TeardownHTTP()
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020039 fixture.SetupHandler(t, "/datastores/{dsID}", "GET", "", GetDSResp, 200)
Jamie Hannaford82523522015-02-17 16:53:29 +010040
41 ds, err := Get(fake.ServiceClient(), "{dsID}").Extract()
42 th.AssertNoErr(t, err)
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020043 th.AssertDeepEquals(t, &ExampleDatastore, ds)
Jamie Hannaford82523522015-02-17 16:53:29 +010044}
45
46func TestListVersions(t *testing.T) {
47 th.SetupHTTP()
48 defer th.TeardownHTTP()
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020049 fixture.SetupHandler(t, "/datastores/{dsID}/versions", "GET", "", ListVersionsResp, 200)
Jamie Hannaford82523522015-02-17 16:53:29 +010050
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 Hannaford52dbcee2015-10-06 16:09:56 +020061 th.CheckDeepEquals(t, ExampleVersions, actual)
Jamie Hannaford82523522015-02-17 16:53:29 +010062
63 return true, nil
64 })
65
66 th.AssertNoErr(t, err)
67 th.AssertEquals(t, 1, pages)
68}
69
70func TestGetVersion(t *testing.T) {
71 th.SetupHTTP()
72 defer th.TeardownHTTP()
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020073 fixture.SetupHandler(t, "/datastores/{dsID}/versions/{versionID}", "GET", "", GetVersionResp, 200)
Jamie Hannaford82523522015-02-17 16:53:29 +010074
75 ds, err := GetVersion(fake.ServiceClient(), "{dsID}", "{versionID}").Extract()
76 th.AssertNoErr(t, err)
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020077 th.AssertDeepEquals(t, &ExampleVersion1, ds)
Jamie Hannaford82523522015-02-17 16:53:29 +010078}