feat: auto detect hostname

This commit is contained in:
Romain Bertrand 2026-01-05 12:47:28 +01:00
parent 2c27823e18
commit c0baf4fa3b
13 changed files with 300 additions and 125 deletions

View file

@ -49,7 +49,7 @@ func TestConfig_GetHost(t *testing.T) {
},
}
host, err := cfg.GetHost("codeberg.org")
host, err := cfg.GetHost("codeberg.org", "")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
@ -58,7 +58,7 @@ func TestConfig_GetHost(t *testing.T) {
t.Errorf("Expected hostname 'codeberg.org', got '%s'", host.Hostname)
}
_, err = cfg.GetHost("nonexistent.org")
_, err = cfg.GetHost("nonexistent.org", "")
if err == nil {
t.Error("Expected error for nonexistent host")
}
@ -261,7 +261,7 @@ func TestConfig_GetHost_EmptyString(t *testing.T) {
}
// Empty hostname should default to codeberg.org
host, err := cfg.GetHost("")
host, err := cfg.GetHost("", "")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
@ -282,7 +282,7 @@ func TestConfig_GetHost_WhitespaceString(t *testing.T) {
}
// Whitespace-only hostname should default to codeberg.org
host, err := cfg.GetHost(" ")
host, err := cfg.GetHost(" ", "")
if err == nil {
t.Logf("Got host: %+v (this may be expected behavior)", host)
} else {
@ -301,7 +301,7 @@ func TestConfig_SetHost_EmptyToken(t *testing.T) {
cfg.SetHost("codeberg.org", hostConfig)
host, err := cfg.GetHost("codeberg.org")
host, err := cfg.GetHost("codeberg.org", "")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
@ -331,7 +331,7 @@ func TestConfig_SetHost_OverwriteExisting(t *testing.T) {
cfg.SetHost("codeberg.org", newConfig)
host, err := cfg.GetHost("codeberg.org")
host, err := cfg.GetHost("codeberg.org", "")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
@ -374,7 +374,7 @@ func TestConfig_MultipleHosts(t *testing.T) {
// Verify each host can be retrieved correctly
for _, h := range hosts {
host, err := cfg.GetHost(h.hostname)
host, err := cfg.GetHost(h.hostname, "")
if err != nil {
t.Errorf("Failed to get host %s: %v", h.hostname, err)
continue
@ -408,12 +408,12 @@ func TestConfig_GitProtocol(t *testing.T) {
})
// Verify protocols are stored correctly
sshHost, _ := cfg.GetHost("test-ssh.org")
sshHost, _ := cfg.GetHost("test-ssh.org", "")
if sshHost.GitProtocol != "ssh" {
t.Errorf("Expected git_protocol 'ssh', got '%s'", sshHost.GitProtocol)
}
httpsHost, _ := cfg.GetHost("test-https.org")
httpsHost, _ := cfg.GetHost("test-https.org", "")
if httpsHost.GitProtocol != "https" {
t.Errorf("Expected git_protocol 'https', got '%s'", httpsHost.GitProtocol)
}