5
5
package ssh
6
6
7
7
import (
8
+ "context"
9
+ "net"
8
10
"testing"
11
+ "time"
9
12
)
10
13
11
14
func TestAutoPortListenBroken (t * testing.T ) {
@@ -18,3 +21,33 @@ func TestAutoPortListenBroken(t *testing.T) {
18
21
t .Errorf ("version %q marked as broken" , works )
19
22
}
20
23
}
24
+
25
+ func TestClientImplementsDialContext (t * testing.T ) {
26
+ type ContextDialer interface {
27
+ DialContext (context.Context , string , string ) (net.Conn , error )
28
+ }
29
+ // Belt and suspenders assertion, since package net does not
30
+ // declare a ContextDialer type.
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
+ }
0 commit comments