tcpip_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package ssh
  5. import (
  6. "context"
  7. "net"
  8. "testing"
  9. "time"
  10. )
  11. func TestAutoPortListenBroken(t *testing.T) {
  12. broken := "SSH-2.0-OpenSSH_5.9hh11"
  13. works := "SSH-2.0-OpenSSH_6.1"
  14. if !isBrokenOpenSSHVersion(broken) {
  15. t.Errorf("version %q not marked as broken", broken)
  16. }
  17. if isBrokenOpenSSHVersion(works) {
  18. t.Errorf("version %q marked as broken", works)
  19. }
  20. }
  21. func TestClientImplementsDialContext(t *testing.T) {
  22. type ContextDialer interface {
  23. DialContext(context.Context, string, string) (net.Conn, error)
  24. }
  25. // Belt and suspenders assertion, since package net does not
  26. // declare a ContextDialer type.
  27. var _ ContextDialer = &net.Dialer{}
  28. var _ ContextDialer = &Client{}
  29. }
  30. func TestClientDialContextWithCancel(t *testing.T) {
  31. c := &Client{}
  32. ctx, cancel := context.WithCancel(context.Background())
  33. cancel()
  34. _, err := c.DialContext(ctx, "tcp", "localhost:1000")
  35. if err != context.Canceled {
  36. t.Errorf("DialContext: got nil error, expected %v", context.Canceled)
  37. }
  38. }
  39. func TestClientDialContextWithDeadline(t *testing.T) {
  40. c := &Client{}
  41. ctx, cancel := context.WithDeadline(context.Background(), time.Now())
  42. defer cancel()
  43. _, err := c.DialContext(ctx, "tcp", "localhost:1000")
  44. if err != context.DeadlineExceeded {
  45. t.Errorf("DialContext: got nil error, expected %v", context.DeadlineExceeded)
  46. }
  47. }