Skip to content
quarry Artifact [a3813b2640]
Login

Artifact [a3813b2640]

Artifact a3813b2640e4a1db833fd34f5cef78acdb3bc62fd294d8781541226567a5fd11:


package api

import "testing"

func TestAMirrorRemoteBecomesItsWebAddress(t *testing.T) {
	for remote, want := range map[string]string{
		"[email protected]:owner/repo.git":          "github.com owner/repo",
		"ssh://[email protected]/owner/repo.git":    "github.com owner/repo",
		"ssh://[email protected]:2222/g/sub/r":    "host.example g/sub/r",
		"[email protected]:group/sub/repo":  "gitlab.example.org group/sub/repo",
		"ssh://[email protected]:2222/~/repo.git": " ",
	} {
		h, p := gitRemoteHostPath(remote)
		if got := h + " " + p; got != want {
			t.Errorf("FAIL: %q -> %q, want %q", remote, got, want)
		}
	}
}

// A repository that broke out of a Git upstream mirrors to a new
// repository, never back into the old one: every spelling of the old
// address is the same place.
func TestSameGitRemoteNamesOnePlace(t *testing.T) {
	old := "https://github.com/danmestas/notify"
	for _, same := range []string{"[email protected]:danmestas/notify.git", "ssh://[email protected]/danmestas/notify",
		"https://github.com/danmestas/notify.git", "https://GitHub.com/danmestas/notify/"} {
		if !sameGitRemote(same, old) {
			t.Errorf("FAIL: %q reads as a different repository from %q", same, old)
		}
	}
	for _, other := range []string{"[email protected]:danmestas/notify-quarry.git", "[email protected]:danmestas/notify.git", ""} {
		if sameGitRemote(other, old) {
			t.Errorf("FAIL: %q reads as the same repository as %q", other, old)
		}
	}
}