krz/gitbay
A CLI-first git forge.
clone: git clone https://gitbay.org/krz/gitbay.git
main: internal/cliconfig/cliconfig_test.go · raw
1package cliconfig
2
3import "testing"
4
5func TestParseRemoteURL(t *testing.T) {
6 cases := []struct {
7 url string
8 host string
9 port int
10 user string
11 repo string
12 ok bool
13 }{
14 {"ssh://git@gitbay.example/alice/proj.git", "gitbay.example", 0, "git", "alice/proj", true},
15 {"ssh://git@gitbay.example:2222/alice/proj.git", "gitbay.example", 2222, "git", "alice/proj", true},
16 {"ssh://gitbay.example/alice/proj", "gitbay.example", 0, "", "alice/proj", true},
17 {"git@gitbay.example:alice/proj.git", "gitbay.example", 0, "git", "alice/proj", true},
18 {"git@gitbay.example:alice/proj", "gitbay.example", 0, "git", "alice/proj", true},
19 {"https://gitbay.example/alice/proj.git", "", 0, "", "", false},
20 {"/local/path/repo.git", "", 0, "", "", false},
21 }
22 for _, tc := range cases {
23 inst, repo, ok := ParseRemoteURL(tc.url)
24 if ok != tc.ok {
25 t.Errorf("%s: ok = %v, want %v", tc.url, ok, tc.ok)
26 continue
27 }
28 if !ok {
29 continue
30 }
31 if inst.Host != tc.host || inst.Port != tc.port || inst.User != tc.user || repo != tc.repo {
32 t.Errorf("%s: got host=%s port=%d user=%s repo=%s", tc.url, inst.Host, inst.Port, inst.User, repo)
33 }
34 }
35}
36
37func TestCloneURL(t *testing.T) {
38 i := Instance{Host: "gitbay.example"}
39 if got := i.CloneURL("a/b"); got != "ssh://git@gitbay.example/a/b.git" {
40 t.Errorf("CloneURL = %s", got)
41 }
42 i = Instance{Host: "gitbay.example", Port: 2222, User: "u"}
43 if got := i.CloneURL("a/b"); got != "ssh://u@gitbay.example:2222/a/b.git" {
44 t.Errorf("CloneURL = %s", got)
45 }
46}