package main import "testing" func TestWebBaseFindsTheServerBehindEveryRemoteForm(t *testing.T) { good := [][2]string{ {"https://barerepo.example/john/johnbot", "https://barerepo.example"}, {"https://barerepo.example/john/johnbot.git", "https://barerepo.example"}, {"http://x:gt_live_abc@127.0.0.1:3999/john/johnbot", "http://127.0.0.1:3999"}, {"git@barerepo.example:john/johnbot.git", "https://barerepo.example"}, {"barerepo.example:john/johnbot", "https://barerepo.example"}, {"ssh://git@barerepo.example/john/johnbot", "https://barerepo.example"}, {"ssh://git@barerepo.example:2222/john/johnbot", "https://barerepo.example"}, } for _, c := range good { got, err := webBase(c[0]) if err != nil || got != c[1] { t.Errorf("webBase(%q) = %q, %v; want %q", c[0], got, err, c[1]) } } for _, bad := range []string{"", " ", "johnbot", "https:///john/johnbot"} { if got, err := webBase(bad); err == nil { t.Errorf("webBase(%q) = %q, want an error", bad, got) } } }