ab76d589cebd20057b3a79c688a56a3586f008f7
[WebKit-https.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         it('should return only top level repositories', () => {
82             const commitSet = customCommitSetWithoutOwnedCommit();
83             assert.deepEqual(commitSet.topLevelRepositories(), [MockModels.osx, MockModels.webkit]);
84         });
85     });
86
87     describe('Test custom commit set with owned commit', () => {
88         it('should have right revision for a given repository', () => {
89             const commitSet = customCommitSetWithOwnedCommit();
90             assert.equal(commitSet.revisionForRepository(MockModels.osx), '10.11.4 15E65');
91             assert.equal(commitSet.revisionForRepository(MockModels.ownerRepository), 'OwnerRepository-r0');
92             assert.equal(commitSet.revisionForRepository(MockModels.ownedRepository), 'OwnedRepository-r0');
93         });
94
95         it('should have no patch for any repository', () => {
96             const commitSet = customCommitSetWithOwnedCommit();
97             assert.equal(commitSet.patchForRepository(MockModels.osx), null);
98             assert.equal(commitSet.patchForRepository(MockModels.ownerRepository), null);
99             assert.equal(commitSet.patchForRepository(MockModels.ownedRepository), null);
100         });
101
102         it('should have right owner revision for an owned repository', () => {
103             const commitSet = customCommitSetWithOwnedCommit();
104             assert.equal(commitSet.ownerRevisionForRepository(MockModels.osx), null);
105             assert.equal(commitSet.ownerRevisionForRepository(MockModels.ownerRepository), null);
106             assert.equal(commitSet.ownerRevisionForRepository(MockModels.ownedRepository), 'OwnerRepository-r0');
107         });
108
109         it('should return all repositories in it', () => {
110             const commitSet = customCommitSetWithOwnedCommit();
111             assert.deepEqual(commitSet.repositories(), [MockModels.osx, MockModels.ownerRepository, MockModels.ownedRepository]);
112         });
113
114         it('should return only top level repositories', () => {
115             const commitSet = customCommitSetWithOwnedCommit();
116             assert.deepEqual(commitSet.topLevelRepositories(), [MockModels.osx, MockModels.ownerRepository]);
117         });
118     });
119
120     describe('Test custom commit set with patch', () => {
121         it('should have right revision for a given repository', () => {
122             const commitSet = customCommitSetWithPatch();
123             assert.equal(commitSet.revisionForRepository(MockModels.osx), '10.11.4 15E65');
124             assert.equal(commitSet.revisionForRepository(MockModels.webkit), '200805');
125         });
126
127         it('should have a patch for a repository with patch specified', () => {
128             const commitSet = customCommitSetWithPatch();
129             assert.equal(commitSet.patchForRepository(MockModels.osx), null);
130             assert.deepEqual(commitSet.patchForRepository(MockModels.webkit), createPatch());
131         });
132
133         it('should have no owner revision for a given repository', () => {
134             const commitSet = customCommitSetWithPatch();
135             assert.equal(commitSet.ownerRevisionForRepository(MockModels.osx), null);
136             assert.equal(commitSet.ownerRevisionForRepository(MockModels.webkit), null);
137         });
138
139         it('should return all repositories in it', () => {
140             const commitSet = customCommitSetWithPatch();
141             assert.deepEqual(commitSet.repositories(), [MockModels.osx, MockModels.webkit]);
142         });
143
144         it('should return only top level repositories', () => {
145             const commitSet = customCommitSetWithPatch();
146             assert.deepEqual(commitSet.topLevelRepositories(), [MockModels.osx, MockModels.webkit]);
147         });
148     });
149
150     describe('Test custom commit set with owned repository has same name as non-owned repository',  () => {
151         it('should have right revision for a given repository', () => {
152             const commitSet = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
153             assert.equal(commitSet.revisionForRepository(MockModels.osx), '10.11.4 15E65');
154             assert.equal(commitSet.revisionForRepository(MockModels.webkit), '200805');
155             assert.equal(commitSet.revisionForRepository(MockModels.ownedWebkit), 'owned-200805');
156         });
157
158         it('should have no patch for any repository', () => {
159             const commitSet = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
160             assert.equal(commitSet.patchForRepository(MockModels.osx), null);
161             assert.equal(commitSet.patchForRepository(MockModels.webkit), null);
162             assert.equal(commitSet.patchForRepository(MockModels.ownedWebkit), null);
163         });
164
165         it('should have right owner revision for an owned repository', () => {
166             const commitSet = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
167             assert.equal(commitSet.ownerRevisionForRepository(MockModels.osx), null);
168             assert.equal(commitSet.ownerRevisionForRepository(MockModels.webkit), null);
169             assert.equal(commitSet.ownerRevisionForRepository(MockModels.ownedWebkit), '10.11.4 15E65');
170         });
171
172         it('should return all repositories in it', () => {
173             const commitSet = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
174             assert.deepEqual(commitSet.repositories(), [MockModels.osx, MockModels.webkit, MockModels.ownedWebkit]);
175         });
176
177         it('should return only top level repositories', () => {
178             const commitSet = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
179             assert.deepEqual(commitSet.topLevelRepositories(), [MockModels.osx, MockModels.webkit]);
180         });
181     });
182
183     describe('Test custom commit set equality function', () => {
184         it('should be equal to same custom commit set', () => {
185             assert.deepEqual(customCommitSetWithoutOwnedCommit(), customCommitSetWithoutOwnedCommit());
186             assert.deepEqual(customCommitSetWithOwnedCommit(), customCommitSetWithOwnedCommit());
187             assert.deepEqual(customCommitSetWithPatch(), customCommitSetWithPatch());
188             assert.deepEqual(customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository(),
189                 customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository());
190         });
191
192         it('should not be equal even if non-owned revisions are the same', () => {
193             const commitSet0 = customCommitSetWithoutOwnedCommit();
194             const commitSet1 = customCommitSetWithOwnedRepositoryHasSameNameAsNotOwnedRepository();
195             assert.equal(commitSet0.equals(commitSet1), false);
196         });
197     });
198
199     describe('Test custom commit set custom root operations', () => {
200         it('should return empty custom roots if no custom root specified', () => {
201             assert.deepEqual(customCommitSetWithoutOwnedCommit().customRoots(), []);
202         });
203
204         it('should return root if root is added into commit set', () => {
205             const commitSet = customCommitSetWithoutOwnedCommit();
206             commitSet.addCustomRoot(createRoot());
207             assert.deepEqual(commitSet.customRoots(), [createRoot()]);
208         });
209     });
210 });