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. |
Ash Wilson | 0036cbf | 2014-10-24 15:29:48 -0400 | [diff] [blame] | 16 | client := newClient(t) |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 17 | |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame] | 18 | // Update an account's metadata. |
Jon Perritt | 2b36fa3 | 2014-10-24 15:44:23 -0500 | [diff] [blame] | 19 | updateres := accounts.Update(client, accounts.UpdateOpts{Metadata: metadata}) |
| 20 | th.AssertNoErr(t, updateres.Err) |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 21 | |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame] | 22 | // Defer the deletion of the metadata set above. |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 23 | defer func() { |
| 24 | tempMap := make(map[string]string) |
| 25 | for k := range metadata { |
| 26 | tempMap[k] = "" |
| 27 | } |
Jon Perritt | 2b36fa3 | 2014-10-24 15:44:23 -0500 | [diff] [blame] | 28 | updateres = accounts.Update(client, accounts.UpdateOpts{Metadata: tempMap}) |
| 29 | th.AssertNoErr(t, updateres.Err) |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 30 | }() |
| 31 | |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame] | 32 | // Extract the custom metadata from the 'Get' response. |
Jon Perritt | ae06ab7 | 2014-11-06 18:18:55 -0600 | [diff] [blame^] | 33 | res := accounts.Get(client, nil) |
| 34 | |
| 35 | h, err := res.Extract() |
| 36 | th.AssertNoErr(t, err) |
| 37 | t.Logf("Get Account Response Headers: %+v\n", h) |
| 38 | |
| 39 | am, err := res.ExtractMetadata() |
Jon Perritt | 2b36fa3 | 2014-10-24 15:44:23 -0500 | [diff] [blame] | 40 | th.AssertNoErr(t, err) |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 41 | for k := range metadata { |
| 42 | if am[k] != metadata[strings.Title(k)] { |
| 43 | t.Errorf("Expected custom metadata with key: %s", k) |
| 44 | return |
| 45 | } |
| 46 | } |
| 47 | } |