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