Jamie Hannaford | af4570f | 2015-02-12 13:33:25 +0100 | [diff] [blame] | 1 | package users |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | db "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" |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame^] | 10 | "github.com/rackspace/gophercloud/testhelper/fixture" |
Jamie Hannaford | af4570f | 2015-02-12 13:33:25 +0100 | [diff] [blame] | 11 | ) |
| 12 | |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame^] | 13 | var ( |
| 14 | instanceID = "{instanceID}" |
| 15 | _rootURL = "/instances/" + instanceID + "/users" |
| 16 | ) |
Jamie Hannaford | af4570f | 2015-02-12 13:33:25 +0100 | [diff] [blame] | 17 | |
| 18 | func TestCreate(t *testing.T) { |
| 19 | th.SetupHTTP() |
| 20 | defer th.TeardownHTTP() |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame^] | 21 | fixture.SetupHandler(t, _rootURL, "POST", createReq, "", 202) |
Jamie Hannaford | af4570f | 2015-02-12 13:33:25 +0100 | [diff] [blame] | 22 | |
| 23 | opts := BatchCreateOpts{ |
| 24 | CreateOpts{ |
| 25 | Databases: db.BatchCreateOpts{ |
| 26 | db.CreateOpts{Name: "databaseA"}, |
| 27 | }, |
| 28 | Name: "dbuser3", |
| 29 | Password: "secretsecret", |
| 30 | }, |
| 31 | CreateOpts{ |
| 32 | Databases: db.BatchCreateOpts{ |
| 33 | db.CreateOpts{Name: "databaseB"}, |
| 34 | db.CreateOpts{Name: "databaseC"}, |
| 35 | }, |
| 36 | Name: "dbuser4", |
| 37 | Password: "secretsecret", |
| 38 | }, |
| 39 | } |
| 40 | |
| 41 | res := Create(fake.ServiceClient(), instanceID, opts) |
| 42 | th.AssertNoErr(t, res.Err) |
| 43 | } |
| 44 | |
| 45 | func TestUserList(t *testing.T) { |
| 46 | th.SetupHTTP() |
| 47 | defer th.TeardownHTTP() |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame^] | 48 | fixture.SetupHandler(t, _rootURL, "GET", "", listResp, 200) |
Jamie Hannaford | af4570f | 2015-02-12 13:33:25 +0100 | [diff] [blame] | 49 | |
| 50 | expectedUsers := []User{ |
| 51 | User{ |
| 52 | Databases: []db.Database{ |
| 53 | db.Database{Name: "databaseA"}, |
| 54 | }, |
| 55 | Name: "dbuser3", |
| 56 | }, |
| 57 | User{ |
| 58 | Databases: []db.Database{ |
| 59 | db.Database{Name: "databaseB"}, |
| 60 | db.Database{Name: "databaseC"}, |
| 61 | }, |
| 62 | Name: "dbuser4", |
| 63 | }, |
| 64 | } |
| 65 | |
| 66 | pages := 0 |
| 67 | err := List(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) { |
| 68 | pages++ |
| 69 | |
| 70 | actual, err := ExtractUsers(page) |
| 71 | if err != nil { |
| 72 | return false, err |
| 73 | } |
| 74 | |
| 75 | th.CheckDeepEquals(t, expectedUsers, actual) |
Jamie Hannaford | af4570f | 2015-02-12 13:33:25 +0100 | [diff] [blame] | 76 | return true, nil |
| 77 | }) |
| 78 | |
| 79 | th.AssertNoErr(t, err) |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame^] | 80 | th.AssertEquals(t, 1, pages) |
Jamie Hannaford | af4570f | 2015-02-12 13:33:25 +0100 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | func TestDeleteInstance(t *testing.T) { |
| 84 | th.SetupHTTP() |
| 85 | defer th.TeardownHTTP() |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame^] | 86 | fixture.SetupHandler(t, _rootURL+"/{dbName}", "DELETE", "", "", 202) |
Jamie Hannaford | af4570f | 2015-02-12 13:33:25 +0100 | [diff] [blame] | 87 | |
| 88 | res := Delete(fake.ServiceClient(), instanceID, "{dbName}") |
| 89 | th.AssertNoErr(t, res.Err) |
| 90 | } |