-
Notifications
You must be signed in to change notification settings - Fork 4
/
git-identity-test.el
178 lines (157 loc) · 8.02 KB
/
git-identity-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
;;; -*- lexical-binding: t -*-
(require 'buttercup)
(require 'git-identity)
;; Based on the specification of git urls in the man page of git-push (1) for Git 2.28.0.
(defconst git-identity-test-identity-list
'(("[email protected]"
:name "Akira Komamura"
:domains ("github.com")
:exclude-organizations ("my-company-org" "my-another-private-org")
:dirs ("~/work/github.com/"))
:name "My name in the local language"
:organizations ("my-company-org")
:exclude-organizations ("my-another-private-org")
:domains ("github.com" "mycompany.com")
:dirs ("~/work/mycompany.com/"))))
(describe "Identity operations"
(describe "git-identity-username"
(it "Retrieves the user name of an identity"
(let ((git-identity-list git-identity-test-identity-list))
(expect (git-identity-username (car git-identity-list))
:to-equal "Akira Komamura"))))
(describe "git-identity-email"
(it "Retrieve the email address of an identity"
(let ((git-identity-list git-identity-test-identity-list))
(expect (git-identity-email (nth 1 git-identity-list))
:to-equal "[email protected]")))))
(describe "Parsing Git URLs"
(describe "git-identity-git-url-host"
(it "matches an SSH URL"
(expect (git-identity-git-url-host "ssh://github.com/path/to/repo.git")
:to-equal "github.com")
(expect (git-identity-git-url-host "ssh://github.com:22/path/to/repo.git/")
:to-equal "github.com")
(expect (git-identity-git-url-host "ssh://[email protected]/path/to/repo.git/")
:to-equal "github.com")
(expect (git-identity-git-url-host "ssh://[email protected]:22/path/to/repo.git/")
:to-equal "github.com"))
(it "matches an Git URL"
(expect (git-identity-git-url-host "git://github.com/owner/repo.git")
:to-equal "github.com")
(expect (git-identity-git-url-host "git://github.com:22/owner/repo.git/")
:to-equal "github.com"))
(it "matches an HTTPS URL"
(expect (git-identity-git-url-host "https://github.com/owner/repo")
:to-equal "github.com")
(expect (git-identity-git-url-host "https://github.com/owner/repo/")
:to-equal "github.com")
(expect (git-identity-git-url-host "https://github.com:22/owner/repo.git")
:to-equal "github.com")
(expect (git-identity-git-url-host "https://github.com:22/owner/repo.git/")
:to-equal "github.com")
(expect (git-identity-git-url-host "https://hg.sr.ht/~geyaeb/haskell-pdftotext")
:to-equal "hg.sr.ht"))
(it "matches URLs of git-remote-hg"
(expect (git-identity-git-url-host "hg::https://hg.sr.ht/~geyaeb/haskell-pdftotext")
:to-equal "hg.sr.ht"))
(it "matches an FTP URL"
(expect (git-identity-git-url-host "ftp://github.com/owner/repo.git")
:to-equal "github.com")
(expect (git-identity-git-url-host "ftps://github.com/owner/repo.git/")
:to-equal "github.com")
(expect (git-identity-git-url-host "ftp://github.com:22/owner/repo.git")
:to-equal "github.com")
(expect (git-identity-git-url-host "ftps://github.com:22/owner/repo.git/")
:to-equal "github.com"))
(it "matches an SCP-like syntax"
(expect (git-identity-git-url-host "[email protected]:owner/repo.git")
:to-equal "github.com")
(expect (git-identity-git-url-host "github.com:owner/repo.git")
:to-equal "github.com")
(expect (git-identity-git-url-host "[email protected]:1234123412341234.git")
:to-equal "gist.github.com")
(expect (git-identity-git-url-host "[email protected]:/owner/repo.git")
:to-equal "yyy.host.com")))
(describe "git-identity-git-url-directory"
(it "matches an SSH URL"
(expect (git-identity-git-url-directory "ssh://github.com/path/to/repo.git")
:to-equal "path/to")
(expect (git-identity-git-url-directory "ssh://github.com:22/path/to/repo.git/")
:to-equal "path/to")
(expect (git-identity-git-url-directory "ssh://[email protected]/path/to/repo.git/")
:to-equal "path/to")
(expect (git-identity-git-url-directory "ssh://[email protected]:22/path/to/repo.git/")
:to-equal "path/to"))
(it "matches an Git URL"
(expect (git-identity-git-url-directory "git://github.com/owner/repo.git")
:to-equal "owner")
(expect (git-identity-git-url-directory "git://github.com:22/owner/repo.git/")
:to-equal "owner"))
(it "matches an HTTPS URL"
(expect (git-identity-git-url-directory "https://github.com/owner/repo")
:to-equal "owner")
(expect (git-identity-git-url-directory "https://github.com/owner/repo/")
:to-equal "owner")
(expect (git-identity-git-url-directory "https://github.com:22/owner/repo.git")
:to-equal "owner")
(expect (git-identity-git-url-directory "https://github.com:22/owner/repo.git/")
:to-equal "owner")
(expect (git-identity-git-url-directory "https://hg.sr.ht/~geyaeb/haskell-pdftotext")
:to-equal "~geyaeb"))
(it "matches URLs of git-remote-hg"
(expect (git-identity-git-url-directory "hg::https://hg.sr.ht/~geyaeb/haskell-pdftotext")
:to-equal "~geyaeb"))
(it "matches an FTP URL"
(expect (git-identity-git-url-directory "ftp://github.com/owner/repo.git")
:to-equal "owner")
(expect (git-identity-git-url-directory "ftps://github.com/owner/repo.git/")
:to-equal "owner")
(expect (git-identity-git-url-directory "ftp://github.com:22/owner/repo.git")
:to-equal "owner")
(expect (git-identity-git-url-directory "ftps://github.com:22/owner/repo.git/")
:to-equal "owner"))
(it "matches an SCP-like syntax"
(expect (git-identity-git-url-directory "[email protected]:owner/repo.git")
:to-equal "owner")
(expect (git-identity-git-url-directory "github.com:owner/repo.git")
:to-equal "owner")
(expect (git-identity-git-url-directory "[email protected]:/owner/repo.git")
:to-equal "owner"))))
(describe "Detecting an identity"
(describe "git-identity-guess-identity"
(it "respect :domains"
(let ((git-identity-list git-identity-test-identity-list))
(expect (car (git-identity-guess-identity
:url "[email protected]:akirak/git-identity.el.git"
:directory nil
:verbose nil))
:to-equal "[email protected]")))
(it "respect :domains and :organizations"
(let ((git-identity-list git-identity-test-identity-list))
(expect (car (git-identity-guess-identity
:url "[email protected]:my-company-org/private-project.git"
:directory nil
:verbose nil))
:to-equal "[email protected]")))
(it "respect :domains and :exclude-organizations"
(let ((git-identity-list git-identity-test-identity-list))
(expect (git-identity-guess-identity
:url "[email protected]:my-another-private-org/xxx.git"
:directory nil
:verbose nil)
:to-be nil)))
(it "respect :dirs"
(let ((git-identity-list git-identity-test-identity-list))
(expect (car (git-identity-guess-identity
:url nil
:directory "~/work/mycompany.com/xxx/"
:verbose nil))
:to-equal "[email protected]"))))
(describe "git-identity-ancestor-directories-from-url"
(it "returns a list of directories"
(let ((git-identity-list git-identity-test-identity-list))
(expect (git-identity-ancestor-directories-from-url
"[email protected]:my-company-org/hello.git")
:to-equal '("~/work/mycompany.com/"))))))
(provide 'git-identity-test)