go_dreamfactory/cmd/v2/service/ssh_test.go
2022-09-28 23:08:15 +08:00

59 lines
1.1 KiB
Go

package service
import (
"fmt"
"path"
"path/filepath"
"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)
}
path := filepath.Join(`E:/svn/dreamworks/client/dreamworks/ExcelFile/JSON/`, "game_vikingchallenge.json")
fmt.Println(path)
if err := ssh.ScpCopy(path, "/opt/json/"); err != nil {
fmt.Println(err)
}
}
func TestPath(t *testing.T) {
Dir := `E:/svn/dreamworks/client/dreamworks/ExcelFile/JSON/`
mypath := filepath.Join(Dir, "a.json")
s := filepath.ToSlash(mypath)
fmt.Println(path.Base(s))
}
func TestMath(t *testing.T) {
a := float64(10) / float64(3)
fmt.Println(a)
}