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
|
import { validateTag, validationMessages } from '~/lib/utils/ref_validator';
describe('~/lib/utils/ref_validator', () => {
describe('validateTag', () => {
describe.each([
['foo'],
['FOO'],
['foo/a.lockx'],
['foo.123'],
['foo/123'],
['foo/bar/123'],
['foo.bar.123'],
['foo-bar_baz'],
['head'],
['"foo"-'],
['foo@bar'],
['\ud83e\udd8a'],
['ünicöde'],
['\x80}'],
])('tag with the name "%s"', (tagName) => {
it('is valid', () => {
const result = validateTag(tagName);
expect(result.isValid).toBe(true);
expect(result.validationErrors).toEqual([]);
});
});
describe.each([
[' ', validationMessages.EmptyNameValidationMessage],
['refs/heads/tagName', validationMessages.DisallowedPrefixesValidationMessage],
['/foo', validationMessages.DisallowedPrefixesValidationMessage],
['-tagName', validationMessages.DisallowedPrefixesValidationMessage],
['HEAD', validationMessages.DisallowedNameValidationMessage],
['@', validationMessages.DisallowedNameValidationMessage],
['tag name with spaces', validationMessages.DisallowedSubstringsValidationMessage],
['tag\\name', validationMessages.DisallowedSubstringsValidationMessage],
['tag^name', validationMessages.DisallowedSubstringsValidationMessage],
['tag..name', validationMessages.DisallowedSubstringsValidationMessage],
['..', validationMessages.DisallowedSubstringsValidationMessage],
['tag?name', validationMessages.DisallowedSubstringsValidationMessage],
['tag*name', validationMessages.DisallowedSubstringsValidationMessage],
['tag[name', validationMessages.DisallowedSubstringsValidationMessage],
['tag@{name', validationMessages.DisallowedSubstringsValidationMessage],
['tag:name', validationMessages.DisallowedSubstringsValidationMessage],
['tag~name', validationMessages.DisallowedSubstringsValidationMessage],
['/', validationMessages.DisallowedSequenceEmptyValidationMessage],
['//', validationMessages.DisallowedSequenceEmptyValidationMessage],
['foo//123', validationMessages.DisallowedSequenceEmptyValidationMessage],
['.', validationMessages.DisallowedSequencePrefixesValidationMessage],
['/./', validationMessages.DisallowedSequencePrefixesValidationMessage],
['./.', validationMessages.DisallowedSequencePrefixesValidationMessage],
['.tagName', validationMessages.DisallowedSequencePrefixesValidationMessage],
['tag/.Name', validationMessages.DisallowedSequencePrefixesValidationMessage],
['foo/.123/bar', validationMessages.DisallowedSequencePrefixesValidationMessage],
['foo.', validationMessages.DisallowedSequencePostfixesValidationMessage],
['a.lock', validationMessages.DisallowedSequencePostfixesValidationMessage],
['foo/a.lock', validationMessages.DisallowedSequencePostfixesValidationMessage],
['foo/a.lock/b', validationMessages.DisallowedSequencePostfixesValidationMessage],
['foo.123.', validationMessages.DisallowedSequencePostfixesValidationMessage],
['foo/', validationMessages.DisallowedPostfixesValidationMessage],
['control-character\x7f', validationMessages.ControlCharactersValidationMessage],
['control-character\x15', validationMessages.ControlCharactersValidationMessage],
])('tag with name "%s"', (tagName, validationMessage) => {
it(`should be invalid with validation message "${validationMessage}"`, () => {
const result = validateTag(tagName);
expect(result.isValid).toBe(false);
expect(result.validationErrors).toContain(validationMessage);
});
});
});
});
|