Skip to content

Commit a03d51e

Browse files
author
Michael Perrotte
committedSep 28, 2019
test: added refactered tests for bitbucket
1 parent 0aea712 commit a03d51e

File tree

3 files changed

+382
-50
lines changed

3 files changed

+382
-50
lines changed
 

‎test/bitbucket-https-with-embedded-auth.js

-27
This file was deleted.

‎test/bitbucket.js

+283-23
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,292 @@
22
var HostedGit = require('../index')
33
var test = require('tap').test
44

5-
test('fromUrl(bitbucket url)', function (t) {
6-
function verify (host, label, branch) {
5+
var showLabel = function (label, fn) { return label + ' -> ' + fn }
6+
7+
var testFixtures = function (t, params, fixtures) {
8+
for (var i = 0; i < fixtures.length; ++i) {
9+
var fixture = fixtures[i]
10+
11+
var host = fixture.host(params)
712
var hostinfo = HostedGit.fromUrl(host)
8-
var hash = branch ? '#' + branch : ''
9-
t.ok(hostinfo, label)
10-
if (!hostinfo) return
11-
t.is(hostinfo.https(), 'git+https://bitbucket.org/111/222.git' + hash, label + ' -> https')
12-
t.is(hostinfo.browse(), 'https://bitbucket.org/111/222' + (branch ? '/src/' + branch : ''), label + ' -> browse')
13-
t.is(hostinfo.browse(''), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/', label + ' -> browse(path)')
14-
t.is(hostinfo.browse('C'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C', label + ' -> browse(path)')
15-
t.is(hostinfo.browse('C/D'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C/D', label + ' -> browse(path)')
16-
t.is(hostinfo.browse('C', 'A'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C#a', label + ' -> browse(path, fragment)')
17-
t.is(hostinfo.browse('C/D', 'A'), 'https://bitbucket.org/111/222/src/' + (branch || 'master') + '/C/D#a', label + ' -> browse(path, fragment)')
18-
t.is(hostinfo.docs(), 'https://bitbucket.org/111/222' + (branch ? '/src/' + branch : '') + '#readme', label + ' -> docs')
19-
t.is(hostinfo.ssh(), 'git@bitbucket.org:111/222.git' + hash, label + ' -> ssh')
20-
t.is(hostinfo.sshurl(), 'git+ssh://git@bitbucket.org/111/222.git' + hash, label + ' -> sshurl')
21-
t.is(hostinfo.shortcut(), 'bitbucket:111/222' + hash, label + ' -> shortcut')
22-
t.is(hostinfo.file(''), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/', label + ' -> file')
23-
t.is(hostinfo.file('C'), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/C', label + ' -> file')
24-
t.is(hostinfo.file('C/D'), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/C/D', label + ' -> file')
25-
t.is(hostinfo.tarball(), 'https://bitbucket.org/111/222/get/' + (branch || 'master') + '.tar.gz', label + ' -> tarball')
26-
t.is(hostinfo.tarball({ noCommittish: true }), 'https://bitbucket.org/111/222/get/' + (branch || 'master') + '.tar.gz', label + ' -> tarball')
13+
14+
// INFO: fromUrl should return `undefined` from fixture input
15+
if (fixture.isUndefined) {
16+
t.test('input results in undefined', function (tt) {
17+
tt.is(hostinfo, undefined)
18+
tt.end()
19+
})
20+
break
21+
}
22+
23+
t.test('hostinfo.https', function (tt) {
24+
var expected = function (url, hasBranch) {
25+
return (hasBranch)
26+
? url + '#' + params.branch
27+
: url
28+
}
29+
tt.is(
30+
hostinfo.https(),
31+
expected('git+https://bitbucket.org/some-owner/some-repo.git', fixture.hasBranch, fixture.hasGroup),
32+
showLabel(fixture.label, 'https')
33+
)
34+
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
35+
tt.is(
36+
hostinfo.https({ noCommittish: true }),
37+
'git+https://bitbucket.org/some-owner/some-repo.git',
38+
showLabel(fixture.label, 'https({ noCommittish: true })')
39+
)
40+
tt.is(
41+
hostinfo.https({ noGitPlus: true }),
42+
expected('https://bitbucket.org/some-owner/some-repo.git', fixture.hasBranch),
43+
showLabel(fixture.label, 'https({ noGitPlus: true })')
44+
)
45+
tt.end()
46+
})
47+
t.test('hostinfo.browse', function (tt) {
48+
var expected = function (url, hasBranch) {
49+
if (hasBranch) {
50+
if (url.indexOf('master') === -1) {
51+
return url + '/src/' + params.branch
52+
} else {
53+
return url.replace(/master/gi, params.branch)
54+
}
55+
}
56+
return url
57+
}
58+
tt.is(
59+
hostinfo.browse(),
60+
expected('https://bitbucket.org/some-owner/some-repo', fixture.hasBranch),
61+
showLabel(fixture.label, 'browse')
62+
)
63+
tt.is(
64+
hostinfo.browse(''),
65+
expected('https://bitbucket.org/some-owner/some-repo/src/master/', fixture.hasBranch),
66+
showLabel(fixture.label, "browse('')")
67+
)
68+
tt.is(
69+
hostinfo.browse('C'),
70+
expected('https://bitbucket.org/some-owner/some-repo/src/master/C', fixture.hasBranch),
71+
showLabel(fixture.label, "browse('C')")
72+
)
73+
tt.is(
74+
hostinfo.browse('C/D'),
75+
expected('https://bitbucket.org/some-owner/some-repo/src/master/C/D', fixture.hasBranch),
76+
showLabel(fixture.label, "browse('C/D')")
77+
)
78+
tt.is(
79+
hostinfo.browse('C', 'A'),
80+
expected('https://bitbucket.org/some-owner/some-repo/src/master/C#a', fixture.hasBranch),
81+
showLabel(fixture.label, "browse('C', 'A')")
82+
)
83+
tt.is(
84+
hostinfo.browse('C/D', 'A'),
85+
expected('https://bitbucket.org/some-owner/some-repo/src/master/C/D#a', fixture.hasBranch),
86+
showLabel(fixture.label, "browse('C/D', 'A')")
87+
)
88+
tt.end()
89+
})
90+
t.test('hostinfo.docs', function (tt) {
91+
var expected = function (url, hasBranch) {
92+
if (hasBranch) {
93+
var splitUrl = url.split('#')
94+
return splitUrl[0] + '/src/' + params.branch + '#' + splitUrl[1]
95+
}
96+
return url
97+
}
98+
tt.is(
99+
hostinfo.docs(),
100+
expected('https://bitbucket.org/some-owner/some-repo#readme', fixture.hasBranch),
101+
showLabel(fixture.label, 'docs')
102+
)
103+
tt.is(
104+
hostinfo.docs({ noCommittish: true }),
105+
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
106+
'https://bitbucket.org/some-owner/some-repo#readme',
107+
showLabel(fixture.label, 'docs({ noCommittish: true })')
108+
)
109+
tt.is(
110+
hostinfo.docs({ noGitPlus: true }),
111+
expected('https://bitbucket.org/some-owner/some-repo#readme', fixture.hasBranch),
112+
showLabel(fixture.label, 'docs({ noGitPlus: true })')
113+
)
114+
tt.end()
115+
})
116+
t.test('hostinfo.ssh', function (tt) {
117+
var expected = function (url, hasBranch) {
118+
return (hasBranch)
119+
? url + '#' + params.branch
120+
: url
121+
}
122+
tt.is(
123+
hostinfo.ssh(),
124+
expected('git@bitbucket.org:some-owner/some-repo.git', fixture.hasBranch),
125+
showLabel(fixture.label, 'ssh')
126+
)
127+
tt.is(
128+
hostinfo.ssh({ noCommittish: true }),
129+
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
130+
'git@bitbucket.org:some-owner/some-repo.git',
131+
showLabel(fixture.label, 'ssh({ noCommittish: true })')
132+
)
133+
tt.is(
134+
hostinfo.ssh({ noGitPlus: true }),
135+
expected('git@bitbucket.org:some-owner/some-repo.git', fixture.hasBranch),
136+
showLabel(fixture.label, 'ssh({ noGitPlus: true })')
137+
)
138+
tt.end()
139+
})
140+
t.test('hostinfo.sshurl', function (tt) {
141+
var expected = function (url, hasBranch) {
142+
return (hasBranch)
143+
? url + '#' + params.branch
144+
: url
145+
}
146+
tt.is(
147+
hostinfo.sshurl(),
148+
expected('git+ssh://git@bitbucket.org/some-owner/some-repo.git', fixture.hasBranch),
149+
showLabel(fixture.label, 'sshurl')
150+
)
151+
tt.is(
152+
hostinfo.sshurl({ noCommittish: true }),
153+
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
154+
'git+ssh://git@bitbucket.org/some-owner/some-repo.git',
155+
showLabel(fixture.label, 'sshurl({ noCommittish: true })')
156+
)
157+
tt.is(
158+
hostinfo.sshurl({ noGitPlus: true }),
159+
expected('ssh://git@bitbucket.org/some-owner/some-repo.git', fixture.hasBranch),
160+
showLabel(fixture.label, 'sshurl({ noGitPlus: true })')
161+
)
162+
tt.end()
163+
})
164+
t.test('hostinfo.shortcut', function (tt) {
165+
var expected = function (url, hasBranch) {
166+
return (hasBranch)
167+
? url + '#' + params.branch
168+
: url
169+
}
170+
tt.is(
171+
hostinfo.shortcut(),
172+
expected('bitbucket:some-owner/some-repo', fixture.hasBranch),
173+
showLabel(fixture.label, 'shortcut')
174+
)
175+
tt.is(
176+
hostinfo.shortcut({ noCommittish: true }),
177+
// INFO: not using `expected` because with `{noCommittish: true}` the output is always the same
178+
'bitbucket:some-owner/some-repo',
179+
showLabel(fixture.label, 'shortcut({ noCommittish: true })')
180+
)
181+
tt.is(
182+
hostinfo.shortcut({ noGitPlus: true }),
183+
expected('bitbucket:some-owner/some-repo', fixture.hasBranch),
184+
showLabel(fixture.label, 'shortcut({ noGitPlus: true })')
185+
)
186+
tt.end()
187+
})
188+
t.test('hostinfo.file', function (tt) {
189+
var expected = function (url, hasBranch) {
190+
return (hasBranch)
191+
? url.replace(/master/gi, params.branch)
192+
: url
193+
}
194+
tt.is(
195+
hostinfo.file(),
196+
expected('https://bitbucket.org/some-owner/some-repo/raw/master/', fixture.hasBranch),
197+
showLabel(fixture.label, 'file')
198+
)
199+
tt.is(
200+
hostinfo.file('C'),
201+
expected('https://bitbucket.org/some-owner/some-repo/raw/master/C', fixture.hasBranch),
202+
showLabel(fixture.label, "file('C')")
203+
)
204+
tt.is(
205+
hostinfo.file('C/D'),
206+
expected('https://bitbucket.org/some-owner/some-repo/raw/master/C/D', fixture.hasBranch),
207+
showLabel(fixture.label, "file('C/D')")
208+
)
209+
tt.end()
210+
})
211+
t.test('hostinfo.tarball', function (tt) {
212+
var expected = function (url, hasBranch) {
213+
return (hasBranch)
214+
? url.replace(/master/gi, params.branch)
215+
: url
216+
}
217+
tt.is(
218+
hostinfo.tarball(),
219+
expected('https://bitbucket.org/some-owner/some-repo/get/master.tar.gz', fixture.hasBranch),
220+
showLabel(fixture.label, 'tarball')
221+
)
222+
tt.is(
223+
hostinfo.tarball({ noCommittish: true }),
224+
expected('https://bitbucket.org/some-owner/some-repo/get/master.tar.gz', fixture.hasBranch),
225+
showLabel(fixture.label, 'tarball({ noCommittish: true })')
226+
)
227+
tt.is(
228+
hostinfo.tarball({ noGitPlus: true }),
229+
expected('https://bitbucket.org/some-owner/some-repo/get/master.tar.gz', fixture.hasBranch),
230+
showLabel(fixture.label, 'tarball({ noGitPlus: true })')
231+
)
232+
tt.end()
233+
})
27234
}
235+
}
236+
237+
test('fromUrl(bitbucket url)', function (t) {
238+
var fixtures = require('./fixtures/bitbucket')
239+
// var gitlabFixtures = require('./fixtures/bitbucket')
240+
// var collectedFixtures = [].concat(fixtures, gitlabFixtures)
241+
242+
t.test('domain: bitbucket.org', function (tt) {
243+
var params = {
244+
domain: 'bitbucket.org',
245+
shortname: 'bitbucket',
246+
label: 'bitbucket',
247+
owner: 'some-owner',
248+
project: 'some-repo',
249+
branch: 'feature-branch'
250+
}
251+
testFixtures(tt, params, fixtures)
252+
tt.end()
253+
})
254+
255+
t.test('domain: www.bitbucket.org', function (tt) {
256+
var params = {
257+
domain: 'www.bitbucket.org',
258+
shortname: 'bitbucket',
259+
label: 'bitbucket',
260+
owner: 'some-owner',
261+
project: 'some-repo',
262+
branch: 'feature-branch'
263+
}
264+
testFixtures(tt, params, fixtures)
265+
tt.end()
266+
})
28267

29-
require('./lib/standard-tests')(verify, 'bitbucket.org', 'bitbucket')
30-
require('./lib/standard-tests')(verify, 'www.bitbucket.org', 'bitbucket')
268+
t.test('Bitbucket HTTPS URLs with embedded auth', function (tt) {
269+
tt.is(
270+
HostedGit.fromUrl('https://user:pass@bitbucket.org/user/repo.git').toString(),
271+
'git+https://user:pass@bitbucket.org/user/repo.git',
272+
'credentials were included in URL'
273+
)
274+
tt.is(
275+
HostedGit.fromUrl('https://user:pass@bitbucket.org/user/repo').toString(),
276+
'git+https://user:pass@bitbucket.org/user/repo.git',
277+
'credentials were included in URL'
278+
)
279+
tt.is(
280+
HostedGit.fromUrl('git+https://user:pass@bitbucket.org/user/repo.git').toString(),
281+
'git+https://user:pass@bitbucket.org/user/repo.git',
282+
'credentials were included in URL'
283+
)
284+
tt.is(
285+
HostedGit.fromUrl('git+https://user:pass@bitbucket.org/user/repo').toString(),
286+
'git+https://user:pass@bitbucket.org/user/repo.git',
287+
'credentials were included in URL'
288+
)
289+
tt.end()
290+
})
31291

32292
t.end()
33293
})

‎test/fixtures/bitbucket.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
'use strcit'
2+
3+
module.exports = [
4+
{
5+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project },
6+
label: 'https'
7+
},
8+
{
9+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' },
10+
label: 'https.git'
11+
},
12+
{
13+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch },
14+
label: 'https#branch',
15+
hasBranch: true
16+
},
17+
{
18+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch },
19+
label: 'https.git#branch',
20+
hasBranch: true
21+
},
22+
{
23+
host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '/-/' + 'archive' + '/3.3.2' + '/ws-3.3.2.tar.gz' },
24+
label: 'https.tar',
25+
isUndefined: true
26+
},
27+
{
28+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project },
29+
label: 'git+https'
30+
},
31+
{
32+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git' },
33+
label: 'git+https.git'
34+
},
35+
{
36+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch },
37+
label: 'git+https#branch',
38+
hasBranch: true
39+
},
40+
{
41+
host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch },
42+
label: 'git+https.git#branch',
43+
hasBranch: true
44+
},
45+
{
46+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project },
47+
label: 'ssh'
48+
},
49+
{
50+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git' },
51+
label: 'ssh.git'
52+
},
53+
{
54+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '#' + p.branch },
55+
label: 'ssh#branch',
56+
hasBranch: true
57+
},
58+
{
59+
host: function (p) { return 'git@' + p.domain + ':' + p.owner + '/' + p.project + '.git#' + p.branch },
60+
label: 'ssh.git#branch',
61+
hasBranch: true
62+
},
63+
{
64+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project },
65+
label: 'ssh-url'
66+
},
67+
{
68+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git' },
69+
label: 'ssh-url.git'
70+
},
71+
{
72+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '#' + p.branch },
73+
label: 'ssh-url#branch',
74+
hasBranch: true
75+
},
76+
{
77+
host: function (p) { return 'git+ssh://git@' + p.domain + '/' + p.owner + '/' + p.project + '.git#' + p.branch },
78+
label: 'ssh-url.git#branch',
79+
hasBranch: true
80+
},
81+
{
82+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project },
83+
label: 'shortcut'
84+
},
85+
{
86+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git' },
87+
label: 'shortcut.git'
88+
},
89+
{
90+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '#' + p.branch },
91+
label: 'shortcut#branch',
92+
hasBranch: true
93+
},
94+
{
95+
host: function (p) { return p.shortname + ':' + p.owner + '/' + p.project + '.git#' + p.branch },
96+
label: 'shortcut.git#branch',
97+
hasBranch: true
98+
}
99+
]

0 commit comments

Comments
 (0)
Please sign in to comment.