2015-03-11 22:42:08 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
2017-02-27 17:49:35 +00:00
|
|
|
|
|
|
|
"golang.org/x/net/http2"
|
2015-03-11 22:42:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// testHTTPServer creates a test HTTP server that handles requests until
|
|
|
|
// the listener returned is closed.
|
|
|
|
func testHTTPServer(
|
2015-04-23 15:13:52 +00:00
|
|
|
t *testing.T, handler http.Handler) (*Config, net.Listener) {
|
2015-03-11 22:42:08 +00:00
|
|
|
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
server := &http.Server{Handler: handler}
|
2017-02-27 17:49:35 +00:00
|
|
|
if err := http2.ConfigureServer(server, nil); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-03-11 22:42:08 +00:00
|
|
|
go server.Serve(ln)
|
|
|
|
|
|
|
|
config := DefaultConfig()
|
|
|
|
config.Address = fmt.Sprintf("http://%s", ln.Addr())
|
|
|
|
|
|
|
|
return config, ln
|
|
|
|
}
|