45 lines
794 B
Go
45 lines
794 B
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
username = "root"
|
|
password = "Legu.cc()123"
|
|
ip = "10.0.0.9"
|
|
port = 22
|
|
cmd = "ls"
|
|
cmds = "cd /home/liwei/go_dreamfactory&&git pull&&exit" //exit结尾,否则程序不会退出
|
|
)
|
|
|
|
func TestRunShell(t *testing.T) {
|
|
ciphers := []string{}
|
|
ssh := &SSHService{}
|
|
|
|
err := ssh.Connect(username, password, ip, "", port, ciphers)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// ssh.RunShell("cd /opt")
|
|
ssh.RunShell(cmds)
|
|
|
|
}
|
|
|
|
func TestScp(t *testing.T) {
|
|
ciphers := []string{}
|
|
ssh := &SSHService{}
|
|
|
|
err := ssh.Connect(username, password, ip, "", port, ciphers)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := ssh.ScpCopy(`E:/svn/dreamworks/client/dreamworks/ExcelFile/testscp.txt`, "/opt"); err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
|
|
}
|