blob: 71111b96571440d9b76706553a430a1898994c18 [file] [log] [blame]
Jamie Hannaford82523522015-02-17 16:53:29 +01001package datastores
2
3import (
4 "testing"
5
Jamie Hannaford52dbcee2015-10-06 16:09:56 +02006 os "github.com/rackspace/gophercloud/openstack/db/v1/datastores"
Jamie Hannaford82523522015-02-17 16:53:29 +01007 "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
13func TestList(t *testing.T) {
14 th.SetupHTTP()
15 defer th.TeardownHTTP()
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020016 fixture.SetupHandler(t, "/datastores", "GET", "", os.ListDSResp, 200)
Jamie Hannaford82523522015-02-17 16:53:29 +010017
18 pages := 0
19
20 err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
21 pages++
22
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020023 actual, err := os.ExtractDatastores(page)
Jamie Hannaford82523522015-02-17 16:53:29 +010024 if err != nil {
25 return false, err
26 }
27
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020028 th.CheckDeepEquals(t, []os.Datastore{os.ExampleDatastore}, actual)
Jamie Hannaford82523522015-02-17 16:53:29 +010029
30 return true, nil
31 })
32
33 th.AssertNoErr(t, err)
34 th.AssertEquals(t, 1, pages)
35}
36
37func TestGet(t *testing.T) {
38 th.SetupHTTP()
39 defer th.TeardownHTTP()
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020040 fixture.SetupHandler(t, "/datastores/{dsID}", "GET", "", os.GetDSResp, 200)
Jamie Hannaford82523522015-02-17 16:53:29 +010041
42 ds, err := Get(fake.ServiceClient(), "{dsID}").Extract()
43 th.AssertNoErr(t, err)
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020044 th.AssertDeepEquals(t, &os.ExampleDatastore, ds)
Jamie Hannaford82523522015-02-17 16:53:29 +010045}
46
47func TestListVersions(t *testing.T) {
48 th.SetupHTTP()
49 defer th.TeardownHTTP()
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020050 fixture.SetupHandler(t, "/datastores/{dsID}/versions", "GET", "", os.ListVersionsResp, 200)
Jamie Hannaford82523522015-02-17 16:53:29 +010051
52 pages := 0
53
54 err := ListVersions(fake.ServiceClient(), "{dsID}").EachPage(func(page pagination.Page) (bool, error) {
55 pages++
56
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020057 actual, err := os.ExtractVersions(page)
Jamie Hannaford82523522015-02-17 16:53:29 +010058 if err != nil {
59 return false, err
60 }
61
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020062 th.CheckDeepEquals(t, os.ExampleVersions, actual)
Jamie Hannaford82523522015-02-17 16:53:29 +010063
64 return true, nil
65 })
66
67 th.AssertNoErr(t, err)
68 th.AssertEquals(t, 1, pages)
69}
70
71func TestGetVersion(t *testing.T) {
72 th.SetupHTTP()
73 defer th.TeardownHTTP()
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020074 fixture.SetupHandler(t, "/datastores/{dsID}/versions/{versionID}", "GET", "", os.GetVersionResp, 200)
Jamie Hannaford82523522015-02-17 16:53:29 +010075
76 ds, err := GetVersion(fake.ServiceClient(), "{dsID}", "{versionID}").Extract()
77 th.AssertNoErr(t, err)
Jamie Hannaford52dbcee2015-10-06 16:09:56 +020078 th.AssertDeepEquals(t, &os.ExampleVersion1, ds)
Jamie Hannaford82523522015-02-17 16:53:29 +010079}