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