feat: support ~ (tilde) expansion in match_dirs paths
This commit is contained in:
parent
c293e233d2
commit
ac780231a8
2 changed files with 66 additions and 0 deletions
|
|
@ -539,3 +539,55 @@ func TestGetHost_MatchDirsIntegration(t *testing.T) {
|
|||
t.Errorf("expected codeberg.org, got %s", host.Hostname)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveHostByPath_TildeExpansion(t *testing.T) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Skip("cannot determine home directory")
|
||||
}
|
||||
|
||||
cfg := &Config{
|
||||
Hosts: map[string]HostConfig{
|
||||
"tilde.org": {
|
||||
Hostname: "tilde.org",
|
||||
Token: "t1",
|
||||
MatchDirs: []string{"~/repos"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
got := cfg.ResolveHostByPath(filepath.Join(home, "repos", "myproject"))
|
||||
if got != "tilde.org" {
|
||||
t.Errorf("expected tilde.org, got %q", got)
|
||||
}
|
||||
|
||||
got = cfg.ResolveHostByPath(filepath.Join(home, "other"))
|
||||
if got != "" {
|
||||
t.Errorf("expected empty, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandHome(t *testing.T) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Skip("cannot determine home directory")
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{"~/repos", filepath.Join(home, "repos")},
|
||||
{"~", home},
|
||||
{"/absolute/path", "/absolute/path"},
|
||||
{"relative/path", "relative/path"},
|
||||
{"~other", "~other"}, // only ~/... is expanded, not ~user
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
got := expandHome(tt.input)
|
||||
if got != tt.want {
|
||||
t.Errorf("expandHome(%q) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue