forked from hypersleep/easyssh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasyssh_test.go
54 lines (47 loc) · 987 Bytes
/
easyssh_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package easyssh
import (
"fmt"
"testing"
)
var sshConfig = &SSHConfig{
User: "test",
Server: "192.168.2.24",
Key: "/home/test/.ssh/id_rsa",
Port: "22",
}
func TestRun(t *testing.T) {
commands := []string{
"ls -lt",
}
for _, cmd := range commands {
err := sshConfig.RtRun(cmd, func(out string, lineType int) {
fmt.Println(out)
})
if err != nil {
fmt.Println("error: " + err.Error())
t.FailNow()
}
}
}
func TestSSHConfig_Scp(t *testing.T) {
// Call Scp method with file you want to upload to remote server.
err := sshConfig.Scp("/tmp/hello", "/tmp/target.html")
// Handle errors
if err != nil {
panic("Can't run remote command: " + err.Error())
} else {
fmt.Println("success")
out, eOut, _ := sshConfig.Run("cat /tmp/target.html")
fmt.Println(out, eOut)
}
}
func TestSSHConfig_RunScript(t *testing.T) {
script := `
ls -l /tmp
echo list tmp done
`
err := sshConfig.RunScript(script)
if err != nil {
t.Error(err)
}
}