package config import "testing" func TestIdentityFollowsTheHostTheServerAnswersOn(t *testing.T) { cases := []struct{ user, sshHost, external, want string }{ {"", "", "https://barerepo.com", "git@barerepo.com"}, {"barerepo", "", "https://barerepo.com", "barerepo@barerepo.com"}, {"", "barerepo.com", "https://other.example", "git@barerepo.com"}, {"", "", "", "git@localhost"}, } for _, c := range cases { cfg := Default() cfg.Server.SSHUser, cfg.Server.SSHHost, cfg.Server.ExternalURL = c.user, c.sshHost, c.external if got := cfg.Identity(); got != c.want { t.Errorf("Identity(user=%q host=%q ext=%q) = %q, want %q", c.user, c.sshHost, c.external, got, c.want) } } cfg := Default() cfg.Server.GitIdentity = "someone@else" if got := cfg.Identity(); got != "someone@else" { t.Errorf("a configured identity was ignored, got %q", got) } }