/
modules.spec.ts
64 lines (55 loc) · 2.3 KB
/
modules.spec.ts
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
import { getName } from '../../../test/util';
import { gitTagsRefMatchRegex, githubRefMatchRegex } from './modules';
describe(getName(__filename), () => {
describe('githubRefMatchRegex', () => {
it('should split project and tag from source', () => {
const { project, tag } = githubRefMatchRegex.exec(
'github.com/hashicorp/example?ref=v1.0.0'
).groups;
expect(project).toBe('hashicorp/example');
expect(tag).toBe('v1.0.0');
});
it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => {
const { project } = githubRefMatchRegex.exec(
'github.com/hashicorp/example.repo-123?ref=v1.0.0'
).groups;
expect(project).toBe('hashicorp/example.repo-123');
});
});
describe('gitTagsRefMatchRegex', () => {
it('should split project and tag from source', () => {
const http = gitTagsRefMatchRegex.exec(
'http://github.com/hashicorp/example?ref=v1.0.0'
).groups;
const https = gitTagsRefMatchRegex.exec(
'https://github.com/hashicorp/example?ref=v1.0.0'
).groups;
const ssh = gitTagsRefMatchRegex.exec(
'ssh://github.com/hashicorp/example?ref=v1.0.0'
).groups;
expect(http.project).toBe('hashicorp/example');
expect(http.tag).toBe('v1.0.0');
expect(https.project).toBe('hashicorp/example');
expect(https.tag).toBe('v1.0.0');
expect(ssh.project).toBe('hashicorp/example');
expect(ssh.tag).toBe('v1.0.0');
});
it('should parse alpha-numeric characters as well as dots, underscores, and dashes in repo names', () => {
const http = gitTagsRefMatchRegex.exec(
'http://github.com/hashicorp/example.repo-123?ref=v1.0.0'
).groups;
const https = gitTagsRefMatchRegex.exec(
'https://github.com/hashicorp/example.repo-123?ref=v1.0.0'
).groups;
const ssh = gitTagsRefMatchRegex.exec(
'ssh://github.com/hashicorp/example.repo-123?ref=v1.0.0'
).groups;
expect(http.project).toBe('hashicorp/example.repo-123');
expect(http.tag).toBe('v1.0.0');
expect(https.project).toBe('hashicorp/example.repo-123');
expect(https.tag).toBe('v1.0.0');
expect(ssh.project).toBe('hashicorp/example.repo-123');
expect(ssh.tag).toBe('v1.0.0');
});
});
});