blob: 6768927e71f4f1844151581650b19b1d9c82f4a3 [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 Perrittf050a4c2014-09-11 15:01:17 -050010)
11
12func TestAccounts(t *testing.T) {
Jon Perrittc81fa8f2014-09-15 23:12:26 -050013 // Create a provider client for making the HTTP requests.
14 // See common.go in this directory for more information.
Jon Perrittf050a4c2014-09-11 15:01:17 -050015 client, err := newClient()
16 if err != nil {
17 t.Error(err)
18 return
19 }
20
Jon Perrittc81fa8f2014-09-15 23:12:26 -050021 // Update an account's metadata.
Jon Perrittf050a4c2014-09-11 15:01:17 -050022 err = accounts.Update(client, accounts.UpdateOpts{
23 Metadata: metadata,
24 })
25 if err != nil {
26 t.Error(err)
27 return
28 }
Jon Perrittc81fa8f2014-09-15 23:12:26 -050029 // Defer the deletion of the metadata set above.
Jon Perrittf050a4c2014-09-11 15:01:17 -050030 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 Perrittc81fa8f2014-09-15 23:12:26 -050044 // Retrieve account metadata.
Jon Perrittf050a4c2014-09-11 15:01:17 -050045 gr, err := accounts.Get(client, accounts.GetOpts{})
46 if err != nil {
47 t.Error(err)
48 return
49 }
Jon Perrittc81fa8f2014-09-15 23:12:26 -050050 // Extract the custom metadata from the 'Get' response.
Jon Perrittf050a4c2014-09-11 15:01:17 -050051 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}