blob: fe93fc9730be657463bc480fc61ebd97d374b9ed [file] [log] [blame]
jrperrittc5c590a2016-11-04 14:41:15 -05001package testing
2
3import (
4 "io/ioutil"
5 "net/http"
6 "testing"
7
8 th "github.com/gophercloud/gophercloud/testhelper"
9 fakeclient "github.com/gophercloud/gophercloud/testhelper/client"
10)
11
12// HandlePutImageDataSuccessfully setup
13func HandlePutImageDataSuccessfully(t *testing.T) {
14 th.Mux.HandleFunc("/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea/file", func(w http.ResponseWriter, r *http.Request) {
15 th.TestMethod(t, r, "PUT")
16 th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID)
17
18 b, err := ioutil.ReadAll(r.Body)
19 if err != nil {
20 t.Errorf("Unable to read request body: %v", err)
21 }
22
23 th.AssertByteArrayEquals(t, []byte{5, 3, 7, 24}, b)
24
25 w.WriteHeader(http.StatusNoContent)
26 })
27}
28
29// HandleGetImageDataSuccessfully setup
30func HandleGetImageDataSuccessfully(t *testing.T) {
31 th.Mux.HandleFunc("/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea/file", func(w http.ResponseWriter, r *http.Request) {
32 th.TestMethod(t, r, "GET")
33 th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID)
34
35 w.WriteHeader(http.StatusOK)
36
37 _, err := w.Write([]byte{34, 87, 0, 23, 23, 23, 56, 255, 254, 0})
38 th.AssertNoErr(t, err)
39 })
40}