blob: b55f2a65285ab84fd2fdd186f86accac0e62d936 [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.
Jon Perrittf050a4c2014-09-11 15:01:17 -050016 client, err := newClient()
Jon Perritt2a7797d2014-10-21 15:08:43 -050017 th.AssertNoErr(t, err)
Jon Perrittf050a4c2014-09-11 15:01:17 -050018
Jon Perrittc81fa8f2014-09-15 23:12:26 -050019 // Update an account's metadata.
Jon Perritt2a7797d2014-10-21 15:08:43 -050020 res = accounts.Update(client, accounts.UpdateOpts{Metadata: metadata})
21 th.AssertNoErr(t, res.Err)
22
Jon Perrittc81fa8f2014-09-15 23:12:26 -050023 // Defer the deletion of the metadata set above.
Jon Perrittf050a4c2014-09-11 15:01:17 -050024 defer func() {
25 tempMap := make(map[string]string)
26 for k := range metadata {
27 tempMap[k] = ""
28 }
Jon Perritt2a7797d2014-10-21 15:08:43 -050029 res = accounts.Update(client, accounts.UpdateOpts{Metadata: tempMap})
30 th.AssertNoErr(t, res.Err)
Jon Perrittf050a4c2014-09-11 15:01:17 -050031 }()
32
Jon Perrittc81fa8f2014-09-15 23:12:26 -050033 // Retrieve account metadata.
Jon Perritt2a7797d2014-10-21 15:08:43 -050034 res := accounts.Get(client, accounts.GetOpts{})
35 th.AssertNoErr(res.Err)
Jon Perrittc81fa8f2014-09-15 23:12:26 -050036 // Extract the custom metadata from the 'Get' response.
Jon Perrittf050a4c2014-09-11 15:01:17 -050037 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}