vault/api/api_test.go
Vault Automation 58e59e67b2
Backport license: update headers to IBM Corp. into release/1.21.x+ent (#10234) (#10252)
* license: update headers to IBM Corp.
* `make proto`
* update offset because source file changed
* update licenses in files that were not included in backport

Signed-off-by: Ryan Cragun <me@ryan.ec>
Co-authored-by: Ryan Cragun <me@ryan.ec>
2025-10-21 15:20:35 -06:00

29 lines
584 B
Go

// Copyright IBM Corp. 2016, 2025
// SPDX-License-Identifier: MPL-2.0
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) {
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
}