Ash Wilson | 6f3162a | 2014-10-20 17:28:36 -0400 | [diff] [blame] | 1 | package flavors |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud/pagination" |
| 9 | th "github.com/rackspace/gophercloud/testhelper" |
| 10 | "github.com/rackspace/gophercloud/testhelper/client" |
| 11 | ) |
| 12 | |
| 13 | func TestListFlavors(t *testing.T) { |
| 14 | th.SetupHTTP() |
| 15 | defer th.TeardownHTTP() |
| 16 | |
| 17 | th.Mux.HandleFunc("/flavors/detail", func(w http.ResponseWriter, r *http.Request) { |
| 18 | th.TestMethod(t, r, "GET") |
| 19 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 20 | |
| 21 | w.Header().Add("Content-Type", "application/json") |
| 22 | r.ParseForm() |
| 23 | marker := r.Form.Get("marker") |
| 24 | switch marker { |
| 25 | case "": |
| 26 | fmt.Fprintf(w, ListOutput) |
| 27 | case "performance1-2": |
| 28 | fmt.Fprintf(w, `{ "flavors": [] }`) |
| 29 | default: |
| 30 | t.Fatalf("Unexpected marker: [%s]", marker) |
| 31 | } |
| 32 | }) |
| 33 | |
| 34 | count := 0 |
Ash Wilson | 8a0e24b | 2014-10-24 14:14:36 -0400 | [diff] [blame] | 35 | err := ListDetail(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { |
Ash Wilson | 6f3162a | 2014-10-20 17:28:36 -0400 | [diff] [blame] | 36 | actual, err := ExtractFlavors(page) |
| 37 | th.AssertNoErr(t, err) |
| 38 | th.CheckDeepEquals(t, ExpectedFlavorSlice, actual) |
| 39 | |
| 40 | count++ |
| 41 | return true, nil |
| 42 | }) |
| 43 | th.AssertNoErr(t, err) |
| 44 | th.CheckEquals(t, 1, count) |
| 45 | } |
Ash Wilson | 9751fed | 2014-10-20 17:32:21 -0400 | [diff] [blame] | 46 | |
| 47 | func TestGetFlavor(t *testing.T) { |
| 48 | th.SetupHTTP() |
| 49 | defer th.TeardownHTTP() |
| 50 | |
| 51 | th.Mux.HandleFunc("/flavors/performance1-1", func(w http.ResponseWriter, r *http.Request) { |
| 52 | th.TestMethod(t, r, "GET") |
| 53 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 54 | |
| 55 | w.Header().Add("Content-Type", "application/json") |
| 56 | fmt.Fprintf(w, GetOutput) |
| 57 | }) |
| 58 | |
| 59 | actual, err := Get(client.ServiceClient(), "performance1-1").Extract() |
| 60 | th.AssertNoErr(t, err) |
| 61 | th.CheckDeepEquals(t, &Performance1Flavor, actual) |
| 62 | } |