Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 1 | package accounts |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | "testing" |
| 6 | |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/testhelper" |
Jamie Hannaford | 496ad13 | 2014-10-06 16:20:15 +0200 | [diff] [blame] | 8 | fake "github.com/rackspace/gophercloud/testhelper/client" |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 9 | ) |
| 10 | |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 11 | var metadata = map[string]string{"gophercloud-test": "accounts"} |
| 12 | |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 13 | func 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 Hannaford | 496ad13 | 2014-10-06 16:20:15 +0200 | [diff] [blame] | 19 | testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 20 | testhelper.TestHeader(t, r, "X-Account-Meta-Gophercloud-Test", "accounts") |
| 21 | w.WriteHeader(http.StatusNoContent) |
| 22 | }) |
| 23 | |
Jamie Hannaford | 496ad13 | 2014-10-06 16:20:15 +0200 | [diff] [blame] | 24 | err := Update(fake.ServiceClient(), UpdateOpts{Metadata: metadata}) |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 25 | if err != nil { |
| 26 | t.Fatalf("Unable to update account: %v", err) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | func 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 Hannaford | 496ad13 | 2014-10-06 16:20:15 +0200 | [diff] [blame] | 36 | testhelper.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 37 | w.WriteHeader(http.StatusNoContent) |
| 38 | }) |
| 39 | |
Jamie Hannaford | 496ad13 | 2014-10-06 16:20:15 +0200 | [diff] [blame] | 40 | _, err := Get(fake.ServiceClient(), GetOpts{}) |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 41 | if err != nil { |
| 42 | t.Fatalf("Unable to get account metadata: %v", err) |
| 43 | } |
| 44 | } |