github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/imageservice/v2/imagedata/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "io/ioutil" 5 "net/http" 6 "testing" 7 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 fakeclient "github.com/huaweicloud/golangsdk/testhelper/client" 10 ) 11 12 // HandlePutImageDataSuccessfully setup 13 func 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 // HandleStageImageDataSuccessfully setup 30 func HandleStageImageDataSuccessfully(t *testing.T) { 31 th.Mux.HandleFunc("/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea/stage", func(w http.ResponseWriter, r *http.Request) { 32 th.TestMethod(t, r, "PUT") 33 th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) 34 35 b, err := ioutil.ReadAll(r.Body) 36 if err != nil { 37 t.Errorf("Unable to read request body: %v", err) 38 } 39 40 th.AssertByteArrayEquals(t, []byte{5, 3, 7, 24}, b) 41 42 w.WriteHeader(http.StatusNoContent) 43 }) 44 } 45 46 // HandleGetImageDataSuccessfully setup 47 func HandleGetImageDataSuccessfully(t *testing.T) { 48 th.Mux.HandleFunc("/images/da3b75d9-3f4a-40e7-8a2c-bfab23927dea/file", func(w http.ResponseWriter, r *http.Request) { 49 th.TestMethod(t, r, "GET") 50 th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID) 51 52 w.WriteHeader(http.StatusOK) 53 54 _, err := w.Write([]byte{34, 87, 0, 23, 23, 23, 56, 255, 254, 0}) 55 th.AssertNoErr(t, err) 56 }) 57 }