github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/net/websocket/dial_test.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package websocket 6 7 import ( 8 "fmt" 9 "log" 10 "net" 11 "testing" 12 "time" 13 14 "github.com/hxx258456/ccgo/gmhttp/httptest" 15 16 tls "github.com/hxx258456/ccgo/gmtls" 17 ) 18 19 // This test depend on Go 1.3+ because in earlier versions the Dialer won't be 20 // used in TLS connections and a timeout won't be triggered. 21 func TestDialConfigTLSWithDialer(t *testing.T) { 22 tlsServer := httptest.NewTLSServer(nil) 23 tlsServerAddr := tlsServer.Listener.Addr().String() 24 log.Print("Test TLS WebSocket server listening on ", tlsServerAddr) 25 defer tlsServer.Close() 26 config, _ := NewConfig(fmt.Sprintf("wss://%s/echo", tlsServerAddr), "http://localhost") 27 config.Dialer = &net.Dialer{ 28 Deadline: time.Now().Add(-time.Minute), 29 } 30 config.TlsConfig = &tls.Config{ 31 InsecureSkipVerify: true, 32 } 33 _, err := DialConfig(config) 34 dialerr, ok := err.(*DialError) 35 if !ok { 36 t.Fatalf("DialError expected, got %#v", err) 37 } 38 neterr, ok := dialerr.Err.(*net.OpError) 39 if !ok { 40 t.Fatalf("net.OpError error expected, got %#v", dialerr.Err) 41 } 42 if !neterr.Timeout() { 43 t.Fatalf("expected timeout error, got %#v", neterr) 44 } 45 }