Example #1
0
func TestFuncPublickeyAuth(t *testing.T) {
	if *sshuser == "" {
		t.Log("ssh.user not defined, skipping test")
		return
	}
	host, err := host.FromString("localhost:22")
	if err != nil {
		t.Fatal(err)
	}
	host.User = *sshuser
	host.Keyfiles = []string{*sshprivkey}

	cmd, err := Command(host, "echo %s", 42)
	if err != nil {
		t.Fatal(err)
	}

	res, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatal(err)
	}
	if string(res) != "42" {
		t.Fatalf("stdout: %s != %v", res, 42)
	}
}
Example #2
0
File: ctrl.go Project: afajl/ctrl
func (c Ctrl) ForHost(h interface{}) Ctrl {
	switch ht := h.(type) {
	case string:
		newh, err := host.FromString(ht)
		if err != nil {
			panic(fmt.Sprintf("could not parse host: %s", err))
		}
		c.host = newh
	case *host.Host:
		c.host = new(host.Host)
		*c.host = *ht
	case host.Host:
		c.host = &ht
	default:
		panic(fmt.Sprintf("unkown type %q", ht))
	}
	return c
}