client_test.go 969 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. "net"
  7. "testing"
  8. )
  9. func testClientVersion(t *testing.T, config *ClientConfig, expected string) {
  10. clientConn, serverConn := net.Pipe()
  11. defer clientConn.Close()
  12. receivedVersion := make(chan string, 1)
  13. go func() {
  14. version, err := readVersion(serverConn)
  15. if err != nil {
  16. receivedVersion <- ""
  17. } else {
  18. receivedVersion <- string(version)
  19. }
  20. serverConn.Close()
  21. }()
  22. NewClientConn(clientConn, "", config)
  23. actual := <-receivedVersion
  24. if actual != expected {
  25. t.Fatalf("got %s; want %s", actual, expected)
  26. }
  27. }
  28. func TestCustomClientVersion(t *testing.T) {
  29. version := "Test-Client-Version-0.0"
  30. testClientVersion(t, &ClientConfig{ClientVersion: version}, version)
  31. }
  32. func TestDefaultClientVersion(t *testing.T) {
  33. testClientVersion(t, &ClientConfig{}, packageVersion)
  34. }