~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/golang.org/x/crypto/ssh/client_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}