Skip to content

Commit 80d88d9

Browse files
author
Chief
committed
Add tests for SSH url matching.
Signed-off-by: Chief <[email protected]>
1 parent db0e226 commit 80d88d9

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

internal/url/url_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package url
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestMatchesScpLike(t *testing.T) {
8+
examples := []string{
9+
"[email protected]:james/bond",
10+
"[email protected]:007/bond",
11+
"[email protected]:22:james/bond",
12+
"[email protected]:22:007/bond",
13+
}
14+
15+
for _, url := range examples {
16+
if !MatchesScpLike(url) {
17+
t.Fatalf("repo url %q did not match ScpLike", url)
18+
}
19+
}
20+
}
21+
22+
func TestFindScpLikeComponents(t *testing.T) {
23+
url := "[email protected]:james/bond"
24+
user, host, port, path := FindScpLikeComponents(url)
25+
26+
if user != "git" || host != "github.com" || port != "" || path != "james/bond" {
27+
t.Fatalf("repo url %q did not match properly", user)
28+
}
29+
30+
url = "[email protected]:007/bond"
31+
user, host, port, path = FindScpLikeComponents(url)
32+
33+
if user != "git" || host != "github.com" || port != "" || path != "007/bond" {
34+
t.Fatalf("repo url %q did not match properly", user)
35+
}
36+
37+
url = "[email protected]:22:james/bond"
38+
user, host, port, path = FindScpLikeComponents(url)
39+
40+
if user != "git" || host != "github.com" || port != "22" || path != "james/bond" {
41+
t.Fatalf("repo url %q did not match properly", user)
42+
}
43+
44+
url = "[email protected]:22:007/bond"
45+
user, host, port, path = FindScpLikeComponents(url)
46+
47+
if user != "git" || host != "github.com" || port != "22" || path != "007/bond" {
48+
t.Fatalf("repo url %q did not match properly", user)
49+
}
50+
}

0 commit comments

Comments
 (0)