exp/ssh: fix test?

Fixes use of c after Dial failure (causes crash).
May fix Dial failure by listening to 127.0.0.1:0
instead of 0.0.0.0:0 (tests should only listen on
localhost).

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/5395052
This commit is contained in:
Russ Cox 2011-11-16 18:13:50 -05:00
parent 7d1d8fe430
commit 8c6461bcb1

View file

@ -112,22 +112,22 @@ func TestClientAuthPublickey(t *testing.T) {
}
serverConfig.PasswordCallback = nil
l, err := Listen("tcp", "0.0.0.0:0", serverConfig)
l, err := Listen("tcp", "127.0.0.1:0", serverConfig)
if err != nil {
t.Fatalf("unable to listen: %s", err)
}
defer l.Close()
done := make(chan bool)
done := make(chan bool, 1)
go func() {
c, err := l.Accept()
if err != nil {
t.Fatal(err)
}
defer c.Close()
if err := c.Handshake(); err != nil {
t.Error(err)
}
defer c.Close()
done <- true
}()
@ -140,7 +140,7 @@ func TestClientAuthPublickey(t *testing.T) {
c, err := Dial("tcp", l.Addr().String(), config)
if err != nil {
t.Errorf("unable to dial remote side: %s", err)
t.Fatalf("unable to dial remote side: %s", err)
}
defer c.Close()
<-done