2015-03-13 18:13:33 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
2015-03-15 23:52:19 +00:00
|
|
|
"fmt"
|
2015-03-13 18:13:33 +00:00
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/vault/vault"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestServer(t *testing.T, core *vault.Core) (net.Listener, string) {
|
2015-03-15 23:52:19 +00:00
|
|
|
fail := func(format string, args ...interface{}) {
|
|
|
|
panic(fmt.Sprintf(format, args...))
|
|
|
|
}
|
|
|
|
if t != nil {
|
|
|
|
fail = t.Fatalf
|
|
|
|
}
|
|
|
|
|
2015-03-13 18:13:33 +00:00
|
|
|
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
|
|
|
if err != nil {
|
2015-03-15 23:52:19 +00:00
|
|
|
fail("err: %s", err)
|
2015-03-13 18:13:33 +00:00
|
|
|
}
|
|
|
|
addr := "http://" + ln.Addr().String()
|
|
|
|
|
|
|
|
server := &http.Server{
|
|
|
|
Addr: ln.Addr().String(),
|
|
|
|
Handler: Handler(core),
|
|
|
|
}
|
|
|
|
go server.Serve(ln)
|
|
|
|
|
|
|
|
return ln, addr
|
|
|
|
}
|