36 Star 160 Fork 23

小蚂蚁/gout

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gout_newopt_with_skip_verify_test.go 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
guonaihong 提交于 2021-08-01 22:03 . Response (#302)
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")
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/guonaihong/gout.git
git@gitee.com:guonaihong/gout.git
guonaihong
gout
gout
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385