From 6fef176918b5c6010522e62c3009f27a0ca72de9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 8 Sep 2023 16:23:09 +0530 Subject: [PATCH] Add some tests for uname/hname parsing --- kittens/ssh/config_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/kittens/ssh/config_test.go b/kittens/ssh/config_test.go index 62d596f57..eb5b28713 100644 --- a/kittens/ssh/config_test.go +++ b/kittens/ssh/config_test.go @@ -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) + } + } + }