Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
Jon Perritt | a9caabd | 2014-09-30 13:02:34 -0500 | [diff] [blame] | 9 | "github.com/rackspace/gophercloud/openstack/objectstorage/v1/accounts" |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame^] | 10 | th "github.com/rackspace/gophercloud/testhelper" |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func TestAccounts(t *testing.T) { |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame] | 14 | // Create a provider client for making the HTTP requests. |
| 15 | // See common.go in this directory for more information. |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 16 | client, err := newClient() |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame^] | 17 | th.AssertNoErr(t, err) |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 18 | |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame] | 19 | // Update an account's metadata. |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame^] | 20 | res = accounts.Update(client, accounts.UpdateOpts{Metadata: metadata}) |
| 21 | th.AssertNoErr(t, res.Err) |
| 22 | |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame] | 23 | // Defer the deletion of the metadata set above. |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 24 | defer func() { |
| 25 | tempMap := make(map[string]string) |
| 26 | for k := range metadata { |
| 27 | tempMap[k] = "" |
| 28 | } |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame^] | 29 | res = accounts.Update(client, accounts.UpdateOpts{Metadata: tempMap}) |
| 30 | th.AssertNoErr(t, res.Err) |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 31 | }() |
| 32 | |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame] | 33 | // Retrieve account metadata. |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame^] | 34 | res := accounts.Get(client, accounts.GetOpts{}) |
| 35 | th.AssertNoErr(res.Err) |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame] | 36 | // Extract the custom metadata from the 'Get' response. |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 37 | am := accounts.ExtractMetadata(gr) |
| 38 | for k := range metadata { |
| 39 | if am[k] != metadata[strings.Title(k)] { |
| 40 | t.Errorf("Expected custom metadata with key: %s", k) |
| 41 | return |
| 42 | } |
| 43 | } |
| 44 | } |