2016-02-15 18:17:41 +00:00
|
|
|
package sftp
|
|
|
|
|
2017-04-10 20:17:50 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
2016-02-15 18:17:41 +00:00
|
|
|
|
|
|
|
var sshcmdTests = []struct {
|
2017-04-10 20:17:50 +00:00
|
|
|
cfg Config
|
|
|
|
cmd string
|
|
|
|
args []string
|
2016-02-15 18:17:41 +00:00
|
|
|
}{
|
|
|
|
{
|
2017-04-10 20:17:50 +00:00
|
|
|
Config{User: "user", Host: "host", Path: "dir/subdir"},
|
|
|
|
"ssh",
|
2016-02-15 18:17:41 +00:00
|
|
|
[]string{"host", "-l", "user", "-s", "sftp"},
|
|
|
|
},
|
|
|
|
{
|
2017-04-10 20:17:50 +00:00
|
|
|
Config{Host: "host", Path: "dir/subdir"},
|
|
|
|
"ssh",
|
2016-02-15 18:17:41 +00:00
|
|
|
[]string{"host", "-s", "sftp"},
|
|
|
|
},
|
|
|
|
{
|
2017-04-10 20:17:50 +00:00
|
|
|
Config{Host: "host:10022", Path: "/dir/subdir"},
|
|
|
|
"ssh",
|
2016-02-15 18:17:41 +00:00
|
|
|
[]string{"host", "-p", "10022", "-s", "sftp"},
|
|
|
|
},
|
|
|
|
{
|
2017-04-10 20:17:50 +00:00
|
|
|
Config{User: "user", Host: "host:10022", Path: "/dir/subdir"},
|
|
|
|
"ssh",
|
2016-02-15 18:17:41 +00:00
|
|
|
[]string{"host", "-p", "10022", "-l", "user", "-s", "sftp"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuildSSHCommand(t *testing.T) {
|
2017-04-10 20:17:50 +00:00
|
|
|
for _, test := range sshcmdTests {
|
|
|
|
t.Run("", func(t *testing.T) {
|
|
|
|
cmd, args, err := buildSSHCommand(test.cfg)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2016-02-15 18:17:41 +00:00
|
|
|
}
|
2017-04-10 20:17:50 +00:00
|
|
|
|
|
|
|
if cmd != test.cmd {
|
|
|
|
t.Fatalf("cmd: want %v, got %v", test.cmd, cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(test.args, args) {
|
|
|
|
t.Fatalf("wrong args, want:\n %v\ngot:\n %v", test.args, args)
|
|
|
|
}
|
|
|
|
})
|
2016-02-15 18:17:41 +00:00
|
|
|
}
|
|
|
|
}
|