blob: ae9524fe3c9dd9e4c257ef5726d13f4a4cfafcac [file] [log] [blame]
Jon Perritt70bba632014-09-13 00:32:32 -05001package accounts
2
3import (
4 "net/http"
Jamie Hannaford93209fe2014-10-10 11:54:19 +02005 "reflect"
Jon Perritt70bba632014-09-13 00:32:32 -05006 "testing"
7
Jon Perritt70bba632014-09-13 00:32:32 -05008 "github.com/rackspace/gophercloud/testhelper"
Jamie Hannaford496ad132014-10-06 16:20:15 +02009 fake "github.com/rackspace/gophercloud/testhelper/client"
Jon Perritt70bba632014-09-13 00:32:32 -050010)
11
Jon Perritt70bba632014-09-13 00:32:32 -050012var metadata = map[string]string{"gophercloud-test": "accounts"}
13
Jon Perritt70bba632014-09-13 00:32:32 -050014func TestUpdateAccount(t *testing.T) {
15 testhelper.SetupHTTP()
16 defer testhelper.TeardownHTTP()
17
18 testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
19 testhelper.TestMethod(t, r, "POST")
Jamie Hannaford496ad132014-10-06 16:20:15 +020020 testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jon Perritt70bba632014-09-13 00:32:32 -050021 testhelper.TestHeader(t, r, "X-Account-Meta-Gophercloud-Test", "accounts")
22 w.WriteHeader(http.StatusNoContent)
23 })
24
Jamie Hannaford496ad132014-10-06 16:20:15 +020025 err := Update(fake.ServiceClient(), UpdateOpts{Metadata: metadata})
Jon Perritt70bba632014-09-13 00:32:32 -050026 if err != nil {
27 t.Fatalf("Unable to update account: %v", err)
28 }
29}
30
31func TestGetAccount(t *testing.T) {
32 testhelper.SetupHTTP()
33 defer testhelper.TeardownHTTP()
34
35 testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
36 testhelper.TestMethod(t, r, "HEAD")
Jamie Hannaford496ad132014-10-06 16:20:15 +020037 testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
Jon Perritt70bba632014-09-13 00:32:32 -050038 w.WriteHeader(http.StatusNoContent)
39 })
40
Jamie Hannaford496ad132014-10-06 16:20:15 +020041 _, err := Get(fake.ServiceClient(), GetOpts{})
Jon Perritt70bba632014-09-13 00:32:32 -050042 if err != nil {
43 t.Fatalf("Unable to get account metadata: %v", err)
44 }
45}
Jamie Hannaford93209fe2014-10-10 11:54:19 +020046
47func TestExtractAccountMetadata(t *testing.T) {
48 getResult := &http.Response{}
49
50 expected := map[string]string{}
51
52 actual := ExtractMetadata(getResult)
53
54 if !reflect.DeepEqual(expected, actual) {
55 t.Errorf("Expected: %+v\nActual:%+v", expected, actual)
56 }
57}