Skip to content
quarry Artifact [95d432f604]
Login

Artifact [95d432f604]

Artifact 95d432f604857b7101d8ed3acb0398e2f37d43061f433ce72dd2c48b7f3dbfd1:


package api

import "testing"

// One Fossil repository has many spellings: a default port, a letter
// case or a slash is not a different place, a different path is.
func TestSameFossilRemoteNamesOnePlace(t *testing.T) {
	up := "https://fossil.example.org/quarry"
	if !sameFossilRemote("https://fossil.example.org/repo/xfer", "https://FOSSIL.example.org:443/%72epo/") {
		t.Error("FAIL: /repo/xfer and /%72epo/ read as different places")
	}
	for _, same := range []string{
		"https://fossil.example.org/quarry/", "https://FOSSIL.example.org/quarry",
		"https://fossil.example.org:443/quarry", "http://fossil.example.org/quarry",
		"https://fossil.example.org/quarry/xfer", "https://fossil.example.org/quarry/xfer/",
		"https://fossil.example.org/%71uarry", "https://fossil.example.org//quarry",
		"https://fossil.example.org/a/../quarry",
	} {
		if !sameFossilRemote(same, up) {
			t.Errorf("FAIL: %q reads as a different place from %q", same, up)
		}
	}
	for _, other := range []string{
		"https://fossil.example.org/other", "https://fossil.example.org:8443/quarry",
		"https://other.example.org/quarry", "https://fossil.example.org/quarry/other", "https://fossil.example.org/xfer", "",
	} {
		if sameFossilRemote(other, up) {
			t.Errorf("FAIL: %q reads as the same place as %q", other, up)
		}
	}
	t.Log("ok")
}

func TestAFossilRemoteBecomesItsWebAddress(t *testing.T) {
	for remote, want := range map[string]string{
		"https://fossil.craftdesign.group/quarry": "fossil.craftdesign.group quarry",
		"https://Fossil.Example.org:8443/a/b/":    "fossil.example.org:8443 a/b",
		"https://fossil.example.org/":             "fossil.example.org ",
	} {
		h, p := fossilPlace(remote)
		if got := h + " " + p; got != want {
			t.Errorf("FAIL: %q -> %q, want %q", remote, got, want)
		}
	}
	t.Log("ok")
}