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