summaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/crypto/ssh/test/tcpip_test.go
blob: a2eb9358d0212fc42e95e8dcf86607fb1c6ac7a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !windows

package test

// direct-tcpip functional tests

import (
	"io"
	"net"
	"testing"
)

func TestDial(t *testing.T) {
	server := newServer(t)
	defer server.Shutdown()
	sshConn := server.Dial(clientConfig())
	defer sshConn.Close()

	l, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		t.Fatalf("Listen: %v", err)
	}
	defer l.Close()

	go func() {
		for {
			c, err := l.Accept()
			if err != nil {
				break
			}

			io.WriteString(c, c.RemoteAddr().String())
			c.Close()
		}
	}()

	conn, err := sshConn.Dial("tcp", l.Addr().String())
	if err != nil {
		t.Fatalf("Dial: %v", err)
	}
	defer conn.Close()
}