Jon Perritt | 036c944 | 2014-10-07 11:40:58 -0500 | [diff] [blame] | 1 | package snapshots |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | "time" |
| 8 | |
| 9 | th "github.com/rackspace/gophercloud/testhelper" |
Ash Wilson | 407cfa3 | 2014-10-22 09:21:37 -0400 | [diff] [blame] | 10 | "github.com/rackspace/gophercloud/testhelper/client" |
Jon Perritt | 036c944 | 2014-10-07 11:40:58 -0500 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func TestWaitForStatus(t *testing.T) { |
| 14 | th.SetupHTTP() |
| 15 | defer th.TeardownHTTP() |
| 16 | |
| 17 | th.Mux.HandleFunc("/snapshots/1234", 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 | "snapshot": { |
| 24 | "display_name": "snapshot-001", |
| 25 | "id": "1234", |
| 26 | "status":"available" |
| 27 | } |
| 28 | }`) |
| 29 | }) |
| 30 | |
Ash Wilson | 407cfa3 | 2014-10-22 09:21:37 -0400 | [diff] [blame] | 31 | err := WaitForStatus(client.ServiceClient(), "1234", "available", 0) |
Jon Perritt | 036c944 | 2014-10-07 11:40:58 -0500 | [diff] [blame] | 32 | if err == nil { |
| 33 | t.Errorf("Expected error: 'Time Out in WaitFor'") |
| 34 | } |
| 35 | |
Ash Wilson | 407cfa3 | 2014-10-22 09:21:37 -0400 | [diff] [blame] | 36 | err = WaitForStatus(client.ServiceClient(), "1234", "available", 3) |
Jon Perritt | 036c944 | 2014-10-07 11:40:58 -0500 | [diff] [blame] | 37 | th.CheckNoErr(t, err) |
| 38 | } |