blob: e1450d4d99441a6a355443328c137a870a009c10 [file] [log] [blame]
Jon Perritt70bba632014-09-13 00:32:32 -05001package accounts
2
3import (
4 "net/http"
5 "testing"
6
7 "github.com/rackspace/gophercloud"
8 "github.com/rackspace/gophercloud/testhelper"
9)
10
11const tokenId = "abcabcabcabc"
12
13var metadata = map[string]string{"gophercloud-test": "accounts"}
14
15func serviceClient() *gophercloud.ServiceClient {
16 return &gophercloud.ServiceClient{
17 Provider: &gophercloud.ProviderClient{TokenID: tokenId},
18 Endpoint: testhelper.Endpoint(),
19 }
20}
21
22func TestUpdateAccount(t *testing.T) {
23 testhelper.SetupHTTP()
24 defer testhelper.TeardownHTTP()
25
26 testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
27 testhelper.TestMethod(t, r, "POST")
28 testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
29 testhelper.TestHeader(t, r, "X-Account-Meta-Gophercloud-Test", "accounts")
30 w.WriteHeader(http.StatusNoContent)
31 })
32
33 client := serviceClient()
34 err := Update(client, UpdateOpts{Metadata: metadata})
35 if err != nil {
36 t.Fatalf("Unable to update account: %v", err)
37 }
38}
39
40func TestGetAccount(t *testing.T) {
41 testhelper.SetupHTTP()
42 defer testhelper.TeardownHTTP()
43
44 testhelper.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
45 testhelper.TestMethod(t, r, "HEAD")
46 testhelper.TestHeader(t, r, "X-Auth-Token", tokenId)
47 w.WriteHeader(http.StatusNoContent)
48 })
49
50 client := serviceClient()
51 _, err := Get(client, GetOpts{})
52 if err != nil {
53 t.Fatalf("Unable to get account metadata: %v", err)
54 }
55}