...
1
2
3
4
5 package ssh
6
7 import (
8 "context"
9 "net"
10 "testing"
11 "time"
12 )
13
14 func TestAutoPortListenBroken(t *testing.T) {
15 broken := "SSH-2.0-OpenSSH_5.9hh11"
16 works := "SSH-2.0-OpenSSH_6.1"
17 if !isBrokenOpenSSHVersion(broken) {
18 t.Errorf("version %q not marked as broken", broken)
19 }
20 if isBrokenOpenSSHVersion(works) {
21 t.Errorf("version %q marked as broken", works)
22 }
23 }
24
25 func TestClientImplementsDialContext(t *testing.T) {
26 type ContextDialer interface {
27 DialContext(context.Context, string, string) (net.Conn, error)
28 }
29
30
31 var _ ContextDialer = &net.Dialer{}
32 var _ ContextDialer = &Client{}
33 }
34
35 func TestClientDialContextWithCancel(t *testing.T) {
36 c := &Client{}
37 ctx, cancel := context.WithCancel(context.Background())
38 cancel()
39 _, err := c.DialContext(ctx, "tcp", "localhost:1000")
40 if err != context.Canceled {
41 t.Errorf("DialContext: got nil error, expected %v", context.Canceled)
42 }
43 }
44
45 func TestClientDialContextWithDeadline(t *testing.T) {
46 c := &Client{}
47 ctx, cancel := context.WithDeadline(context.Background(), time.Now())
48 defer cancel()
49 _, err := c.DialContext(ctx, "tcp", "localhost:1000")
50 if err != context.DeadlineExceeded {
51 t.Errorf("DialContext: got nil error, expected %v", context.DeadlineExceeded)
52 }
53 }
54
View as plain text