aboutsummaryrefslogtreecommitdiff
path: root/ssh/test
diff options
context:
space:
mode:
authorJoel Sing <jsing@google.com>2012-11-12 02:50:33 +1100
committerJoel Sing <jsing@google.com>2012-11-12 02:50:33 +1100
commitae58a7bde0ebc1afab65a3bbcffcf63d4e7e7e9c (patch)
treeff1cc629654b8651280f54274afe736ceee6ce2b /ssh/test
parent153731a6de123b98250cbf9e5adbc8d0d950c10a (diff)
downloadgo-x-crypto-ae58a7bde0ebc1afab65a3bbcffcf63d4e7e7e9c.tar.xz
go.crypto/ssh: make tests work on non-cgo platforms.
user.Current() currently requires cgo - if an error is returned attempt to get the username from the environment. R=golang-dev, minux.ma, bradfitz, dave CC=golang-dev https://golang.org/cl/6819113
Diffstat (limited to 'ssh/test')
-rw-r--r--ssh/test/test_unix_test.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/ssh/test/test_unix_test.go b/ssh/test/test_unix_test.go
index ad10408..47a03d0 100644
--- a/ssh/test/test_unix_test.go
+++ b/ssh/test/test_unix_test.go
@@ -150,15 +150,26 @@ type server struct {
output bytes.Buffer // holds stderr from sshd process
}
-func clientConfig() *ssh.ClientConfig {
- user, err := user.Current()
- if err != nil {
- panic(err)
+func username() string {
+ var username string
+ if user, err := user.Current(); err == nil {
+ username = user.Username
+ } else {
+ // user.Current() currently requires cgo. If an error is
+ // returned attempt to get the username from the environment.
+ username = os.Getenv("USER")
+ }
+ if username == "" {
+ panic("Unable to get username")
}
+ return username
+}
+
+func clientConfig() *ssh.ClientConfig {
kc := new(keychain)
kc.keys = append(kc.keys, rsakey)
config := &ssh.ClientConfig{
- User: user.Username,
+ User: username(),
Auth: []ssh.ClientAuth{
ssh.ClientAuthKeyring(kc),
},