Ash Wilson | ad21c71 | 2014-09-25 10:15:22 -0400 | [diff] [blame^] | 1 | package servers |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | "github.com/rackspace/gophercloud/pagination" |
| 10 | "github.com/rackspace/gophercloud/testhelper" |
| 11 | ) |
| 12 | |
| 13 | const tokenID = "bzbzbzbzbz" |
| 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 TestListServers(t *testing.T) { |
| 23 | testhelper.SetupHTTP() |
| 24 | defer testhelper.TeardownHTTP() |
| 25 | |
| 26 | testhelper.Mux.HandleFunc("/servers/detail", func(w http.ResponseWriter, r *http.Request) { |
| 27 | testhelper.TestMethod(t, r, "GET") |
| 28 | testhelper.TestHeader(t, r, "X-Auth-Token", tokenID) |
| 29 | |
| 30 | w.Header().Add("Content-Type", "application/json") |
| 31 | r.ParseForm() |
| 32 | marker := r.Form.Get("marker") |
| 33 | switch marker { |
| 34 | case "": |
| 35 | fmt.Fprintf(w, serverListBody) |
| 36 | case "9e5476bd-a4ec-4653-93d6-72c93aa682ba": |
| 37 | fmt.Fprintf(w, `{ "servers": [] }`) |
| 38 | default: |
| 39 | t.Fatalf("/servers/detail invoked with unexpected marker=[%s]", marker) |
| 40 | } |
| 41 | }) |
| 42 | |
| 43 | client := serviceClient() |
| 44 | pages := 0 |
| 45 | err := List(client).EachPage(func(page pagination.Page) (bool, error) { |
| 46 | pages++ |
| 47 | |
| 48 | actual, err := ExtractServers(page) |
| 49 | if err != nil { |
| 50 | return false, err |
| 51 | } |
| 52 | |
| 53 | if len(actual) != 2 { |
| 54 | t.Fatalf("Expected 2 servers, got %d", len(actual)) |
| 55 | } |
| 56 | equalServers(t, serverHerp, actual[0]) |
| 57 | equalServers(t, serverDerp, actual[1]) |
| 58 | |
| 59 | return true, nil |
| 60 | }) |
| 61 | |
| 62 | if err != nil { |
| 63 | t.Fatalf("Unexpected error from EachPage: %v", err) |
| 64 | } |
| 65 | if pages != 1 { |
| 66 | t.Errorf("Expected 1 page, saw %d", pages) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func TestCreateServer(t *testing.T) { |
| 71 | testhelper.SetupHTTP() |
| 72 | defer testhelper.TeardownHTTP() |
| 73 | t.Error("Pending") |
| 74 | } |
| 75 | |
| 76 | func TestDeleteServer(t *testing.T) { |
| 77 | testhelper.SetupHTTP() |
| 78 | defer testhelper.TeardownHTTP() |
| 79 | t.Error("Pending") |
| 80 | } |
| 81 | |
| 82 | func TestGetServer(t *testing.T) { |
| 83 | testhelper.SetupHTTP() |
| 84 | defer testhelper.TeardownHTTP() |
| 85 | t.Error("Pending") |
| 86 | } |
| 87 | |
| 88 | func TestUpdateServer(t *testing.T) { |
| 89 | testhelper.SetupHTTP() |
| 90 | defer testhelper.TeardownHTTP() |
| 91 | t.Error("Pending") |
| 92 | } |
| 93 | |
| 94 | func TestChangeServerAdminPassword(t *testing.T) { |
| 95 | testhelper.SetupHTTP() |
| 96 | defer testhelper.TeardownHTTP() |
| 97 | t.Error("Pending") |
| 98 | } |
| 99 | |
| 100 | func TestRebootServer(t *testing.T) { |
| 101 | testhelper.SetupHTTP() |
| 102 | defer testhelper.TeardownHTTP() |
| 103 | t.Error("Pending") |
| 104 | } |
| 105 | |
| 106 | func TestRebuildServer(t *testing.T) { |
| 107 | testhelper.SetupHTTP() |
| 108 | defer testhelper.TeardownHTTP() |
| 109 | t.Error("Pending") |
| 110 | } |
| 111 | |
| 112 | func TestResizeServer(t *testing.T) { |
| 113 | testhelper.SetupHTTP() |
| 114 | defer testhelper.TeardownHTTP() |
| 115 | t.Error("Pending") |
| 116 | } |
| 117 | |
| 118 | func TestConfirmResize(t *testing.T) { |
| 119 | testhelper.SetupHTTP() |
| 120 | defer testhelper.TeardownHTTP() |
| 121 | t.Error("Pending") |
| 122 | } |
| 123 | |
| 124 | func TestRevertResize(t *testing.T) { |
| 125 | testhelper.SetupHTTP() |
| 126 | defer testhelper.TeardownHTTP() |
| 127 | t.Error("Pending") |
| 128 | } |