55package ssh
66
77import (
8+ "context"
9+ "net"
810 "testing"
11+ "time"
912)
1013
1114func TestAutoPortListenBroken (t * testing.T ) {
@@ -18,3 +21,40 @@ func TestAutoPortListenBroken(t *testing.T) {
1821 t .Errorf ("version %q marked as broken" , works )
1922 }
2023}
24+
25+ func TestClientImplementsDialContext (t * testing.T ) {
26+ type ContextDialer interface {
27+ DialContext (context.Context , string , string ) (net.Conn , error )
28+ }
29+ var _ ContextDialer = & Client {}
30+ }
31+
32+ func TestClientDialContextWithCancel (t * testing.T ) {
33+ c := & Client {}
34+ ctx , cancel := context .WithCancel (context .Background ())
35+ cancel ()
36+ _ , err := c .DialContext (ctx , "tcp" , "localhost:1000" )
37+ if err != context .Canceled {
38+ t .Errorf ("DialContext: got nil error, expected %v" , context .Canceled )
39+ }
40+ }
41+
42+ func TestClientDialContextWithDeadline (t * testing.T ) {
43+ c := & Client {}
44+ ctx , cancel := context .WithDeadline (context .Background (), time .Now ())
45+ defer cancel ()
46+ _ , err := c .DialContext (ctx , "tcp" , "localhost:1000" )
47+ if err != context .DeadlineExceeded {
48+ t .Errorf ("DialContext: got nil error, expected %v" , context .DeadlineExceeded )
49+ }
50+ }
51+
52+ func TestClientDialContextWithTimeout (t * testing.T ) {
53+ c := & Client {}
54+ ctx , cancel := context .WithTimeout (context .Background (), 0 )
55+ defer cancel ()
56+ _ , err := c .DialContext (ctx , "tcp" , "localhost:1000" )
57+ if err != context .DeadlineExceeded {
58+ t .Errorf ("DialContext: got nil error, expected %v" , context .DeadlineExceeded )
59+ }
60+ }
0 commit comments