blob: 8cb2be864c82e7bc125de25ec59afdc503522f0f [file] [log] [blame]
Jon Perritt70bba632014-09-13 00:32:32 -05001package accounts
2
3import (
4 "net/http"
5 "testing"
6
Jon Perritt70bba632014-09-13 00:32:32 -05007 "github.com/rackspace/gophercloud/testhelper"
Jamie Hannaford496ad132014-10-06 16:20:15 +02008 fake "github.com/rackspace/gophercloud/testhelper/client"
Jon Perritt70bba632014-09-13 00:32:32 -05009)
10
Jon Perritt70bba632014-09-13 00:32:32 -050011var metadata = map[string]string{"gophercloud-test": "accounts"}
12
Jon Perritt70bba632014-09-13 00:32:32 -050013func TestUpdateAccount(t *testing.T) {
14 testhelper.SetupHTTP()
15 defer testhelper.TeardownHTTP()
16
17 testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
18 testhelper.TestMethod(t, r, "POST")
Jamie Hannaford496ad132014-10-06 16:20:15 +020019 testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jon Perritt70bba632014-09-13 00:32:32 -050020 testhelper.TestHeader(t, r, "X-Account-Meta-Gophercloud-Test", "accounts")
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020021
22 w.Header().Set("X-Account-Container-Count", "2")
23 w.Header().Set("X-Account-Bytes-Used", "14")
24 w.Header().Set("X-Account-Meta-Subject", "books")
25
Jon Perritt70bba632014-09-13 00:32:32 -050026 w.WriteHeader(http.StatusNoContent)
27 })
28
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020029 res := Update(fake.ServiceClient(), UpdateOpts{Metadata: metadata})
30
31 metadata := res.ExtractMetadata()
32 expected := map[string]string{"Subject": "books"}
33
34 testhelper.AssertDeepEquals(t, expected, metadata)
35 testhelper.AssertNoErr(t, res.Err)
Jon Perritt70bba632014-09-13 00:32:32 -050036}
37
38func TestGetAccount(t *testing.T) {
39 testhelper.SetupHTTP()
40 defer testhelper.TeardownHTTP()
41
42 testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
43 testhelper.TestMethod(t, r, "HEAD")
Jamie Hannaford496ad132014-10-06 16:20:15 +020044 testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020045
46 w.Header().Set("X-Account-Container-Count", "2")
47 w.Header().Set("X-Account-Bytes-Used", "14")
48 w.Header().Set("X-Account-Meta-Subject", "books")
49
Jon Perritt70bba632014-09-13 00:32:32 -050050 w.WriteHeader(http.StatusNoContent)
51 })
52
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020053 res := Get(fake.ServiceClient(), GetOpts{})
Jamie Hannaford93209fe2014-10-10 11:54:19 +020054
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020055 metadata := res.ExtractMetadata()
56 expected := map[string]string{"Subject": "books"}
Jamie Hannaford93209fe2014-10-10 11:54:19 +020057
Jamie Hannafordb2e129d2014-10-10 14:06:28 +020058 testhelper.AssertDeepEquals(t, expected, metadata)
59 testhelper.AssertNoErr(t, res.Err)
Jamie Hannaford93209fe2014-10-10 11:54:19 +020060}