blob: 8a1b297f22982c958c7ca7c17d167b86424b716c [file] [log] [blame]
Jamie Hannaford1943b382015-02-12 11:50:02 +01001package databases
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"
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +01009)
10
Jamie Hannaford1943b382015-02-12 11:50:02 +010011func TestCreate(t *testing.T) {
12 th.SetupHTTP()
13 defer th.TeardownHTTP()
Jamie Hannaford4a170282015-02-18 14:16:57 +010014 HandleCreate(t)
Jamie Hannaford1943b382015-02-12 11:50:02 +010015
16 opts := BatchCreateOpts{
17 CreateOpts{Name: "testingdb", CharSet: "utf8", Collate: "utf8_general_ci"},
18 CreateOpts{Name: "sampledb"},
19 }
20
21 res := Create(fake.ServiceClient(), instanceID, opts)
22 th.AssertNoErr(t, res.Err)
23}
24
25func TestList(t *testing.T) {
26 th.SetupHTTP()
27 defer th.TeardownHTTP()
Jamie Hannaford4a170282015-02-18 14:16:57 +010028 HandleList(t)
Jamie Hannaford1943b382015-02-12 11:50:02 +010029
30 expectedDBs := []Database{
31 Database{Name: "anotherexampledb"},
32 Database{Name: "exampledb"},
33 Database{Name: "nextround"},
34 Database{Name: "sampledb"},
35 Database{Name: "testingdb"},
36 }
37
38 pages := 0
39 err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
40 pages++
41
42 actual, err := ExtractDBs(page)
43 if err != nil {
44 return false, err
45 }
46
47 th.CheckDeepEquals(t, expectedDBs, actual)
48
49 return true, nil
50 })
51
52 th.AssertNoErr(t, err)
53
54 if pages != 1 {
55 t.Errorf("Expected 1 page, saw %d", pages)
56 }
57}
58
59func TestDelete(t *testing.T) {
60 th.SetupHTTP()
61 defer th.TeardownHTTP()
Jamie Hannaford4a170282015-02-18 14:16:57 +010062 HandleDelete(t)
Jamie Hannaford1943b382015-02-12 11:50:02 +010063
64 err := Delete(fake.ServiceClient(), instanceID, "{dbName}").ExtractErr()
65 th.AssertNoErr(t, err)
66}