-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathgout_newopt_with_skip_verify_test.go
54 lines (44 loc) · 1.16 KB
/
gout_newopt_with_skip_verify_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package gout
import (
"log"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type chanWriter chan string
func (w chanWriter) Write(p []byte) (n int, err error) {
w <- string(p)
return len(p), nil
}
func Test_WithInsecureSkipVerify(t *testing.T) {
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte("Hello"))
assert.NoError(t, err)
}))
errc := make(chanWriter, 10) // but only expecting 1
ts.Config.ErrorLog = log.New(errc, "", 0)
defer ts.Close()
c := ts.Client()
for _, insecure := range []bool{true, false} {
var opts []Option
if insecure {
opts = []Option{WithClient(c), WithInsecureSkipVerify()}
}
client := NewWithOpt(opts...)
err := client.GET(ts.URL).Do()
if (err == nil) != insecure {
t.Errorf("#insecure=%v: got unexpected err=%v", insecure, err)
}
}
select {
case v := <-errc:
if !strings.Contains(v, "TLS handshake error") {
t.Errorf("expected an error log message containing 'TLS handshake error'; got %q", v)
}
case <-time.After(5 * time.Second):
t.Errorf("timeout waiting for logged error")
}
}