forked from tsoding/snitch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
42 lines (38 loc) · 1.55 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"testing"
)
func TestMain_GetRepoFromRemoteURL(t *testing.T) {
serviceURL := "github.com"
tests := []struct {
in string
out *string
}{
{"https://bitbucket.org/user/project.git", nil},
{"https://github.com/user/project", stringPtr("user/project")},
{"https://github.com/user/project/", stringPtr("user/project")},
{"https://github.com/user/project.git", stringPtr("user/project")},
{"https://github.com/user/project.with.dot.git", stringPtr("user/project.with.dot")},
{"https://github.com/long/path/to/project", stringPtr("long/path/to/project")},
{"https://github.com/long/path/to/project.git", stringPtr("long/path/to/project")},
{"https://github.com/long/path/to/project.git/", stringPtr("long/path/to/project")},
{"ssh://[email protected]:22/user/project.git", stringPtr("user/project")},
{"ssh://[email protected]:22/long/path/to/project.git", stringPtr("long/path/to/project")},
{"ssh://[email protected]:user/project.git", stringPtr("user/project")},
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
if got := getRepoFromRemoteURL(serviceURL, tt.in); !stringPtrEqual(got, tt.out) {
t.Errorf("got %q, want %q", derefString(got), derefString(tt.out))
}
})
}
}
func TestMain_GetRepoFromRemoteURLWithPort(t *testing.T) {
serviceURL := "gitea.com:80"
gitRemote := "https://gitea.com:80/user/path.git"
expected := stringPtr("user/path")
if got := getRepoFromRemoteURL(serviceURL, gitRemote); !stringPtrEqual(got, expected) {
t.Errorf("got %q, want %q", derefString(got), derefString(expected))
}
}