Add some tests for uname/hname parsing

This commit is contained in:
Kovid Goyal
2023-09-08 16:23:09 +05:30
parent af4213579c
commit 6fef176918

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"kitty/tools/utils"
"os"
"os/user"
"path/filepath"
"testing"
@@ -14,6 +15,10 @@ import (
var _ = fmt.Print
type Pair struct {
Input, Uname, Host string
}
func TestSSHConfigParsing(t *testing.T) {
tdir := t.TempDir()
hostname := "unmatched"
@@ -128,4 +133,20 @@ func TestSSHConfigParsing(t *testing.T) {
t.Fatal(ci)
}
u, _ := user.Current()
un := u.Username
for _, x := range []Pair{
{"localhost:12", un, "localhost"},
{"@localhost", un, "@localhost"},
{"ssh://@localhost:33", un, "localhost"},
{"me@localhost", "me", "localhost"},
{"ssh://me@localhost:12/something?else=1", "me", "localhost"},
} {
ue, uh := get_destination(x.Input)
q := Pair{x.Input, ue, uh}
if diff := cmp.Diff(x, q); diff != "" {
t.Fatalf("Failed: %s", diff)
}
}
}