[mike@mwxm4]

This commit is contained in:
2026-08-11 11:40:32 +02:00
parent 113527f220
commit 39f5b48d94
14 changed files with 719 additions and 39 deletions
+71
View File
@@ -499,6 +499,77 @@ remotes = hub, public
}
}
// TestInactiveRemoteIsOnlyUsedWhenNamed: `active = false` takes a target off the
// automatic path — not used when no name is given — while naming it, by name or
// by host, still reaches it. It is not the same as removing the target, and not
// the same as an unusable one: it stays in the configuration, listed and ready.
func TestInactiveRemoteIsOnlyUsedWhenNamed(t *testing.T) {
rc := `
remote.gitea.url = https://git.example.com
remote.gitea.key = tok
remote.gitea.active = false
remote.hub.url = https://github.com
remote.hub.key = tok2
`
var c Config
applyConfig(&c, parseConfig(rc))
all, incomplete := c.mirrorTargets()
if len(all) != 2 || len(incomplete) != 0 {
t.Fatalf("mirrorTargets = %+v (incomplete %v), want both targets", all, incomplete)
}
if got := pickRemotes(all, nil); len(got) != 1 || got[0].Name != "hub" {
t.Errorf("selection without a name = %+v, want only the active hub", got)
}
for _, sel := range []string{"gitea", "@gitea", "git.example.com"} {
if got := pickRemotes(all, []string{sel}); len(got) != 1 || got[0].Name != "gitea" {
t.Errorf("pickRemotes(%q) = %+v, want the inactive gitea", sel, got)
}
}
// MGSH_REMOTE_<NAME>_ACTIVE is the environment spelling
t.Setenv("MGSH_REMOTE_HUB_ACTIVE", "false")
var c2 Config
applyConfig(&c2, parseConfig(rc))
applyEnv(&c2)
all2, _ := c2.mirrorTargets()
if got := pickRemotes(all2, nil); len(got) != 0 {
t.Errorf("MGSH_REMOTE_HUB_ACTIVE=false left %+v in the default set", got)
}
}
// TestRemoteActiveDefaultsToOn: the setting exists to take a server *out* of the
// default set, so anything but a deliberate "off" — unset, "true", a typo — has
// to leave it in. A configuration written before the flag existed must not
// suddenly stop mirroring.
func TestRemoteActiveDefaultsToOn(t *testing.T) {
for _, v := range []string{"", "true", "yes", "1", "on", "sometimes"} {
if !(RemoteTarget{Active: v}).isActive() {
t.Errorf("active = %q switched the target off", v)
}
}
for _, v := range []string{"false", "no", "0", "off", " FALSE "} {
if (RemoteTarget{Active: v}).isActive() {
t.Errorf("active = %q did not switch the target off", v)
}
}
}
// TestPushRemoteWithOnlyInactiveTargets: the message has to name the reason.
// "needs a remote.<name>.url" would send the user looking for a setting that is
// sitting right there in the file.
func TestPushRemoteWithOnlyInactiveTargets(t *testing.T) {
dir := useProject(t, "notes")
mustGit(t, dir, "init", "-q")
cfg.Remotes = []RemoteTarget{{Name: "gitea", URL: "https://git.example.com", Key: "tok", Active: "false"}}
out := captureStdout(t, func() { runCommand("pushremote") })
if !strings.Contains(out, "inactive") || !strings.Contains(out, "@gitea") {
t.Errorf("output = %q, want it to report the inactive target and how to name it", out)
}
}
func TestParsePushRemoteArgs(t *testing.T) {
cases := []struct {
in string