open-vault/api/api_test.go

29 lines
583 B
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
2015-03-11 22:42:08 +00:00
package api
import (
"fmt"
"net"
"net/http"
"testing"
)
// testHTTPServer creates a test HTTP server that handles requests until
// the listener returned is closed.
func testHTTPServer(t *testing.T, handler http.Handler) (*Config, net.Listener) {
2015-03-11 22:42:08 +00:00
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("err: %s", err)
}
server := &http.Server{Handler: handler}
go server.Serve(ln)
config := DefaultConfig()
config.Address = fmt.Sprintf("http://%s", ln.Addr())
return config, ln
}