blob: a4c4c8282e0b09a480288ebaaf6f8953c733096d [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"
Ash Wilson407cfa32014-10-22 09:21:37 -040010 "github.com/rackspace/gophercloud/testhelper/client"
Jon Perritt036c9442014-10-07 11:40:58 -050011)
12
13func 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 Wilson407cfa32014-10-22 09:21:37 -040031 err := WaitForStatus(client.ServiceClient(), "1234", "available", 0)
Jon Perritt036c9442014-10-07 11:40:58 -050032 if err == nil {
33 t.Errorf("Expected error: 'Time Out in WaitFor'")
34 }
35
Ash Wilson407cfa32014-10-22 09:21:37 -040036 err = WaitForStatus(client.ServiceClient(), "1234", "available", 3)
Jon Perritt036c9442014-10-07 11:40:58 -050037 th.CheckNoErr(t, err)
38}