]> Cypherpunks repositories - gostls13.git/commitdiff
os/exec: quiet distracting log output during test
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 15 Apr 2014 00:20:30 +0000 (17:20 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 15 Apr 2014 00:20:30 +0000 (17:20 -0700)
TLS handshake failures didn't use to log, but do in Go 1.3.
Shut it up so the actual failure can be seen in e.g.
http://build.golang.org/log/ede7e12362a941d93bf1fe21db9208a3e298029e

LGTM=adg
R=adg
CC=golang-codereviews
https://golang.org/cl/87870043

src/pkg/os/exec/exec_test.go

index f237312280c33234023660b557be9c00e72543a5..e4ad7d31575dfa9ec89512fcd8ca5b6c724dd14f 100644 (file)
@@ -13,6 +13,7 @@ import (
        "fmt"
        "io"
        "io/ioutil"
+       "log"
        "net"
        "net/http"
        "net/http/httptest"
@@ -401,11 +402,15 @@ func TestExtraFiles(t *testing.T) {
 
        // Force TLS root certs to be loaded (which might involve
        // cgo), to make sure none of that potential C code leaks fds.
-       ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-               w.Write([]byte("Hello"))
-       }))
+       ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
+       // quiet expected TLS handshake error "remote error: bad certificate"
+       ts.Config.ErrorLog = log.New(ioutil.Discard, "", 0)
+       ts.StartTLS()
        defer ts.Close()
-       http.Get(ts.URL) // ignore result; just calling to force root cert loading
+       _, err = http.Get(ts.URL)
+       if err == nil {
+               t.Errorf("success trying to fetch %s; want an error", ts.URL)
+       }
 
        tf, err := ioutil.TempFile("", "")
        if err != nil {