blob: b9e50a53f11b595c69fde507b99ddbd07b5357b5 [file] [log] [blame]
Jamie Hannafordba1e96c2015-02-12 12:50:19 +01001package databases
2
3import (
4 "testing"
5
6 os "github.com/rackspace/gophercloud/openstack/db/v1/databases"
7 "github.com/rackspace/gophercloud/pagination"
8 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
10)
11
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010012var (
13 instanceID = "{instanceID}"
14 rootURL = "/instances"
15 resURL = rootURL + "/" + instanceID
16 uRootURL = resURL + "/root"
17 aURL = resURL + "/action"
18)
Jamie Hannafordba1e96c2015-02-12 12:50:19 +010019
20func TestCreate(t *testing.T) {
21 th.SetupHTTP()
22 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010023 os.HandleCreate(t)
Jamie Hannafordba1e96c2015-02-12 12:50:19 +010024
25 opts := os.BatchCreateOpts{
26 os.CreateOpts{Name: "testingdb", CharSet: "utf8", Collate: "utf8_general_ci"},
27 os.CreateOpts{Name: "sampledb"},
28 }
29
30 res := Create(fake.ServiceClient(), instanceID, opts)
31 th.AssertNoErr(t, res.Err)
32}
33
34func TestList(t *testing.T) {
35 th.SetupHTTP()
36 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010037 os.HandleList(t)
Jamie Hannafordba1e96c2015-02-12 12:50:19 +010038
39 expectedDBs := []os.Database{
40 os.Database{Name: "anotherexampledb"},
41 os.Database{Name: "exampledb"},
42 os.Database{Name: "nextround"},
43 os.Database{Name: "sampledb"},
44 os.Database{Name: "testingdb"},
45 }
46
47 pages := 0
48 err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
49 pages++
50
51 actual, err := os.ExtractDBs(page)
52 if err != nil {
53 return false, err
54 }
55
56 th.CheckDeepEquals(t, expectedDBs, actual)
Jamie Hannafordba1e96c2015-02-12 12:50:19 +010057 return true, nil
58 })
59
60 th.AssertNoErr(t, err)
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010061 th.AssertEquals(t, 1, pages)
Jamie Hannafordba1e96c2015-02-12 12:50:19 +010062}
63
64func TestDelete(t *testing.T) {
65 th.SetupHTTP()
66 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010067 os.HandleDelete(t)
Jamie Hannafordba1e96c2015-02-12 12:50:19 +010068
69 err := os.Delete(fake.ServiceClient(), instanceID, "{dbName}").ExtractErr()
70 th.AssertNoErr(t, err)
71}