...
1
2
3
4
5 package websocket
6
7 import (
8 "crypto/tls"
9 "fmt"
10 "log"
11 "net"
12 "net/http/httptest"
13 "testing"
14 "time"
15 )
16
17
18
19 func TestDialConfigTLSWithDialer(t *testing.T) {
20 tlsServer := httptest.NewTLSServer(nil)
21 tlsServerAddr := tlsServer.Listener.Addr().String()
22 log.Print("Test TLS WebSocket server listening on ", tlsServerAddr)
23 defer tlsServer.Close()
24 config, _ := NewConfig(fmt.Sprintf("wss://%s/echo", tlsServerAddr), "http://localhost")
25 config.Dialer = &net.Dialer{
26 Deadline: time.Now().Add(-time.Minute),
27 }
28 config.TlsConfig = &tls.Config{
29 InsecureSkipVerify: true,
30 }
31 _, err := DialConfig(config)
32 dialerr, ok := err.(*DialError)
33 if !ok {
34 t.Fatalf("DialError expected, got %#v", err)
35 }
36 neterr, ok := dialerr.Err.(*net.OpError)
37 if !ok {
38 t.Fatalf("net.OpError error expected, got %#v", dialerr.Err)
39 }
40 if !neterr.Timeout() {
41 t.Fatalf("expected timeout error, got %#v", neterr)
42 }
43 }
44
View as plain text