blob: 0090eeaf8af37d527a0ae24eea54637de67bfc29 [file] [log] [blame]
Jon Perritt70bba632014-09-13 00:32:32 -05001package accounts
2
3import (
4 "net/http"
5 "testing"
6
Jon Perritt4a59d232014-10-09 20:21:31 -05007 th "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) {
Jon Perritt4a59d232014-10-09 20:21:31 -050014 th.SetupHTTP()
15 defer th.TeardownHTTP()
Jon Perritt70bba632014-09-13 00:32:32 -050016
Jon Perritt4a59d232014-10-09 20:21:31 -050017 th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
18 th.TestMethod(t, r, "POST")
19 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
20 th.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
Jon Perritt4a59d232014-10-09 20:21:31 -050029 options := &UpdateOpts{Metadata: map[string]string{"gophercloud-test": "accounts"}}
30 _, err := Update(fake.ServiceClient(), options).ExtractHeaders()
31 if err != nil {
32 t.Fatalf("Unable to update account: %v", err)
33 }
Jon Perritt70bba632014-09-13 00:32:32 -050034}
35
36func TestGetAccount(t *testing.T) {
Jon Perritt4a59d232014-10-09 20:21:31 -050037 th.SetupHTTP()
38 defer th.TeardownHTTP()
Jon Perritt70bba632014-09-13 00:32:32 -050039
Jon Perritt4a59d232014-10-09 20:21:31 -050040 th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
41 th.TestMethod(t, r, "HEAD")
42 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
43 w.Header().Set("X-Account-Meta-Foo", "bar")
Jon Perritt70bba632014-09-13 00:32:32 -050044 w.WriteHeader(http.StatusNoContent)
45 })
46
Jon Perritt4a59d232014-10-09 20:21:31 -050047 expected := map[string]string{"Foo": "bar"}
48 actual, err := Get(fake.ServiceClient(), &GetOpts{}).ExtractMetadata()
49 if err != nil {
50 t.Fatalf("Unable to get account metadata: %v", err)
51 }
52 th.CheckDeepEquals(t, expected, actual)
Jamie Hannaford93209fe2014-10-10 11:54:19 +020053}