blob: 24ef3b6190c4911ae70dcb0c5feb76a647795fb8 [file] [log] [blame]
Jon Perrittda086712014-10-07 11:59:44 -05001package volumes
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7 "time"
8
9 th "github.com/rackspace/gophercloud/testhelper"
Ash Wilson407cfa32014-10-22 09:21:37 -040010 "github.com/rackspace/gophercloud/testhelper/client"
Jon Perrittda086712014-10-07 11:59:44 -050011)
12
13func TestWaitForStatus(t *testing.T) {
14 th.SetupHTTP()
15 defer th.TeardownHTTP()
16
17 th.Mux.HandleFunc("/volumes/1234", func(w http.ResponseWriter, r *http.Request) {
Jon Perritt4a420842014-10-23 13:09:05 -050018 time.Sleep(3 * time.Second)
Jon Perrittda086712014-10-07 11:59:44 -050019 w.Header().Add("Content-Type", "application/json")
20 w.WriteHeader(http.StatusOK)
21 fmt.Fprintf(w, `
22 {
23 "volume": {
24 "display_name": "vol-001",
25 "id": "1234",
26 "status":"available"
27 }
28 }`)
29 })
30
Ash Wilson407cfa32014-10-22 09:21:37 -040031 err := WaitForStatus(client.ServiceClient(), "1234", "available", 0)
Jon Perrittda086712014-10-07 11:59:44 -050032 if err == nil {
33 t.Errorf("Expected error: 'Time Out in WaitFor'")
34 }
35
Jon Perritt4a420842014-10-23 13:09:05 -050036 err = WaitForStatus(client.ServiceClient(), "1234", "available", 6)
Jon Perrittda086712014-10-07 11:59:44 -050037 th.CheckNoErr(t, err)
38}