| 331 | } |
| 332 | |
| 333 | func TestTimeoutDialer(t *testing.T) { |
| 334 | listener, err := net.Listen("tcp", "127.0.0.1:0") |
| 335 | if err != nil { |
| 336 | t.Errorf("unexpected error: %v", err) |
| 337 | t.FailNow() |
| 338 | } |
| 339 | |
| 340 | testCases := []struct { |
| 341 | timeout time.Duration |
| 342 | expectedErrString string |
| 343 | }{ |
| 344 | // delay > timeout should cause ssh.Dial to timeout. |
| 345 | {1, "i/o timeout"}, |
| 346 | } |
| 347 | for _, tc := range testCases { |
| 348 | dialer := &timeoutDialer{&realSSHDialer{}, tc.timeout} |
| 349 | _, err := dialer.Dial("tcp", listener.Addr().String(), &ssh.ClientConfig{}) |
| 350 | if len(tc.expectedErrString) == 0 && err != nil || |
| 351 | !strings.Contains(fmt.Sprint(err), tc.expectedErrString) { |
| 352 | t.Errorf("Expected error to contain %q; got %v", tc.expectedErrString, err) |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | listener.Close() |
| 357 | } |
| 358 | |
| 359 | func newSSHTunnelFromBytes(user string, privateKey []byte, host string) (*sshTunnel, error) { |
| 360 | signer, err := MakePrivateKeySignerFromBytes(privateKey) |