blob: f7c01a7c118906202f9a5b9b43a8a5a99261357c [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 // Retrieve account metadata.
Jon Perritt2b36fa32014-10-24 15:44:23 -050033 getres := accounts.Get(client, nil)
34 th.AssertNoErr(t, getres.Err)
Jon Perrittc81fa8f2014-09-15 23:12:26 -050035 // Extract the custom metadata from the 'Get' response.
Jon Perritt2b36fa32014-10-24 15:44:23 -050036 am, err := getres.ExtractMetadata()
37 th.AssertNoErr(t, err)
Jon Perrittf050a4c2014-09-11 15:01:17 -050038 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}