27c2d9e1ee1875426de691d63ad74a669e00c456
[WebKit.git] / Websites / perf.webkit.org / unit-tests / commit-set-tests.js
1 "use strict";
2
3 const assert = require('assert');
4 require('../tools/js/v3-models.js');
5 const MockModels = require('./resources/mock-v3-models.js').MockModels;
6
7 function createPatch()
8 {
9     return new UploadedFile(453, {'createdAt': new Date('2017-05-01T19:16:53Z'), 'filename': 'patch.dat', 'extension': '.dat', 'author': 'some user',
10         size: 534637, sha256: '169463c8125e07c577110fe144ecd63942eb9472d438fc0014f474245e5df8a1'});
11 }
12
13 function createRoot()
14 {
15     return new UploadedFile(456, {'createdAt': new Date('2017-05-01T21:03:27Z'), 'filename': 'root.dat', 'extension': '.dat', 'author': 'some user',
16         size: 16452234, sha256: '03eed7a8494ab8794c44b7d4308e55448fc56f4d6c175809ba968f78f656d58d'});
17 }
18
19 function customCommitSetWithoutOwnedCommit()
20 {
21     const customCommitSet = new CustomCommitSet;
22     customCommitSet.setRevisionForRepository(MockModels.osx, '10.11.4 15E65');
23     customCommitSet.setRevisionForRepository(MockModels.webkit, '200805');
24     return customCommitSet;
25 }
26
27 function customCommitSetWithOwnedCommit()
28 {
29     const customCommitSet = new CustomCommitSet;
30     customCommitSet.setRevisionForRepository(MockModels.osx, '10.11.4 15E65');
31     customCommitSet.setRevisionForRepository(MockModels.ownerRepository, 'OwnerRepository-r0');
32     customCommitSet.setRevisionForRepository(MockModels.ownedRepository, 'OwnedRepository-r0', null, 'OwnerRepository-r0');
33     return customCommitSet;
34 }
35
36 function customCommitSetWithPatch()
37 {
38     const customCommitSet = new CustomCommitSet;
39     const patch = createPatch();
40     customCommitSet.setRevisionForRepository(MockModels.osx, '10.11.4 15E65');
41     customCommitSet.setRevisionForRepository(MockModels.webkit, '200805', patch);
42     return customCommitSet;
43 }
44
45 function customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository()
46 {
47     const customCommitSet = new CustomCommitSet;
48     customCommitSet.setRevisionForRepository(MockModels.osx, '10.11.4 15E65');
49     customCommitSet.setRevisionForRepository(MockModels.webkit, '200805');
50     customCommitSet.setRevisionForRepository(MockModels.ownedWebkit, 'owned-200805', null, '10.11.4 15E65');
51     return customCommitSet;
52 }
53
54 describe('CustomCommitSet', () => {
55     MockModels.inject();
56
57     describe('Test custom commit set without owned commit', () => {
58         it('should have right revision for a given repository', () => {
59             const commitSet = customCommitSetWithoutOwnedCommit();
60             assert.equal(commitSet.revisionForRepository(MockModels.osx), '10.11.4 15E65');
61             assert.equal(commitSet.revisionForRepository(MockModels.webkit), '200805');
62         });
63
64         it('should have no patch for any repository', () => {
65             const commitSet = customCommitSetWithoutOwnedCommit();
66             assert.equal(commitSet.patchForRepository(MockModels.osx), null);
67             assert.equal(commitSet.patchForRepository(MockModels.webkit), null);
68         });
69
70         it('should have no owner revision for a given repository', () => {
71             const commitSet = customCommitSetWithoutOwnedCommit();
72             assert.equal(commitSet.ownerRevisionForRepository(MockModels.osx), null);
73             assert.equal(commitSet.ownerRevisionForRepository(MockModels.webkit), null);
74         });
75
76         it('should return all repositories in it', () => {
77             const commitSet = customCommitSetWithoutOwnedCommit();
78             assert.deepEqual(commitSet.repositories(), [MockModels.osx, MockModels.webkit]);
79         });
80     });
81
82     describe('Test custom commit set with owned commit', () => {
83         it('should have right revision for a given repository', () => {
84             const commitSet = customCommitSetWithOwnedCommit();
85             assert.equal(commitSet.revisionForRepository(MockModels.osx), '10.11.4 15E65');
86             assert.equal(commitSet.revisionForRepository(MockModels.ownerRepository), 'OwnerRepository-r0');
87             assert.equal(commitSet.revisionForRepository(MockModels.ownedRepository), 'OwnedRepository-r0');
88         });
89
90         it('should have no patch for any repository', () => {
91             const commitSet = customCommitSetWithOwnedCommit();
92             assert.equal(commitSet.patchForRepository(MockModels.osx), null);
93             assert.equal(commitSet.patchForRepository(MockModels.ownerRepository), null);
94             assert.equal(commitSet.patchForRepository(MockModels.ownedRepository), null);
95         });
96
97         it('should have right owner revision for an owned repository', () => {
98             const commitSet = customCommitSetWithOwnedCommit();
99             assert.equal(commitSet.ownerRevisionForRepository(MockModels.osx), null);
100             assert.equal(commitSet.ownerRevisionForRepository(MockModels.ownerRepository), null);
101             assert.equal(commitSet.ownerRevisionForRepository(MockModels.ownedRepository), 'OwnerRepository-r0');
102         });
103
104         it('should return all repositories in it', () => {
105             const commitSet = customCommitSetWithOwnedCommit();
106             assert.deepEqual(commitSet.repositories(), [MockModels.osx, MockModels.ownerRepository, MockModels.ownedRepository]);
107         });
108     });
109
110     describe('Test custom commit set with patch', () => {
111         it('should have right revision for a given repository', () => {
112             const commitSet = customCommitSetWithPatch();
113             assert.equal(commitSet.revisionForRepository(MockModels.osx), '10.11.4 15E65');
114             assert.equal(commitSet.revisionForRepository(MockModels.webkit), '200805');
115         });
116
117         it('should have a patch for a repository with patch specified', () => {
118             const commitSet = customCommitSetWithPatch();
119             assert.equal(commitSet.patchForRepository(MockModels.osx), null);
120             assert.deepEqual(commitSet.patchForRepository(MockModels.webkit), createPatch());
121         });
122
123         it('should have no owner revision for a given repository', () => {
124             const commitSet = customCommitSetWithPatch();
125             assert.equal(commitSet.ownerRevisionForRepository(MockModels.osx), null);
126             assert.equal(commitSet.ownerRevisionForRepository(MockModels.webkit), null);
127         });
128
129         it('should return all repositories in it', () => {
130             const commitSet = customCommitSetWithPatch();
131             assert.deepEqual(commitSet.repositories(), [MockModels.osx, MockModels.webkit]);
132         });
133     });
134
135     describe('Test custom commit set with owned repository has same name as non-owned repository',  () => {
136         it('should have right revision for a given repository', () => {
137             const commitSet = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
138             assert.equal(commitSet.revisionForRepository(MockModels.osx), '10.11.4 15E65');
139             assert.equal(commitSet.revisionForRepository(MockModels.webkit), '200805');
140             assert.equal(commitSet.revisionForRepository(MockModels.ownedWebkit), 'owned-200805');
141         });
142
143         it('should have no patch for any repository', () => {
144             const commitSet = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
145             assert.equal(commitSet.patchForRepository(MockModels.osx), null);
146             assert.equal(commitSet.patchForRepository(MockModels.webkit), null);
147             assert.equal(commitSet.patchForRepository(MockModels.ownedWebkit), null);
148         });
149
150         it('should have right owner revision for an owned repository', () => {
151             const commitSet = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
152             assert.equal(commitSet.ownerRevisionForRepository(MockModels.osx), null);
153             assert.equal(commitSet.ownerRevisionForRepository(MockModels.webkit), null);
154             assert.equal(commitSet.ownerRevisionForRepository(MockModels.ownedWebkit), '10.11.4 15E65');
155         });
156
157         it('should return all repositories in it', () => {
158             const commitSet = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
159             assert.deepEqual(commitSet.repositories(), [MockModels.osx, MockModels.webkit, MockModels.ownedWebkit]);
160         });
161     });
162
163     describe('Test custom commit set equality function', () => {
164         it('should be equal to same custom commit set', () => {
165             assert.deepEqual(customCommitSetWithoutOwnedCommit(), customCommitSetWithoutOwnedCommit());
166             assert.deepEqual(customCommitSetWithOwnedCommit(), customCommitSetWithOwnedCommit());
167             assert.deepEqual(customCommitSetWithPatch(), customCommitSetWithPatch());
168             assert.deepEqual(customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository(),
169                 customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository());
170         });
171
172         it('should not be equal even if non-owned revisions are the same', () => {
173             const commitSet0 = customCommitSetWithoutOwnedCommit();
174             const commitSet1 = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
175             assert.equal(commitSet0.equals(commitSet1), false);
176         });
177     });
178
179     describe('Test custom commit set custom root operations', () => {
180         it('should return empty custom roots if no custom root specified', () => {
181             assert.deepEqual(customCommitSetWithoutOwnedCommit().customRoots(), []);
182         });
183
184         it('should return root if root is added into commit set', () => {
185             const commitSet = customCommitSetWithoutOwnedCommit();
186             commitSet.addCustomRoot(createRoot());
187             assert.deepEqual(commitSet.customRoots(), [createRoot()]);
188         });
189     });
190 });