예제 #1
0
func TestNewSSHClient(t *testing.T) {
	s, _ := tests.NewSSHServer()
	port, err := s.Start()
	if err != nil {
		t.Fatalf("Error starting ssh server: %s", err)
	}
	d := &tests.MockDriver{
		Port: port,
		BaseDriver: drivers.BaseDriver{
			IPAddress:  "127.0.0.1",
			SSHKeyPath: "",
		},
	}
	c, err := NewSSHClient(d)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}

	cmd := "foo"
	RunCommand(c, cmd)
	if !s.Connected {
		t.Fatalf("Error!")
	}

	if _, ok := s.Commands[cmd]; !ok {
		t.Fatalf("Expected command: %s", cmd)
	}
}
예제 #2
0
func TestTransfer(t *testing.T) {
	s, _ := tests.NewSSHServer()
	port, err := s.Start()
	if err != nil {
		t.Fatalf("Error starting ssh server: %s", err)
	}
	d := &tests.MockDriver{
		Port: port,
		BaseDriver: drivers.BaseDriver{
			IPAddress:  "127.0.0.1",
			SSHKeyPath: "",
		},
	}
	c, err := NewSSHClient(d)
	if err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}

	dest := "bar"
	if err := Transfer([]byte("testcontents"), "/tmp", dest, "0777", c); err != nil {
		t.Fatalf("Unexpected error: %s", err)
	}
}