add an integration test for uploading data with the client

This commit is contained in:
Marten Seemann
2017-01-16 15:23:23 +07:00
parent f08e00630d
commit 06aa2489ba
2 changed files with 15 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package integrationtests
import (
"bytes"
"io/ioutil"
"net/http"
"os"
@@ -49,4 +50,15 @@ var _ = Describe("Client tests", func() {
Expect(err).ToNot(HaveOccurred())
Expect(body).To(Equal(dataMan.GetData()))
})
It("uploads a file", func() {
dataMan.GenerateData(dataLen)
data := bytes.NewReader(dataMan.GetData())
resp, err := client.Post("https://quic.clemente.io:"+port+"/echo", "text/plain", data)
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(200))
body, err := ioutil.ReadAll(resp.Body)
Expect(err).ToNot(HaveOccurred())
Expect(body).To(Equal(dataMan.GetData()))
})
})

View File

@@ -100,7 +100,9 @@ func setupHTTPHandlers() {
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
defer GinkgoRecover()
_, err := io.Copy(w, r.Body)
body, err := ioutil.ReadAll(r.Body)
Expect(err).NotTo(HaveOccurred())
_, err = w.Write(body)
Expect(err).NotTo(HaveOccurred())
})