From 4654988dd1705b9dc08b4457f92354394b5cd668 Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Mon, 15 Nov 2021 02:12:15 +0500 Subject: [PATCH] :recycle: Use embed certificate keys for TestServe util --- internal/util/test_serve.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/internal/util/test_serve.go b/internal/util/test_serve.go index 8e0c00a..75595ab 100644 --- a/internal/util/test_serve.go +++ b/internal/util/test_serve.go @@ -3,8 +3,8 @@ package util import ( "crypto/tls" + _ "embed" "net" - "path/filepath" "testing" "time" @@ -12,23 +12,33 @@ import ( httputil "github.com/valyala/fasthttp/fasthttputil" ) -//nolint: exhaustivestruct +//nolint: gochecknoglobals +var ( + //go:embed cert.pem + certData []byte + //go:embed key.pem + keyData []byte +) + +// TestServe returns the InMemory HTTP-server and the client connected to it +// with the specified handler. func TestServe(tb testing.TB, handler http.RequestHandler) (*http.Client, *http.Server, func()) { tb.Helper() + //nolint: exhaustivestruct server := &http.Server{ CloseOnShutdown: true, DisableKeepalive: true, - Handler: http.TimeoutHandler(handler, 1*time.Minute, "handler performance is too slow"), ReduceMemoryUsage: true, + Handler: http.TimeoutHandler(handler, 1*time.Second, "handler performance is too slow"), } ln := httputil.NewInmemoryListener() //nolint: errcheck - go server.ServeTLS(ln, filepath.Join("..", "..", "..", "util", "cert.pem"), - filepath.Join("..", "..", "..", "util", "key.pem")) + go server.ServeTLSEmbed(ln, certData, keyData) + //nolint: exhaustivestruct client := &http.Client{ TLSConfig: &tls.Config{ InsecureSkipVerify: true, //nolint: gosec @@ -38,7 +48,8 @@ func TestServe(tb testing.TB, handler http.RequestHandler) (*http.Client, *http. }, } + //nolint: errcheck return client, server, func() { - server.Shutdown() //nolint: errcheck + server.Shutdown() } }