package main
import "testing"
// The clone URL handed to a CI worker. ":8950" is a legitimate listen
// address meaning "every interface", and the naive concatenation made
// it "http://:8950/r/quarry" — which zit rejects outright, so every
// pipeline failed its clone in under a second and every landing armed
// for green sat open forever. It cost a night's CI before anyone read
// the drained log closely enough to see the URL.
func TestCloneBaseNamesAHost(t *testing.T) {
for _, tc := range []struct{ addr, override, want string }{
{":8950", "", "http://127.0.0.1:8950/r/"},
// Every spelling of "listen everywhere" — none is dialable.
{"0.0.0.0:8950", "", "http://127.0.0.1:8950/r/"},
{"[::]:8950", "", "http://127.0.0.1:8950/r/"},
{"100.127.80.78:8950", "", "http://100.127.80.78:8950/r/"},
{"127.0.0.1:8080", "", "http://127.0.0.1:8080/r/"},
// An override wins, with or without its trailing slash, so a
// worker on another box can be told where the forge really is.
{":8950", "https://forge.example", "https://forge.example/r/"},
{":8950", "https://forge.example/", "https://forge.example/r/"},
} {
if got := cloneBaseFor(tc.addr, tc.override); got != tc.want {
t.Errorf("cloneBaseFor(%q, %q) = %q, want %q", tc.addr, tc.override, got, tc.want)
}
}
}