forked from quic-go/quic-go
use the gbytes.TimeoutReader in integration tests
This commit is contained in:
@@ -7,11 +7,13 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/h2quic"
|
"github.com/lucas-clemente/quic-go/h2quic"
|
||||||
"github.com/lucas-clemente/quic-go/protocol"
|
"github.com/lucas-clemente/quic-go/protocol"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/onsi/gomega/gbytes"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Client tests", func() {
|
var _ = Describe("Client tests", func() {
|
||||||
@@ -43,49 +45,45 @@ var _ = Describe("Client tests", func() {
|
|||||||
protocol.SupportedVersions = []protocol.VersionNumber{version}
|
protocol.SupportedVersions = []protocol.VersionNumber{version}
|
||||||
})
|
})
|
||||||
|
|
||||||
It("downloads a hello", func(done Done) {
|
It("downloads a hello", func() {
|
||||||
resp, err := client.Get("https://quic.clemente.io:" + port + "/hello")
|
resp, err := client.Get("https://quic.clemente.io:" + port + "/hello")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(resp.StatusCode).To(Equal(200))
|
Expect(resp.StatusCode).To(Equal(200))
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 3*time.Second))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(string(body)).To(Equal("Hello, World!\n"))
|
Expect(string(body)).To(Equal("Hello, World!\n"))
|
||||||
close(done)
|
})
|
||||||
}, 3)
|
|
||||||
|
|
||||||
It("downloads a small file", func(done Done) {
|
It("downloads a small file", func() {
|
||||||
dataMan.GenerateData(dataLen)
|
dataMan.GenerateData(dataLen)
|
||||||
resp, err := client.Get("https://quic.clemente.io:" + port + "/data")
|
resp, err := client.Get("https://quic.clemente.io:" + port + "/data")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(resp.StatusCode).To(Equal(200))
|
Expect(resp.StatusCode).To(Equal(200))
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 5*time.Second))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(body).To(Equal(dataMan.GetData()))
|
Expect(body).To(Equal(dataMan.GetData()))
|
||||||
close(done)
|
})
|
||||||
}, 5)
|
|
||||||
|
|
||||||
It("downloads a large file", func(done Done) {
|
It("downloads a large file", func() {
|
||||||
dataMan.GenerateData(dataLongLen)
|
dataMan.GenerateData(dataLongLen)
|
||||||
resp, err := client.Get("https://quic.clemente.io:" + port + "/data")
|
resp, err := client.Get("https://quic.clemente.io:" + port + "/data")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(resp.StatusCode).To(Equal(200))
|
Expect(resp.StatusCode).To(Equal(200))
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 20*time.Second))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(body).To(Equal(dataMan.GetData()))
|
Expect(body).To(Equal(dataMan.GetData()))
|
||||||
close(done)
|
})
|
||||||
}, 20)
|
|
||||||
|
|
||||||
It("uploads a file", func(done Done) {
|
It("uploads a file", func() {
|
||||||
dataMan.GenerateData(dataLen)
|
dataMan.GenerateData(dataLen)
|
||||||
data := bytes.NewReader(dataMan.GetData())
|
data := bytes.NewReader(dataMan.GetData())
|
||||||
resp, err := client.Post("https://quic.clemente.io:"+port+"/echo", "text/plain", data)
|
resp, err := client.Post("https://quic.clemente.io:"+port+"/echo", "text/plain", data)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(resp.StatusCode).To(Equal(200))
|
Expect(resp.StatusCode).To(Equal(200))
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(gbytes.TimeoutReader(resp.Body, 5*time.Second))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(body).To(Equal(dataMan.GetData()))
|
Expect(body).To(Equal(dataMan.GetData()))
|
||||||
close(done)
|
})
|
||||||
}, 5)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/lucas-clemente/quic-go/h2quic"
|
"github.com/lucas-clemente/quic-go/h2quic"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/onsi/gomega/gbytes"
|
||||||
. "github.com/onsi/gomega/gexec"
|
. "github.com/onsi/gomega/gexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -161,7 +162,7 @@ var _ = Describe("Server tests", func() {
|
|||||||
tmpDir = ""
|
tmpDir = ""
|
||||||
})
|
})
|
||||||
|
|
||||||
It("downloads a hello", func(done Done) {
|
It("downloads a hello", func() {
|
||||||
data := []byte("Hello world!\n")
|
data := []byte("Hello world!\n")
|
||||||
createDownloadFile("hello", data)
|
createDownloadFile("hello", data)
|
||||||
|
|
||||||
@@ -171,13 +172,12 @@ var _ = Describe("Server tests", func() {
|
|||||||
rsp, err := client.Get("https://quic.clemente.io:" + serverPort + "/hello")
|
rsp, err := client.Get("https://quic.clemente.io:" + serverPort + "/hello")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(rsp.StatusCode).To(Equal(200))
|
Expect(rsp.StatusCode).To(Equal(200))
|
||||||
body, err := ioutil.ReadAll(rsp.Body)
|
body, err := ioutil.ReadAll(gbytes.TimeoutReader(rsp.Body, 5*time.Second))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(body).To(Equal(data))
|
Expect(body).To(Equal(data))
|
||||||
close(done)
|
})
|
||||||
}, 5)
|
|
||||||
|
|
||||||
It("downloads a small file", func(done Done) {
|
It("downloads a small file", func() {
|
||||||
dataMan.GenerateData(dataLen)
|
dataMan.GenerateData(dataLen)
|
||||||
data := dataMan.GetData()
|
data := dataMan.GetData()
|
||||||
createDownloadFile("file.dat", data)
|
createDownloadFile("file.dat", data)
|
||||||
@@ -188,13 +188,12 @@ var _ = Describe("Server tests", func() {
|
|||||||
rsp, err := client.Get("https://quic.clemente.io:" + serverPort + "/file.dat")
|
rsp, err := client.Get("https://quic.clemente.io:" + serverPort + "/file.dat")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(rsp.StatusCode).To(Equal(200))
|
Expect(rsp.StatusCode).To(Equal(200))
|
||||||
body, err := ioutil.ReadAll(rsp.Body)
|
body, err := ioutil.ReadAll(gbytes.TimeoutReader(rsp.Body, 5*time.Second))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(body).To(Equal(data))
|
Expect(body).To(Equal(data))
|
||||||
close(done)
|
})
|
||||||
}, 5)
|
|
||||||
|
|
||||||
It("downloads a large file", func(done Done) {
|
It("downloads a large file", func() {
|
||||||
dataMan.GenerateData(dataLongLen)
|
dataMan.GenerateData(dataLongLen)
|
||||||
data := dataMan.GetData()
|
data := dataMan.GetData()
|
||||||
createDownloadFile("file.dat", data)
|
createDownloadFile("file.dat", data)
|
||||||
@@ -205,9 +204,8 @@ var _ = Describe("Server tests", func() {
|
|||||||
rsp, err := client.Get("https://quic.clemente.io:" + serverPort + "/file.dat")
|
rsp, err := client.Get("https://quic.clemente.io:" + serverPort + "/file.dat")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(rsp.StatusCode).To(Equal(200))
|
Expect(rsp.StatusCode).To(Equal(200))
|
||||||
body, err := ioutil.ReadAll(rsp.Body)
|
body, err := ioutil.ReadAll(gbytes.TimeoutReader(rsp.Body, 20*time.Second))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(body).To(Equal(data))
|
Expect(body).To(Equal(data))
|
||||||
close(done)
|
})
|
||||||
}, 20)
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user