blob: 5a29235fb6b2a44e4fa3e4c048dd67753635f0ac [file] [log] [blame]
Jon Perrittf050a4c2014-09-11 15:01:17 -05001// +build acceptance
2
3package v1
4
5import (
6 "strings"
7 "testing"
8
Jon Perritt27249f42016-02-18 10:35:59 -06009 "github.com/gophercloud/gophercloud/openstack/objectstorage/v1/accounts"
10 th "github.com/gophercloud/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})
Jon Perritt63e7a482014-12-04 09:47:23 -070020 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 Perritt2a7797d2014-10-21 15:08:43 -050024
Jon Perrittc81fa8f2014-09-15 23:12:26 -050025 // Defer the deletion of the metadata set above.
Jon Perrittf050a4c2014-09-11 15:01:17 -050026 defer func() {
27 tempMap := make(map[string]string)
28 for k := range metadata {
29 tempMap[k] = ""
30 }
Jon Perritt2b36fa32014-10-24 15:44:23 -050031 updateres = accounts.Update(client, accounts.UpdateOpts{Metadata: tempMap})
32 th.AssertNoErr(t, updateres.Err)
Jon Perrittf050a4c2014-09-11 15:01:17 -050033 }()
34
Jon Perrittc81fa8f2014-09-15 23:12:26 -050035 // Extract the custom metadata from the 'Get' response.
Jon Perrittae06ab72014-11-06 18:18:55 -060036 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 Perritt2b36fa32014-10-24 15:44:23 -050043 th.AssertNoErr(t, err)
Jon Perrittf050a4c2014-09-11 15:01:17 -050044 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}