예제 #1
0
func TestParseLocation(t *testing.T) {
	assert := assert.New(t)

	r := model.Remote{
		Driver:   "ssh",
		Location: "hostname",
	}
	rd := ssh.Load(r)
	assert.Equal(rd.Host, "hostname")
	assert.Equal(rd.Port, 22)
	assert.Equal(rd.User, "")

	r = model.Remote{
		Driver:   "ssh",
		Location: "user@hostname",
	}
	rd = ssh.Load(r)
	assert.Equal(rd.Host, "hostname")
	assert.Equal(rd.Port, 22)
	assert.Equal(rd.User, "user")

	r = model.Remote{
		Driver:   "ssh",
		Location: "hostname:42",
	}
	rd = ssh.Load(r)
	assert.Equal(rd.Host, "hostname")
	assert.Equal(rd.Port, 42)
	assert.Equal(rd.User, "")

	r = model.Remote{
		Driver:   "ssh",
		Location: "user@hostname:42",
	}
	rd = ssh.Load(r)
	assert.Equal(rd.Host, "hostname")
	assert.Equal(rd.Port, 42)
	assert.Equal(rd.User, "user")

	r = model.Remote{
		Driver:   "ssh",
		Location: "user@hostname:foo",
	}
	rd = ssh.Load(r)
	assert.Equal(rd.Host, "hostname")
	assert.Equal(rd.Port, 22)
	assert.Equal(rd.User, "user")
}
예제 #2
0
파일: remote.go 프로젝트: raphaelm/backupd
func LoadDriver(r model.Remote) (driver RemoteDriver, ok bool) {
	switch r.Driver {
	case "ssh":
		return ssh.Load(r), true
	default:
		return nil, false
	}
}