babashka/test-resources/lib_tests/clojure/tools/gitlibs/test_impl.clj
Gabriel Horner 4e7d04f672
Add libtest (#1112)
* Add add-libtest script and add 2 libraries with it

* Add tests for 3 existing libraries
2021-12-21 19:25:10 +01:00

36 lines
1.5 KiB
Clojure

(ns clojure.tools.gitlibs.test-impl
(:require
[clojure.test :refer :all]
[clojure.tools.gitlibs.impl :as impl]))
(deftest test-clean-url
(are [url expected-path]
(= expected-path (#'impl/clean-url url))
;; url formats - don't use user or port
"ssh://git@gitlab.com:3333/org/repo.git" "ssh/gitlab.com/org/repo"
"ssh://git@gitlab.org.net/org/repo.git" "ssh/gitlab.org.net/org/repo"
"ssh://user@host.xz/~user/repo.git/" "ssh/host.xz/_TILDE_user/repo"
"https://github.com/org/repo.git" "https/github.com/org/repo"
"git://host.xz/path/to/repo.git/" "git/host.xz/path/to/repo"
;; scp style url (most common github ssh url format)
"git@github.com:org/repo.git" "ssh/github.com/org/repo"
"git@github.com:dotted.org/dotted.repo.git" "ssh/github.com/dotted.org/dotted.repo"
"host.xz:~user/path/to/repo.git/" "ssh/host.xz/_TILDE_user/path/to/repo"
;; file scheme
"file:///Users/me/code/repo.git" "file/Users/me/code/repo"
"file://../foo.git" "file/REL/_DOTDOT_/foo"
"file://~/path/repo.git" "file/REL/_TILDE_/path/repo"
;; file repos - handle relative vs absolute, handle . .. ~
"/Users/me/code/repo.git" "file/Users/me/code/repo"
"../foo.git" "file/REL/_DOTDOT_/foo"
"./foo.git" "file/REL/_DOT_/foo"
"~user/foo.git" "file/REL/_TILDE_user/foo"
;; git - unknown transport with url rewrite in gitconfig (unusual, but do something useful)
"work:repo.git" "ssh/work/repo"))