Jamie Hannaford | ba1e96c | 2015-02-12 12:50:19 +0100 | [diff] [blame] | 1 | package databases |
| 2 | |
| 3 | import ( |
| 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 | |
| 12 | const instanceID = "{instanceID}" |
| 13 | |
| 14 | func TestCreate(t *testing.T) { |
| 15 | th.SetupHTTP() |
| 16 | defer th.TeardownHTTP() |
| 17 | |
| 18 | os.HandleCreateDBSuccessfully(t, instanceID) |
| 19 | |
| 20 | opts := os.BatchCreateOpts{ |
| 21 | os.CreateOpts{Name: "testingdb", CharSet: "utf8", Collate: "utf8_general_ci"}, |
| 22 | os.CreateOpts{Name: "sampledb"}, |
| 23 | } |
| 24 | |
| 25 | res := Create(fake.ServiceClient(), instanceID, opts) |
| 26 | th.AssertNoErr(t, res.Err) |
| 27 | } |
| 28 | |
| 29 | func TestList(t *testing.T) { |
| 30 | th.SetupHTTP() |
| 31 | defer th.TeardownHTTP() |
| 32 | |
| 33 | os.HandleListDBsSuccessfully(t, instanceID) |
| 34 | |
| 35 | expectedDBs := []os.Database{ |
| 36 | os.Database{Name: "anotherexampledb"}, |
| 37 | os.Database{Name: "exampledb"}, |
| 38 | os.Database{Name: "nextround"}, |
| 39 | os.Database{Name: "sampledb"}, |
| 40 | os.Database{Name: "testingdb"}, |
| 41 | } |
| 42 | |
| 43 | pages := 0 |
| 44 | err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) { |
| 45 | pages++ |
| 46 | |
| 47 | actual, err := os.ExtractDBs(page) |
| 48 | if err != nil { |
| 49 | return false, err |
| 50 | } |
| 51 | |
| 52 | th.CheckDeepEquals(t, expectedDBs, actual) |
| 53 | |
| 54 | return true, nil |
| 55 | }) |
| 56 | |
| 57 | th.AssertNoErr(t, err) |
| 58 | |
| 59 | if pages != 1 { |
| 60 | t.Errorf("Expected 1 page, saw %d", pages) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func TestDelete(t *testing.T) { |
| 65 | th.SetupHTTP() |
| 66 | defer th.TeardownHTTP() |
| 67 | |
| 68 | os.HandleDeleteDBSuccessfully(t, instanceID, "{dbName}") |
| 69 | |
| 70 | err := os.Delete(fake.ServiceClient(), instanceID, "{dbName}").ExtractErr() |
| 71 | th.AssertNoErr(t, err) |
| 72 | } |