Ash Wilson | 93757df | 2014-10-21 09:36:27 -0400 | [diff] [blame] | 1 | package servers |
| 2 | |
| 3 | import ( |
| 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 | |
| 13 | func 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 | } |