package external import "testing" func TestSplitRemote(t *testing.T) { for _, tc := range []struct { remote, host, ownerRepo string ok bool }{ {"ssh://git@git.hypertheory-labs.dev:2222/loom/loom-cli.git", "git.hypertheory-labs.dev", "loom/loom-cli", true}, {"ssh://git@git.hypertheory-labs.dev/loom/loom-cli.git", "git.hypertheory-labs.dev", "loom/loom-cli", true}, {"git@github.com:octocat/Hello-World.git", "github.com", "octocat/Hello-World", true}, {"https://gitlab.com/gitlab-org/gitlab-svgs.git", "gitlab.com", "gitlab-org/gitlab-svgs", true}, {"https://gitlab.com/gitlab-org/gitlab-svgs", "gitlab.com", "gitlab-org/gitlab-svgs", true}, // A nested group is not owner/repo, and guessing would produce a URL // that answers about the wrong repository. {"https://gitlab.com/group/sub/project.git", "", "", false}, {"/srv/git/bare.git", "", "", false}, {"", "", "", false}, } { host, or, ok := splitRemote(tc.remote) if ok != tc.ok || host != tc.host || or != tc.ownerRepo { t.Errorf("splitRemote(%q) = (%q, %q, %v), want (%q, %q, %v)", tc.remote, host, or, ok, tc.host, tc.ownerRepo, tc.ok) } } } func TestSelfVisibilityUnknownOutsideARepo(t *testing.T) { // Failing open matters: "cannot tell" must not read as "not public". if _, known := selfVisibility(t.TempDir()); known { t.Error("selfVisibility in a non-repository reported a known answer") } }