http: make TestServer public

This commit is contained in:
Mitchell Hashimoto
2015-03-13 11:13:33 -07:00
parent d2642529b7
commit 48c05995e5
4 changed files with 32 additions and 26 deletions

25
http/testing.go Normal file
View File

@@ -0,0 +1,25 @@
package http
import (
"net"
"net/http"
"testing"
"github.com/hashicorp/vault/vault"
)
func TestServer(t *testing.T, core *vault.Core) (net.Listener, string) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("err: %s", err)
}
addr := "http://" + ln.Addr().String()
server := &http.Server{
Addr: ln.Addr().String(),
Handler: Handler(core),
}
go server.Serve(ln)
return ln, addr
}