go_dreamfactory/cmd/v2/service/ssh_test.go
2022-09-27 11:43:50 +08:00

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)
}
}