github.com/deis/deis@v1.13.5-0.20170519182049-1d9e59fbdbfc/Godeps/_workspace/src/golang.org/x/crypto/ssh/client_test.go (about)

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