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