mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-11 18:32:12 +02:00
Port parsing of ssh args
This commit is contained in:
@@ -5,6 +5,10 @@ package ssh
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"kitty/tools/utils/shlex"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
@@ -15,3 +19,36 @@ func TestGetSSHOptions(t *testing.T) {
|
||||
t.Fatalf("Unexpected set of SSH options: %#v", m)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSSHArgs(t *testing.T) {
|
||||
split := func(x string) []string {
|
||||
ans, err := shlex.Split(x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return ans
|
||||
}
|
||||
|
||||
p := func(args, expected_ssh_args, expected_server_args, expected_extra_args string, expected_passthrough bool) {
|
||||
ssh_args, server_args, passthrough, extra_args, err := ParseSSHArgs(split(args), "--kitten")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check := func(a, b any) {
|
||||
diff := cmp.Diff(a, b)
|
||||
if diff != "" {
|
||||
t.Fatalf("Unexpected value for args: %s\n%s", args, diff)
|
||||
}
|
||||
}
|
||||
check(split(expected_ssh_args), ssh_args)
|
||||
check(split(expected_server_args), server_args)
|
||||
check(split(expected_extra_args), extra_args)
|
||||
check(expected_passthrough, passthrough)
|
||||
}
|
||||
p(`localhost`, ``, `localhost`, ``, false)
|
||||
p(`-- localhost`, ``, `localhost`, ``, false)
|
||||
p(`-46p23 localhost sh -c "a b"`, `-4 -6 -p 23`, `localhost sh -c "a b"`, ``, false)
|
||||
p(`-46p23 -S/moose -W x:6 -- localhost sh -c "a b"`, `-4 -6 -p 23 -S /moose -W x:6`, `localhost sh -c "a b"`, ``, false)
|
||||
p(`--kitten=abc -np23 --kitten xyz host`, `-n -p 23`, `host`, `--kitten abc --kitten xyz`, true)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user