|
| 1 | +package url |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestMatchesScpLike(t *testing.T) { |
| 8 | + examples := []string{ |
| 9 | + |
| 10 | + |
| 11 | + "[email protected]:22:james/bond", |
| 12 | + |
| 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