mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Change http testing to tb interface
This commit is contained in:
@@ -11,12 +11,12 @@ import (
|
||||
"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{}) {
|
||||
panic(fmt.Sprintf(format, args...))
|
||||
}
|
||||
if t != nil {
|
||||
fail = t.Fatalf
|
||||
if tb != nil {
|
||||
fail = tb.Fatalf
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
// for tests.
|
||||
mux := http.NewServeMux()
|
||||
@@ -39,20 +39,20 @@ func TestServerWithListener(t *testing.T, ln net.Listener, addr string, core *va
|
||||
Handler: mux,
|
||||
}
|
||||
if err := http2.ConfigureServer(server, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
tb.Fatal(err)
|
||||
}
|
||||
go server.Serve(ln)
|
||||
}
|
||||
|
||||
func TestServer(t *testing.T, core *vault.Core) (net.Listener, string) {
|
||||
ln, addr := TestListener(t)
|
||||
TestServerWithListener(t, ln, addr, core)
|
||||
func TestServer(tb testing.TB, core *vault.Core) (net.Listener, string) {
|
||||
ln, addr := TestListener(tb)
|
||||
TestServerWithListener(tb, ln, addr, core)
|
||||
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 {
|
||||
t.Fatalf("error authenticating: %s", err)
|
||||
tb.Fatalf("error authenticating: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user