Repository navigation
Expand file tree
/
Copy pathremote.test.js
More file actions
92 lines (81 loc) · 3.39 KB
/
Copy pathremote.test.js
File metadata and controls
92 lines (81 loc) · 3.39 KB
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
import Remote, {nullRemote} from '../../lib/models/remote';
describe('Remote', function() {
it('detects and extracts information from GitHub repository URLs', function() {
const urls = [
['git@github.com:atom/github.git', 'ssh'],
['git@github.com:/atom/github.git', 'ssh'],
['https://github.com/atom/github.git', 'https'],
['https://git:pass@github.com/atom/github.git', 'https'],
['ssh+https://github.com/atom/github.git', 'ssh+https'],
['git://github.com/atom/github', 'git'],
['ssh://git@github.com:atom/github.git', 'ssh'],
['ssh://git@github.com:/atom/github.git', 'ssh'],
];
for (const [url, proto] of urls) {
const remote = new Remote('origin', url);
assert.isTrue(remote.isPresent());
assert.strictEqual(remote.getName(), 'origin');
assert.strictEqual(remote.getNameOr('else'), 'origin');
assert.strictEqual(remote.getUrl(), url);
assert.isTrue(remote.isGithubRepo());
assert.strictEqual(remote.getDomain(), 'github.com');
assert.strictEqual(remote.getProtocol(), proto);
assert.strictEqual(remote.getOwner(), 'atom');
assert.strictEqual(remote.getRepo(), 'github');
assert.strictEqual(remote.getSlug(), 'atom/github');
}
});
it('detects non-GitHub remotes', function() {
const urls = [
'git@gitlab.com:atom/github.git',
'atom/github',
];
for (const url of urls) {
const remote = new Remote('origin', url);
assert.isTrue(remote.isPresent());
assert.strictEqual(remote.getName(), 'origin');
assert.strictEqual(remote.getNameOr('else'), 'origin');
assert.strictEqual(remote.getUrl(), url);
assert.isFalse(remote.isGithubRepo());
assert.isNull(remote.getDomain());
assert.isNull(remote.getOwner());
assert.isNull(remote.getRepo());
assert.isNull(remote.getSlug());
}
});
it('may be created without a URL', function() {
const remote = new Remote('origin');
assert.isTrue(remote.isPresent());
assert.strictEqual(remote.getName(), 'origin');
assert.strictEqual(remote.getNameOr('else'), 'origin');
assert.isUndefined(remote.getUrl());
assert.isFalse(remote.isGithubRepo());
assert.isNull(remote.getDomain());
assert.isNull(remote.getOwner());
assert.isNull(remote.getRepo());
assert.isNull(remote.getSlug());
});
it('has a corresponding null object', function() {
assert.isFalse(nullRemote.isPresent());
assert.strictEqual(nullRemote.getName(), '');
assert.strictEqual(nullRemote.getUrl(), '');
assert.isFalse(nullRemote.isGithubRepo());
assert.isNull(nullRemote.getDomain());
assert.isNull(nullRemote.getProtocol());
assert.isNull(nullRemote.getOwner());
assert.isNull(nullRemote.getRepo());
assert.isNull(nullRemote.getSlug());
assert.strictEqual(nullRemote.getNameOr('else'), 'else');
assert.isNull(nullRemote.getEndpoint());
});
describe('getEndpoint', function() {
it('accesses an Endpoint for the corresponding GitHub host', function() {
const remote = new Remote('origin', 'git@github.com:atom/github.git');
assert.strictEqual(remote.getEndpoint().getGraphQLRoot(), 'https://api.github.com/graphql');
});
it('returns null for non-GitHub URLs', function() {
const elsewhere = new Remote('mirror', 'https://me@bitbucket.org/team/repo.git');
assert.isNull(elsewhere.getEndpoint());
});
});
});