blob: 348f93ec8cf2087a7632c66b31b2cdcfe810bb7b [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")
21 w.WriteHeader(http.StatusNoContent)
22 })
23
Jamie Hannaford496ad132014-10-06 16:20:15 +020024 err := Update(fake.ServiceClient(), UpdateOpts{Metadata: metadata})
Jon Perritt70bba632014-09-13 00:32:32 -050025 if err != nil {
26 t.Fatalf("Unable to update account: %v", err)
27 }
28}
29
30func TestGetAccount(t *testing.T) {
31 testhelper.SetupHTTP()
32 defer testhelper.TeardownHTTP()
33
34 testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
35 testhelper.TestMethod(t, r, "HEAD")
Jamie Hannaford496ad132014-10-06 16:20:15 +020036 testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jon Perritt70bba632014-09-13 00:32:32 -050037 w.WriteHeader(http.StatusNoContent)
38 })
39
Jamie Hannaford496ad132014-10-06 16:20:15 +020040 _, err := Get(fake.ServiceClient(), GetOpts{})
Jon Perritt70bba632014-09-13 00:32:32 -050041 if err != nil {
42 t.Fatalf("Unable to get account metadata: %v", err)
43 }
44}