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 | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 7 | th "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) { |
Jon Perritt | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 14 | th.SetupHTTP() |
| 15 | defer th.TeardownHTTP() |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 16 | |
Jon Perritt | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 17 | th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 18 | th.TestMethod(t, r, "POST") |
| 19 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 20 | th.TestHeader(t, r, "X-Account-Meta-Gophercloud-Test", "accounts") |
Jamie Hannaford | b2e129d | 2014-10-10 14:06:28 +0200 | [diff] [blame] | 21 | |
| 22 | w.Header().Set("X-Account-Container-Count", "2") |
| 23 | w.Header().Set("X-Account-Bytes-Used", "14") |
| 24 | w.Header().Set("X-Account-Meta-Subject", "books") |
| 25 | |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 26 | w.WriteHeader(http.StatusNoContent) |
| 27 | }) |
| 28 | |
Jon Perritt | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 29 | options := &UpdateOpts{Metadata: map[string]string{"gophercloud-test": "accounts"}} |
| 30 | _, err := Update(fake.ServiceClient(), options).ExtractHeaders() |
| 31 | if err != nil { |
| 32 | t.Fatalf("Unable to update account: %v", err) |
| 33 | } |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | func TestGetAccount(t *testing.T) { |
Jon Perritt | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 37 | th.SetupHTTP() |
| 38 | defer th.TeardownHTTP() |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 39 | |
Jon Perritt | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 40 | th.Mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 41 | th.TestMethod(t, r, "HEAD") |
| 42 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 43 | w.Header().Set("X-Account-Meta-Foo", "bar") |
Jon Perritt | 70bba63 | 2014-09-13 00:32:32 -0500 | [diff] [blame] | 44 | w.WriteHeader(http.StatusNoContent) |
| 45 | }) |
| 46 | |
Jon Perritt | 4a59d23 | 2014-10-09 20:21:31 -0500 | [diff] [blame] | 47 | expected := map[string]string{"Foo": "bar"} |
| 48 | actual, err := Get(fake.ServiceClient(), &GetOpts{}).ExtractMetadata() |
| 49 | if err != nil { |
| 50 | t.Fatalf("Unable to get account metadata: %v", err) |
| 51 | } |
| 52 | th.CheckDeepEquals(t, expected, actual) |
Jamie Hannaford | 93209fe | 2014-10-10 11:54:19 +0200 | [diff] [blame] | 53 | } |