[PATCH 13/13] tests: add tests for the new url-parse builtin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Matheus Afonso Martins Moreira <matheus@xxxxxxxxxxxxxxxxxx>

Test git URL parsing, validation and component extraction
on all documented git URL schemes and syntaxes.

Signed-off-by: Matheus Afonso Martins Moreira <matheus@xxxxxxxxxxxxxxxxxx>
---
 t/t9904-url-parse.sh | 194 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 194 insertions(+)
 create mode 100755 t/t9904-url-parse.sh

diff --git a/t/t9904-url-parse.sh b/t/t9904-url-parse.sh
new file mode 100755
index 00000000000..f147f00591c
--- /dev/null
+++ b/t/t9904-url-parse.sh
@@ -0,0 +1,194 @@
+#!/bin/sh
+#
+# Copyright © 2024 Matheus Afonso Martins Moreira
+#
+
+test_description='git url-parse tests'
+
+. ./test-lib.sh
+
+test_expect_success 'git url-parse -- ssh syntax' '
+	git url-parse "ssh://user@xxxxxxxxxxx:1234/repository/path" &&
+	git url-parse "ssh://user@xxxxxxxxxxx/repository/path" &&
+	git url-parse "ssh://example.com:1234/repository/path" &&
+	git url-parse "ssh://example.com/repository/path"
+'
+
+test_expect_success 'git url-parse -- git syntax' '
+	git url-parse "git://example.com:1234/repository/path" &&
+	git url-parse "git://example.com/repository/path"
+'
+
+test_expect_success 'git url-parse -- http syntax' '
+	git url-parse "https://example.com:1234/repository/path"; &&
+	git url-parse "https://example.com/repository/path"; &&
+	git url-parse "http://example.com:1234/repository/path"; &&
+	git url-parse "http://example.com/repository/path";
+'
+
+test_expect_success 'git url-parse -- scp syntax' '
+	git url-parse "user@xxxxxxxxxxx:/repository/path" &&
+	git url-parse "example.com:/repository/path"
+'
+
+test_expect_success 'git url-parse -- username expansion - ssh syntax' '
+	git url-parse "ssh://user@xxxxxxxxxxx:1234/~user/repository" &&
+	git url-parse "ssh://user@xxxxxxxxxxx/~user/repository" &&
+	git url-parse "ssh://example.com:1234/~user/repository" &&
+	git url-parse "ssh://example.com/~user/repository"
+'
+
+test_expect_success 'git url-parse -- username expansion - git syntax' '
+	git url-parse "git://example.com:1234/~user/repository" &&
+	git url-parse "git://example.com/~user/repository"
+'
+
+test_expect_success 'git url-parse -- username expansion - scp syntax' '
+	git url-parse "user@xxxxxxxxxxx:~user/repository" &&
+	git url-parse "example.com:~user/repository"
+'
+
+test_expect_success 'git url-parse -- file urls' '
+	git url-parse "file:///repository/path" &&
+	git url-parse "file:///" &&
+	git url-parse "file://"
+'
+
+test_expect_success 'git url-parse -c protocol -- ssh syntax' '
+	test ssh = "$(git url-parse -c protocol "ssh://user@xxxxxxxxxxx:1234/repository/path")" &&
+	test ssh = "$(git url-parse -c protocol "ssh://user@xxxxxxxxxxx/repository/path")" &&
+	test ssh = "$(git url-parse -c protocol "ssh://example.com:1234/repository/path")" &&
+	test ssh = "$(git url-parse -c protocol "ssh://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c protocol -- git syntax' '
+	test git = "$(git url-parse -c protocol "git://example.com:1234/repository/path")" &&
+	test git = "$(git url-parse -c protocol "git://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c protocol -- http syntax' '
+	test https = "$(git url-parse -c protocol "https://example.com:1234/repository/path";)" &&
+	test https = "$(git url-parse -c protocol "https://example.com/repository/path";)" &&
+	test http = "$(git url-parse -c protocol "http://example.com:1234/repository/path";)" &&
+	test http = "$(git url-parse -c protocol "http://example.com/repository/path";)"
+'
+
+test_expect_success 'git url-parse -c protocol -- scp syntax' '
+	test ssh = "$(git url-parse -c protocol "user@xxxxxxxxxxx:/repository/path")" &&
+	test ssh = "$(git url-parse -c protocol "example.com:/repository/path")"
+'
+
+test_expect_success 'git url-parse -c user -- ssh syntax' '
+	test user = "$(git url-parse -c user "ssh://user@xxxxxxxxxxx:1234/repository/path")" &&
+	test user = "$(git url-parse -c user "ssh://user@xxxxxxxxxxx/repository/path")" &&
+	test "" = "$(git url-parse -c user "ssh://example.com:1234/repository/path")" &&
+	test "" = "$(git url-parse -c user "ssh://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c user -- git syntax' '
+	test "" = "$(git url-parse -c user "git://example.com:1234/repository/path")" &&
+	test "" = "$(git url-parse -c user "git://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c user -- http syntax' '
+	test "" = "$(git url-parse -c user "https://example.com:1234/repository/path";)" &&
+	test "" = "$(git url-parse -c user "https://example.com/repository/path";)" &&
+	test "" = "$(git url-parse -c user "http://example.com:1234/repository/path";)" &&
+	test "" = "$(git url-parse -c user "http://example.com/repository/path";)"
+'
+
+test_expect_success 'git url-parse -c user -- scp syntax' '
+	test user = "$(git url-parse -c user "user@xxxxxxxxxxx:/repository/path")" &&
+	test "" = "$(git url-parse -c user "example.com:/repository/path")"
+'
+
+test_expect_success 'git url-parse -c host -- ssh syntax' '
+	test example.com = "$(git url-parse -c host "ssh://user@xxxxxxxxxxx:1234/repository/path")" &&
+	test example.com = "$(git url-parse -c host "ssh://user@xxxxxxxxxxx/repository/path")" &&
+	test example.com = "$(git url-parse -c host "ssh://example.com:1234/repository/path")" &&
+	test example.com = "$(git url-parse -c host "ssh://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c host -- git syntax' '
+	test example.com = "$(git url-parse -c host "git://example.com:1234/repository/path")" &&
+	test example.com = "$(git url-parse -c host "git://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c host -- http syntax' '
+	test example.com = "$(git url-parse -c host "https://example.com:1234/repository/path";)" &&
+	test example.com = "$(git url-parse -c host "https://example.com/repository/path";)" &&
+	test example.com = "$(git url-parse -c host "http://example.com:1234/repository/path";)" &&
+	test example.com = "$(git url-parse -c host "http://example.com/repository/path";)"
+'
+
+test_expect_success 'git url-parse -c host -- scp syntax' '
+	test example.com = "$(git url-parse -c host "user@xxxxxxxxxxx:/repository/path")" &&
+	test example.com = "$(git url-parse -c host "example.com:/repository/path")"
+'
+
+test_expect_success 'git url-parse -c port -- ssh syntax' '
+	test 1234 = "$(git url-parse -c port "ssh://user@xxxxxxxxxxx:1234/repository/path")" &&
+	test "" = "$(git url-parse -c port "ssh://user@xxxxxxxxxxx/repository/path")" &&
+	test 1234 = "$(git url-parse -c port "ssh://example.com:1234/repository/path")" &&
+	test "" = "$(git url-parse -c port "ssh://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c port -- git syntax' '
+	test 1234 = "$(git url-parse -c port "git://example.com:1234/repository/path")" &&
+	test "" = "$(git url-parse -c port "git://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c port -- http syntax' '
+	test 1234 = "$(git url-parse -c port "https://example.com:1234/repository/path";)" &&
+	test "" = "$(git url-parse -c port "https://example.com/repository/path";)" &&
+	test 1234 = "$(git url-parse -c port "http://example.com:1234/repository/path";)" &&
+	test "" = "$(git url-parse -c port "http://example.com/repository/path";)"
+'
+
+test_expect_success 'git url-parse -c port -- scp syntax' '
+	test "" = "$(git url-parse -c port "user@xxxxxxxxxxx:/repository/path")" &&
+	test "" = "$(git url-parse -c port "example.com:/repository/path")"
+'
+
+test_expect_success 'git url-parse -c path -- ssh syntax' '
+	test "/repository/path" = "$(git url-parse -c path "ssh://user@xxxxxxxxxxx:1234/repository/path")" &&
+	test "/repository/path" = "$(git url-parse -c path "ssh://user@xxxxxxxxxxx/repository/path")" &&
+	test "/repository/path" = "$(git url-parse -c path "ssh://example.com:1234/repository/path")" &&
+	test "/repository/path" = "$(git url-parse -c path "ssh://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c path -- git syntax' '
+	test "/repository/path" = "$(git url-parse -c path "git://example.com:1234/repository/path")" &&
+	test "/repository/path" = "$(git url-parse -c path "git://example.com/repository/path")"
+'
+
+test_expect_success 'git url-parse -c path -- http syntax' '
+	test "/repository/path" = "$(git url-parse -c path "https://example.com:1234/repository/path";)" &&
+	test "/repository/path" = "$(git url-parse -c path "https://example.com/repository/path";)" &&
+	test "/repository/path" = "$(git url-parse -c path "http://example.com:1234/repository/path";)" &&
+	test "/repository/path" = "$(git url-parse -c path "http://example.com/repository/path";)"
+'
+
+test_expect_success 'git url-parse -c path -- scp syntax' '
+	test "/repository/path" = "$(git url-parse -c path "user@xxxxxxxxxxx:/repository/path")" &&
+	test "/repository/path" = "$(git url-parse -c path "example.com:/repository/path")"
+'
+
+test_expect_success 'git url-parse -c path -- username expansion - ssh syntax' '
+	test "~user/repository" = "$(git url-parse -c path "ssh://user@xxxxxxxxxxx:1234/~user/repository")" &&
+	test "~user/repository" = "$(git url-parse -c path "ssh://user@xxxxxxxxxxx/~user/repository")" &&
+	test "~user/repository" = "$(git url-parse -c path "ssh://example.com:1234/~user/repository")" &&
+	test "~user/repository" = "$(git url-parse -c path "ssh://example.com/~user/repository")"
+'
+
+test_expect_success 'git url-parse -c path -- username expansion - git syntax' '
+	test "~user/repository" = "$(git url-parse -c path "git://example.com:1234/~user/repository")" &&
+	test "~user/repository" = "$(git url-parse -c path "git://example.com/~user/repository")"
+'
+
+test_expect_success 'git url-parse -c path -- username expansion - scp syntax' '
+	test "~user/repository" = "$(git url-parse -c path "user@xxxxxxxxxxx:~user/repository")" &&
+	test "~user/repository" = "$(git url-parse -c path "example.com:~user/repository")"
+'
+
+test_done
-- 
gitgitgadget




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux