aboutsummaryrefslogtreecommitdiffstats
path: root/internal/url/url_test.go
diff options
context:
space:
mode:
authorChief <admin@117.sh>2019-08-30 13:15:14 -0400
committerChief <admin@117.sh>2019-08-30 13:15:14 -0400
commit80d88d96cbbbef05054d53745b9488d864859fdd (patch)
tree1d6faf5f406dc4db45dc8cdab3184d645b26cdc2 /internal/url/url_test.go
parentdb0e226d48285a0ae8cda7db05d2ca20d9000dc6 (diff)
downloadgo-git-80d88d96cbbbef05054d53745b9488d864859fdd.tar.gz
Add tests for SSH url matching.
Signed-off-by: Chief <admin@117.sh>
Diffstat (limited to 'internal/url/url_test.go')
-rw-r--r--internal/url/url_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/internal/url/url_test.go b/internal/url/url_test.go
new file mode 100644
index 0000000..710fa0c
--- /dev/null
+++ b/internal/url/url_test.go
@@ -0,0 +1,50 @@
+package url
+
+import (
+ "testing"
+)
+
+func TestMatchesScpLike(t *testing.T) {
+ examples := []string{
+ "git@github.com:james/bond",
+ "git@github.com:007/bond",
+ "git@github.com:22:james/bond",
+ "git@github.com:22:007/bond",
+ }
+
+ for _, url := range examples {
+ if !MatchesScpLike(url) {
+ t.Fatalf("repo url %q did not match ScpLike", url)
+ }
+ }
+}
+
+func TestFindScpLikeComponents(t *testing.T) {
+ url := "git@github.com:james/bond"
+ user, host, port, path := FindScpLikeComponents(url)
+
+ if user != "git" || host != "github.com" || port != "" || path != "james/bond" {
+ t.Fatalf("repo url %q did not match properly", user)
+ }
+
+ url = "git@github.com:007/bond"
+ user, host, port, path = FindScpLikeComponents(url)
+
+ if user != "git" || host != "github.com" || port != "" || path != "007/bond" {
+ t.Fatalf("repo url %q did not match properly", user)
+ }
+
+ url = "git@github.com:22:james/bond"
+ user, host, port, path = FindScpLikeComponents(url)
+
+ if user != "git" || host != "github.com" || port != "22" || path != "james/bond" {
+ t.Fatalf("repo url %q did not match properly", user)
+ }
+
+ url = "git@github.com:22:007/bond"
+ user, host, port, path = FindScpLikeComponents(url)
+
+ if user != "git" || host != "github.com" || port != "22" || path != "007/bond" {
+ t.Fatalf("repo url %q did not match properly", user)
+ }
+}