Change http testing to tb interface

This commit is contained in:
Seth Vargo
2017-09-04 23:51:48 -04:00
parent aea62c18c0
commit 4b7a1967f5

View File

@@ -11,12 +11,12 @@ import (
"github.com/hashicorp/vault/vault" "github.com/hashicorp/vault/vault"
) )
func TestListener(t *testing.T) (net.Listener, string) { func TestListener(tb testing.TB) (net.Listener, string) {
fail := func(format string, args ...interface{}) { fail := func(format string, args ...interface{}) {
panic(fmt.Sprintf(format, args...)) panic(fmt.Sprintf(format, args...))
} }
if t != nil { if tb != nil {
fail = t.Fatalf fail = tb.Fatalf
} }
ln, err := net.Listen("tcp", "127.0.0.1:0") ln, err := net.Listen("tcp", "127.0.0.1:0")
@@ -27,7 +27,7 @@ func TestListener(t *testing.T) (net.Listener, string) {
return ln, addr return ln, addr
} }
func TestServerWithListener(t *testing.T, ln net.Listener, addr string, core *vault.Core) { func TestServerWithListener(tb testing.TB, ln net.Listener, addr string, core *vault.Core) {
// Create a muxer to handle our requests so that we can authenticate // Create a muxer to handle our requests so that we can authenticate
// for tests. // for tests.
mux := http.NewServeMux() mux := http.NewServeMux()
@@ -39,20 +39,20 @@ func TestServerWithListener(t *testing.T, ln net.Listener, addr string, core *va
Handler: mux, Handler: mux,
} }
if err := http2.ConfigureServer(server, nil); err != nil { if err := http2.ConfigureServer(server, nil); err != nil {
t.Fatal(err) tb.Fatal(err)
} }
go server.Serve(ln) go server.Serve(ln)
} }
func TestServer(t *testing.T, core *vault.Core) (net.Listener, string) { func TestServer(tb testing.TB, core *vault.Core) (net.Listener, string) {
ln, addr := TestListener(t) ln, addr := TestListener(tb)
TestServerWithListener(t, ln, addr, core) TestServerWithListener(tb, ln, addr, core)
return ln, addr return ln, addr
} }
func TestServerAuth(t *testing.T, addr string, token string) { func TestServerAuth(tb testing.TB, addr string, token string) {
if _, err := http.Get(addr + "/_test/auth?token=" + token); err != nil { if _, err := http.Get(addr + "/_test/auth?token=" + token); err != nil {
t.Fatalf("error authenticating: %s", err) tb.Fatalf("error authenticating: %s", err)
} }
} }