소스 검색

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
Joel Sing 13 년 전
부모
커밋
ae58a7bde0
1개의 변경된 파일16개의 추가작업 그리고 5개의 파일을 삭제
  1. 16 5
      ssh/test/test_unix_test.go

+ 16 - 5
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),
 		},