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