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 | |
| 9 | "github.com/rackspace/gophercloud/openstack/storage/v1/accounts" |
| 10 | ) |
| 11 | |
| 12 | func TestAccounts(t *testing.T) { |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame^] | 13 | // Create a provider client for making the HTTP requests. |
| 14 | // See common.go in this directory for more information. |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 15 | client, err := newClient() |
| 16 | if err != nil { |
| 17 | t.Error(err) |
| 18 | return |
| 19 | } |
| 20 | |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame^] | 21 | // Update an account's metadata. |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 22 | err = accounts.Update(client, accounts.UpdateOpts{ |
| 23 | Metadata: metadata, |
| 24 | }) |
| 25 | if err != nil { |
| 26 | t.Error(err) |
| 27 | return |
| 28 | } |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame^] | 29 | // Defer the deletion of the metadata set above. |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 30 | defer func() { |
| 31 | tempMap := make(map[string]string) |
| 32 | for k := range metadata { |
| 33 | tempMap[k] = "" |
| 34 | } |
| 35 | err = accounts.Update(client, accounts.UpdateOpts{ |
| 36 | Metadata: tempMap, |
| 37 | }) |
| 38 | if err != nil { |
| 39 | t.Error(err) |
| 40 | return |
| 41 | } |
| 42 | }() |
| 43 | |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame^] | 44 | // Retrieve account metadata. |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 45 | gr, err := accounts.Get(client, accounts.GetOpts{}) |
| 46 | if err != nil { |
| 47 | t.Error(err) |
| 48 | return |
| 49 | } |
Jon Perritt | c81fa8f | 2014-09-15 23:12:26 -0500 | [diff] [blame^] | 50 | // Extract the custom metadata from the 'Get' response. |
Jon Perritt | f050a4c | 2014-09-11 15:01:17 -0500 | [diff] [blame] | 51 | am := accounts.ExtractMetadata(gr) |
| 52 | for k := range metadata { |
| 53 | if am[k] != metadata[strings.Title(k)] { |
| 54 | t.Errorf("Expected custom metadata with key: %s", k) |
| 55 | return |
| 56 | } |
| 57 | } |
| 58 | } |