mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 12:07:54 +00:00
Change http testing to tb interface
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user