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" |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 9 | ) |
| 10 | |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 11 | func TestCreate(t *testing.T) { |
| 12 | th.SetupHTTP() |
| 13 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 14 | HandleCreate(t) |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 15 | |
| 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 | |
| 25 | func TestList(t *testing.T) { |
| 26 | th.SetupHTTP() |
| 27 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 28 | HandleList(t) |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 29 | |
| 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 | |
| 59 | func TestDelete(t *testing.T) { |
| 60 | th.SetupHTTP() |
| 61 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 62 | HandleDelete(t) |
Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame] | 63 | |
| 64 | err := Delete(fake.ServiceClient(), instanceID, "{dbName}").ExtractErr() |
| 65 | th.AssertNoErr(t, err) |
| 66 | } |