forked from quic-go/quic-go
interop: move away from Ginkgo (#4652)
This commit is contained in:
@@ -1,13 +0,0 @@
|
|||||||
package http09
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestHttp09(t *testing.T) {
|
|
||||||
RegisterFailHandler(Fail)
|
|
||||||
RunSpecs(t, "HTTP/0.9 Suite")
|
|
||||||
}
|
|
||||||
@@ -7,81 +7,71 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/quic-go/quic-go"
|
"github.com/quic-go/quic-go"
|
||||||
"github.com/quic-go/quic-go/internal/testdata"
|
"github.com/quic-go/quic-go/internal/testdata"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
"github.com/stretchr/testify/require"
|
||||||
. "github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("HTTP 0.9 integration tests", func() {
|
func startServer(t *testing.T) net.Addr {
|
||||||
var (
|
t.Helper()
|
||||||
ln *quic.EarlyListener
|
server := &Server{}
|
||||||
saddr net.Addr
|
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
|
||||||
done chan struct{}
|
require.NoError(t, err)
|
||||||
)
|
tr := &quic.Transport{Conn: conn}
|
||||||
|
tlsConf := testdata.GetTLSConfig()
|
||||||
|
tlsConf.NextProtos = []string{NextProto}
|
||||||
|
ln, err := tr.ListenEarly(tlsConf, &quic.Config{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(done)
|
||||||
|
_ = server.ServeListener(ln)
|
||||||
|
}()
|
||||||
|
t.Cleanup(func() {
|
||||||
|
require.NoError(t, ln.Close())
|
||||||
|
<-done
|
||||||
|
})
|
||||||
|
return ln.Addr()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHTTPRequest(t *testing.T) {
|
||||||
http.HandleFunc("/helloworld", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/helloworld", func(w http.ResponseWriter, r *http.Request) {
|
||||||
_, _ = w.Write([]byte("Hello World!"))
|
_, _ = w.Write([]byte("Hello World!"))
|
||||||
})
|
})
|
||||||
|
|
||||||
BeforeEach(func() {
|
addr := startServer(t)
|
||||||
server := &Server{}
|
|
||||||
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
|
rt := &RoundTripper{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
|
||||||
Expect(err).ToNot(HaveOccurred())
|
t.Cleanup(func() { rt.Close() })
|
||||||
tr := &quic.Transport{Conn: conn}
|
|
||||||
tlsConf := testdata.GetTLSConfig()
|
req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/helloworld", addr), nil)
|
||||||
tlsConf.NextProtos = []string{NextProto}
|
rsp, err := rt.RoundTrip(req)
|
||||||
ln, err = tr.ListenEarly(tlsConf, &quic.Config{})
|
require.NoError(t, err)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
data, err := io.ReadAll(rsp.Body)
|
||||||
done = make(chan struct{})
|
require.NoError(t, err)
|
||||||
go func() {
|
require.Equal(t, []byte("Hello World!"), data)
|
||||||
defer GinkgoRecover()
|
}
|
||||||
defer close(done)
|
|
||||||
_ = server.ServeListener(ln)
|
func TestHTTPHeaders(t *testing.T) {
|
||||||
}()
|
http.HandleFunc("/headers", func(w http.ResponseWriter, r *http.Request) {
|
||||||
saddr = ln.Addr()
|
w.Header().Add("foo", "bar")
|
||||||
|
w.WriteHeader(1337)
|
||||||
|
_, _ = w.Write([]byte("done"))
|
||||||
})
|
})
|
||||||
|
|
||||||
AfterEach(func() {
|
addr := startServer(t)
|
||||||
Expect(ln.Close()).To(Succeed())
|
|
||||||
Eventually(done).Should(BeClosed())
|
|
||||||
})
|
|
||||||
|
|
||||||
It("performs request", func() {
|
rt := &RoundTripper{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
|
||||||
rt := &RoundTripper{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
|
t.Cleanup(func() { rt.Close() })
|
||||||
defer rt.Close()
|
|
||||||
req := httptest.NewRequest(
|
|
||||||
http.MethodGet,
|
|
||||||
fmt.Sprintf("https://%s/helloworld", saddr),
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
rsp, err := rt.RoundTrip(req)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
data, err := io.ReadAll(rsp.Body)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
Expect(data).To(Equal([]byte("Hello World!")))
|
|
||||||
})
|
|
||||||
|
|
||||||
It("allows setting of headers", func() {
|
req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/headers", addr), nil)
|
||||||
http.HandleFunc("/headers", func(w http.ResponseWriter, r *http.Request) {
|
rsp, err := rt.RoundTrip(req)
|
||||||
w.Header().Add("foo", "bar")
|
require.NoError(t, err)
|
||||||
w.WriteHeader(1337)
|
data, err := io.ReadAll(rsp.Body)
|
||||||
_, _ = w.Write([]byte("done"))
|
require.NoError(t, err)
|
||||||
})
|
require.Equal(t, []byte("done"), data)
|
||||||
|
// HTTP/0.9 doesn't support HTTP headers
|
||||||
rt := &RoundTripper{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
|
}
|
||||||
defer rt.Close()
|
|
||||||
req := httptest.NewRequest(
|
|
||||||
http.MethodGet,
|
|
||||||
fmt.Sprintf("https://%s/headers", saddr),
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
rsp, err := rt.RoundTrip(req)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
data, err := io.ReadAll(rsp.Body)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
Expect(data).To(Equal([]byte("done")))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|||||||
Reference in New Issue
Block a user