blob: 9effe582430d90334b76d7300811aeb1c554d3a0 [file] [log] [blame]
Jon Perrittf050a4c2014-09-11 15:01:17 -05001// +build acceptance
2
3package v1
4
5import (
6 "strings"
7 "testing"
8
Jon Perritta9caabd2014-09-30 13:02:34 -05009 "github.com/rackspace/gophercloud/openstack/objectstorage/v1/accounts"
Jon Perritt2a7797d2014-10-21 15:08:43 -050010 th "github.com/rackspace/gophercloud/testhelper"
Jon Perrittf050a4c2014-09-11 15:01:17 -050011)
12
13func TestAccounts(t *testing.T) {
Jon Perrittc81fa8f2014-09-15 23:12:26 -050014 // Create a provider client for making the HTTP requests.
15 // See common.go in this directory for more information.
Ash Wilson0036cbf2014-10-24 15:29:48 -040016 client := newClient(t)
Jon Perrittf050a4c2014-09-11 15:01:17 -050017
Jon Perrittc81fa8f2014-09-15 23:12:26 -050018 // Update an account's metadata.
Jon Perritt2b36fa32014-10-24 15:44:23 -050019 updateres := accounts.Update(client, accounts.UpdateOpts{Metadata: metadata})
20 th.AssertNoErr(t, updateres.Err)
Jon Perritt2a7797d2014-10-21 15:08:43 -050021
Jon Perrittc81fa8f2014-09-15 23:12:26 -050022 // Defer the deletion of the metadata set above.
Jon Perrittf050a4c2014-09-11 15:01:17 -050023 defer func() {
24 tempMap := make(map[string]string)
25 for k := range metadata {
26 tempMap[k] = ""
27 }
Jon Perritt2b36fa32014-10-24 15:44:23 -050028 updateres = accounts.Update(client, accounts.UpdateOpts{Metadata: tempMap})
29 th.AssertNoErr(t, updateres.Err)
Jon Perrittf050a4c2014-09-11 15:01:17 -050030 }()
31
Jon Perrittc81fa8f2014-09-15 23:12:26 -050032 // Extract the custom metadata from the 'Get' response.
Jon Perrittae06ab72014-11-06 18:18:55 -060033 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 Perritt2b36fa32014-10-24 15:44:23 -050040 th.AssertNoErr(t, err)
Jon Perrittf050a4c2014-09-11 15:01:17 -050041 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}