Skip to content
quarry Artifact [c4b0c9872a]
Login

Artifact [c4b0c9872a]

Artifact c4b0c9872aca82bea98391fe5162c2407749e5968a031a5bcfd44e33f9da47d8:


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/",
		// jva, ^2610: a port, a leading slash and GitHub's SSH-over-443 host.
		"ssh://[email protected]:22/danmestas/notify.git", "[email protected]:/danmestas/notify.git",
		"ssh://[email protected]:443/danmestas/notify.git"} {
		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)
		}
	}
}