git-lfs/lfs/ssh_test.go
Steve Streeting 72795a308b Improved SSH support: non-bare urls, custom ports, and GIT_SSH/plinks
* Full SSH urls e.g. ssh://user@host/repo
* Custom ports in both bare and full urls
* GIT_SSH environment for alternate ssh clients
* Explicit support for plink.exe and TortoisePlink.exe
2015-06-22 10:46:40 +01:00

92 lines
2.9 KiB
Go

package lfs
import (
"path/filepath"
"testing"
"github.com/github/git-lfs/vendor/_nuts/github.com/technoweenie/assert"
)
func TestSSHGetExeAndArgsSsh(t *testing.T) {
endpoint := Config.Endpoint()
endpoint.SshUserAndHost = "user@foo.com"
oldGITSSH := Config.Getenv("GIT_SSH")
Config.Setenv("GIT_SSH", "")
exe, args := sshGetExeAndArgs(endpoint)
assert.Equal(t, "ssh", exe)
assert.Equal(t, []string{"user@foo.com"}, args)
Config.Setenv("GIT_SSH", oldGITSSH)
}
func TestSSHGetExeAndArgsSshCustomPort(t *testing.T) {
endpoint := Config.Endpoint()
endpoint.SshUserAndHost = "user@foo.com"
endpoint.SshPort = "8888"
oldGITSSH := Config.Getenv("GIT_SSH")
Config.Setenv("GIT_SSH", "")
exe, args := sshGetExeAndArgs(endpoint)
assert.Equal(t, "ssh", exe)
assert.Equal(t, []string{"-p", "8888", "user@foo.com"}, args)
Config.Setenv("GIT_SSH", oldGITSSH)
}
func TestSSHGetExeAndArgsPlink(t *testing.T) {
endpoint := Config.Endpoint()
endpoint.SshUserAndHost = "user@foo.com"
oldGITSSH := Config.Getenv("GIT_SSH")
// this will run on non-Windows platforms too but no biggie
plink := filepath.Join("Users", "joebloggs", "bin", "plink.exe")
Config.Setenv("GIT_SSH", plink)
exe, args := sshGetExeAndArgs(endpoint)
assert.Equal(t, plink, exe)
assert.Equal(t, []string{"user@foo.com"}, args)
Config.Setenv("GIT_SSH", oldGITSSH)
}
func TestSSHGetExeAndArgsPlinkCustomPort(t *testing.T) {
endpoint := Config.Endpoint()
endpoint.SshUserAndHost = "user@foo.com"
endpoint.SshPort = "8888"
oldGITSSH := Config.Getenv("GIT_SSH")
// this will run on non-Windows platforms too but no biggie
plink := filepath.Join("Users", "joebloggs", "bin", "plink")
Config.Setenv("GIT_SSH", plink)
exe, args := sshGetExeAndArgs(endpoint)
assert.Equal(t, plink, exe)
assert.Equal(t, []string{"-P", "8888", "user@foo.com"}, args)
Config.Setenv("GIT_SSH", oldGITSSH)
}
func TestSSHGetExeAndArgsTortoisePlink(t *testing.T) {
endpoint := Config.Endpoint()
endpoint.SshUserAndHost = "user@foo.com"
oldGITSSH := Config.Getenv("GIT_SSH")
// this will run on non-Windows platforms too but no biggie
plink := filepath.Join("Users", "joebloggs", "bin", "tortoiseplink.exe")
Config.Setenv("GIT_SSH", plink)
exe, args := sshGetExeAndArgs(endpoint)
assert.Equal(t, plink, exe)
assert.Equal(t, []string{"-batch", "user@foo.com"}, args)
Config.Setenv("GIT_SSH", oldGITSSH)
}
func TestSSHGetExeAndArgsTortoisePlinkCustomPort(t *testing.T) {
endpoint := Config.Endpoint()
endpoint.SshUserAndHost = "user@foo.com"
endpoint.SshPort = "8888"
oldGITSSH := Config.Getenv("GIT_SSH")
// this will run on non-Windows platforms too but no biggie
plink := filepath.Join("Users", "joebloggs", "bin", "tortoiseplink")
Config.Setenv("GIT_SSH", plink)
exe, args := sshGetExeAndArgs(endpoint)
assert.Equal(t, plink, exe)
assert.Equal(t, []string{"-batch", "-P", "8888", "user@foo.com"}, args)
Config.Setenv("GIT_SSH", oldGITSSH)
}