Skip to content

Commit 5ffaf1a

Browse files
committed
pkg/tool/http: prevent TestTLS from being chatty
The http server would print tls errors to stderr by default: $ go test server.go:3495: http: TLS handshake error from 127.0.0.1:47098: remote error: tls: bad certificate PASS ok cuelang.org/go/pkg/tool/http 0.021s Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ic5678957d9180bc27774e256cbb2134e1d196c20 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201509 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 43a1e12 commit 5ffaf1a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/tool/http/http_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ package http
1717
import (
1818
"encoding/pem"
1919
"fmt"
20+
"io"
21+
"log"
2022
"net/http"
2123
"net/http/httptest"
2224
"strings"
@@ -30,10 +32,13 @@ import (
3032
)
3133

3234
func newTLSServer() *httptest.Server {
33-
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
35+
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
3436
resp := `{"foo": "bar"}`
3537
w.Write([]byte(resp))
3638
}))
39+
// The TLS errors produced by TestTLS would otherwise print noise to stderr.
40+
server.Config.ErrorLog = log.New(io.Discard, "", 0)
41+
server.StartTLS()
3742
return server
3843
}
3944

0 commit comments

Comments
 (0)