2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-04 18:10:50 +00:00

sftp: test that Args and Command options cannot be set at the same time

This commit is contained in:
Michael Eischer 2023-10-21 19:26:39 +02:00
parent 41f70f1f4f
commit 6a4d6d5da4

View File

@ -9,43 +9,57 @@ var sshcmdTests = []struct {
cfg Config cfg Config
cmd string cmd string
args []string args []string
err string
}{ }{
{ {
Config{User: "user", Host: "host", Path: "dir/subdir"}, Config{User: "user", Host: "host", Path: "dir/subdir"},
"ssh", "ssh",
[]string{"host", "-l", "user", "-s", "sftp"}, []string{"host", "-l", "user", "-s", "sftp"},
"",
}, },
{ {
Config{Host: "host", Path: "dir/subdir"}, Config{Host: "host", Path: "dir/subdir"},
"ssh", "ssh",
[]string{"host", "-s", "sftp"}, []string{"host", "-s", "sftp"},
"",
}, },
{ {
Config{Host: "host", Port: "10022", Path: "/dir/subdir"}, Config{Host: "host", Port: "10022", Path: "/dir/subdir"},
"ssh", "ssh",
[]string{"host", "-p", "10022", "-s", "sftp"}, []string{"host", "-p", "10022", "-s", "sftp"},
"",
}, },
{ {
Config{User: "user", Host: "host", Port: "10022", Path: "/dir/subdir"}, Config{User: "user", Host: "host", Port: "10022", Path: "/dir/subdir"},
"ssh", "ssh",
[]string{"host", "-p", "10022", "-l", "user", "-s", "sftp"}, []string{"host", "-p", "10022", "-l", "user", "-s", "sftp"},
"",
}, },
{ {
Config{User: "user", Host: "host", Port: "10022", Path: "/dir/subdir", Args: "-i /path/to/id_rsa"}, Config{User: "user", Host: "host", Port: "10022", Path: "/dir/subdir", Args: "-i /path/to/id_rsa"},
"ssh", "ssh",
[]string{"host", "-p", "10022", "-l", "user", "-i", "/path/to/id_rsa", "-s", "sftp"}, []string{"host", "-p", "10022", "-l", "user", "-i", "/path/to/id_rsa", "-s", "sftp"},
"",
},
{
Config{Command: "ssh something", Args: "-i /path/to/id_rsa"},
"",
nil,
"cannot specify both sftp.command and sftp.args options",
}, },
{ {
// IPv6 address. // IPv6 address.
Config{User: "user", Host: "::1", Path: "dir"}, Config{User: "user", Host: "::1", Path: "dir"},
"ssh", "ssh",
[]string{"::1", "-l", "user", "-s", "sftp"}, []string{"::1", "-l", "user", "-s", "sftp"},
"",
}, },
{ {
// IPv6 address with zone and port. // IPv6 address with zone and port.
Config{User: "user", Host: "::1%lo0", Port: "22", Path: "dir"}, Config{User: "user", Host: "::1%lo0", Port: "22", Path: "dir"},
"ssh", "ssh",
[]string{"::1%lo0", "-p", "22", "-l", "user", "-s", "sftp"}, []string{"::1%lo0", "-p", "22", "-l", "user", "-s", "sftp"},
"",
}, },
} }
@ -53,8 +67,14 @@ func TestBuildSSHCommand(t *testing.T) {
for i, test := range sshcmdTests { for i, test := range sshcmdTests {
t.Run("", func(t *testing.T) { t.Run("", func(t *testing.T) {
cmd, args, err := buildSSHCommand(test.cfg) cmd, args, err := buildSSHCommand(test.cfg)
if err != nil { if test.err != "" {
t.Fatalf("%v in test %d", err, i) if err.Error() != test.err {
t.Fatalf("expected error %v got %v", test.err, err.Error())
}
} else {
if err != nil {
t.Fatalf("%v in test %d", err, i)
}
} }
if cmd != test.cmd { if cmd != test.cmd {