Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 1 | package accounts |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/rackspace/gophercloud" |
| 8 | "github.com/rackspace/gophercloud/testhelper" |
| 9 | ) |
| 10 | |
| 11 | const tokenId = "abcabcabcabc" |
| 12 | |
| 13 | var metadata = map[string]string{"gophercloud-test": "accounts"} |
| 14 | |
| 15 | func serviceClient() *gophercloud.ServiceClient { |
| 16 | return &gophercloud.ServiceClient{ |
| 17 | Provider: &gophercloud.ProviderClient{TokenID: tokenId}, |
| 18 | Endpoint: testhelper.Endpoint(), |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | func 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 | |
| 40 | func 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 | } |