blob: e192ae3bd9ea71aa195e319ca76f674e878c4579 [file] [log] [blame]
Ash Wilson93757df2014-10-21 09:36:27 -04001package servers
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7 "time"
8
9 th "github.com/rackspace/gophercloud/testhelper"
10 "github.com/rackspace/gophercloud/testhelper/client"
11)
12
13func TestWaitForStatus(t *testing.T) {
14 th.SetupHTTP()
15 defer th.TeardownHTTP()
16
17 th.Mux.HandleFunc("/servers/4321", func(w http.ResponseWriter, r *http.Request) {
18 time.Sleep(2 * time.Second)
19 w.Header().Add("Content-Type", "application/json")
20 w.WriteHeader(http.StatusOK)
21 fmt.Fprintf(w, `
22 {
23 "server": {
24 "name": "the-server",
25 "id": "4321",
26 "status": "ACTIVE"
27 }
28 }`)
29 })
30
31 err := WaitForStatus(client.ServiceClient(), "4321", "ACTIVE", 0)
32 if err == nil {
33 t.Errorf("Expected error: 'Time Out in WaitFor'")
34 }
35
36 err = WaitForStatus(client.ServiceClient(), "4321", "ACTIVE", 3)
37 th.CheckNoErr(t, err)
38}