integration: Add tests for HTTP/2 backend using go-nghttp2
This commit is contained in:
parent
a440bdf15e
commit
8eb2160890
23
README.rst
23
README.rst
|
@ -172,6 +172,29 @@ The generated documents will not be installed with ``make install``.
|
||||||
The online documentation is available at
|
The online documentation is available at
|
||||||
https://nghttp2.org/documentation/
|
https://nghttp2.org/documentation/
|
||||||
|
|
||||||
|
Unit tests
|
||||||
|
----------
|
||||||
|
|
||||||
|
Unit tests are done by simply running `make check`.
|
||||||
|
|
||||||
|
Integration tests
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
We have the integration tests for nghttpx proxy server. The tests are
|
||||||
|
written in `Go programming language <http://golang.org/>`_ and uses
|
||||||
|
its testing framework. We depends on the following libraries:
|
||||||
|
|
||||||
|
* https://github.com/bradfitz/http2
|
||||||
|
* https://github.com/tatsuhiro-t/go-nghttp2
|
||||||
|
|
||||||
|
To run the tests, enter ``integration-tests`` directory and run::
|
||||||
|
|
||||||
|
$ sh setenv go test
|
||||||
|
|
||||||
|
``setenv`` will set necessary environment variables to compile
|
||||||
|
go-nghttp2 library (which uses cgo to interface nghttp2). In side the
|
||||||
|
tests, we use port 3009 to run test subject server.
|
||||||
|
|
||||||
Client, Server and Proxy programs
|
Client, Server and Proxy programs
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
||||||
|
|
|
@ -652,6 +652,7 @@ AC_CONFIG_FILES([
|
||||||
python/Makefile
|
python/Makefile
|
||||||
python/setup.py
|
python/setup.py
|
||||||
integration-tests/config.go
|
integration-tests/config.go
|
||||||
|
integration-tests/setenv
|
||||||
doc/Makefile
|
doc/Makefile
|
||||||
doc/conf.py
|
doc/conf.py
|
||||||
doc/index.rst
|
doc/index.rst
|
||||||
|
|
|
@ -240,3 +240,40 @@ func TestHTTP2InvalidRequestCL(t *testing.T) {
|
||||||
t.Errorf("status: %v; want %v", got, want)
|
t.Errorf("status: %v; want %v", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHTTP2DuplicateResponseCL(t *testing.T) {
|
||||||
|
st := newServerTester([]string{"--http2-bridge"}, t, func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Add("content-length", "1")
|
||||||
|
w.Header().Add("content-length", "2")
|
||||||
|
})
|
||||||
|
defer st.Close()
|
||||||
|
|
||||||
|
res, err := st.http2(requestParam{
|
||||||
|
name: "TestHTTP2DuplicateResponseCL",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error st.http2() = %v", err)
|
||||||
|
}
|
||||||
|
want := 502
|
||||||
|
if got := res.status; got != want {
|
||||||
|
t.Errorf("status: %v; want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHTTP2InvalidResponseCL(t *testing.T) {
|
||||||
|
st := newServerTester([]string{"--http2-bridge"}, t, func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Add("content-length", "")
|
||||||
|
})
|
||||||
|
defer st.Close()
|
||||||
|
|
||||||
|
res, err := st.http2(requestParam{
|
||||||
|
name: "TestHTTP2InvalidResponseCL",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error st.http2() = %v", err)
|
||||||
|
}
|
||||||
|
want := 502
|
||||||
|
if got := res.status; got != want {
|
||||||
|
t.Errorf("status: %v; want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,10 +2,12 @@ package nghttp2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/bradfitz/http2"
|
"github.com/bradfitz/http2"
|
||||||
"github.com/bradfitz/http2/hpack"
|
"github.com/bradfitz/http2/hpack"
|
||||||
|
"github.com/tatsuhiro-t/go-nghttp2"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
@ -48,8 +50,27 @@ type serverTester struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newServerTester(args []string, t *testing.T, handler http.HandlerFunc) *serverTester {
|
func newServerTester(args []string, t *testing.T, handler http.HandlerFunc) *serverTester {
|
||||||
ts := httptest.NewServer(handler)
|
ts := httptest.NewUnstartedServer(handler)
|
||||||
|
|
||||||
|
backendTLS := false
|
||||||
|
for _, k := range args {
|
||||||
|
if k == "--http2-bridge" {
|
||||||
|
backendTLS = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if backendTLS {
|
||||||
|
nghttp2.ConfigureServer(ts.Config, &nghttp2.Server{})
|
||||||
|
// According to httptest/server.go, we have to set
|
||||||
|
// NextProtos separately for ts.TLS. NextProtos set
|
||||||
|
// in nghttp2.ConfigureServer is effectively ignored.
|
||||||
|
ts.TLS = new(tls.Config)
|
||||||
|
ts.TLS.NextProtos = append(ts.TLS.NextProtos, "h2-14")
|
||||||
|
ts.StartTLS()
|
||||||
|
args = append(args, "-k")
|
||||||
|
} else {
|
||||||
|
ts.Start()
|
||||||
|
}
|
||||||
u, err := url.Parse(ts.URL)
|
u, err := url.Parse(ts.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error parsing URL from httptest.Server: %v", err)
|
t.Fatalf("Error parsing URL from httptest.Server: %v", err)
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
export CGO_CFLAGS="-I@abs_top_srcdir@/lib/includes -I@abs_top_builddir@/lib/includes"
|
||||||
|
export CGO_LDFLAGS="-L@abs_top_builddir@/lib/.libs"
|
||||||
|
export LD_LIBRARY_PATH="@abs_top_builddir@/lib/.libs"
|
||||||
|
"$@"
|
Loading…
Reference in New Issue