blob: a470ffa899f5d1d77a84ebed9af0ae71f91fbd38 [file] [log] [blame]
jrperritt3d966162016-06-06 14:08:54 -05001package testing
2
3import (
4 "testing"
5
6 "github.com/gophercloud/gophercloud/openstack/db/v1/databases"
7 "github.com/gophercloud/gophercloud/pagination"
8 th "github.com/gophercloud/gophercloud/testhelper"
9 fake "github.com/gophercloud/gophercloud/testhelper/client"
10)
11
12func TestCreate(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15 HandleCreate(t)
16
17 opts := databases.BatchCreateOpts{
18 databases.CreateOpts{Name: "testingdb", CharSet: "utf8", Collate: "utf8_general_ci"},
19 databases.CreateOpts{Name: "sampledb"},
20 }
21
22 res := databases.Create(fake.ServiceClient(), instanceID, opts)
23 th.AssertNoErr(t, res.Err)
24}
25
26func TestList(t *testing.T) {
27 th.SetupHTTP()
28 defer th.TeardownHTTP()
29 HandleList(t)
30
31 expectedDBs := []databases.Database{
32 {Name: "anotherexampledb"},
33 {Name: "exampledb"},
34 {Name: "nextround"},
35 {Name: "sampledb"},
36 {Name: "testingdb"},
37 }
38
39 pages := 0
40 err := databases.List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
41 pages++
42
43 actual, err := databases.ExtractDBs(page)
44 if err != nil {
45 return false, err
46 }
47
48 th.CheckDeepEquals(t, expectedDBs, actual)
49
50 return true, nil
51 })
52
53 th.AssertNoErr(t, err)
54
55 if pages != 1 {
56 t.Errorf("Expected 1 page, saw %d", pages)
57 }
58}
59
60func TestDelete(t *testing.T) {
61 th.SetupHTTP()
62 defer th.TeardownHTTP()
63 HandleDelete(t)
64
65 err := databases.Delete(fake.ServiceClient(), instanceID, "{dbName}").ExtractErr()
66 th.AssertNoErr(t, err)
67}