Skip to content

Commit f643e25

Browse files
committed
test: add tests for new pagination handling
1 parent aa78c2f commit f643e25

File tree

4 files changed

+76
-10
lines changed

4 files changed

+76
-10
lines changed

src/modules/github.xqm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import module namespace config="http://e-editiones.org/tuttle/config" at "config
1010
declare namespace http="http://expath.org/ns/http-client";
1111

1212
declare variable $github:max-page-size := 100;
13-
declare variable $github:max-total-result-size := 100;
13+
declare variable $github:max-total-result-size := 500;
1414

1515
declare function github:repo-url($config as map(*)) as xs:string {
1616
``[`{$config?baseurl}`repos/`{$config?owner}`/`{$config?repo}`]``
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<tuttle>
2+
<repos>
3+
<!-- A version of tuttle sample data with tons of commits so updates go over multiple pages -->
4+
<collection name="tuttle-sample-data">
5+
<default>true</default>
6+
<type>github</type>
7+
<baseurl>https://api.github.com/</baseurl>
8+
<repo>tuttle-sample-data</repo>
9+
<owner>eeditiones</owner>
10+
<token>XXX</token>
11+
<ref>long-history</ref>
12+
<hookuser>admin</hookuser>
13+
<hookpasswd />
14+
</collection>
15+
</repos>
16+
<ignore>
17+
<file>existdb.json</file>
18+
<file>build.xml</file>
19+
<file>README.md</file>
20+
<file>.gitignore</file>
21+
<file>expath-pkg.xml.tmpl</file>
22+
<file>repo.xml.tmpl</file>
23+
<file>build.properties.xml</file>
24+
</ignore>
25+
<config
26+
apikeys="/db/system/auth/tuttle-token.xml"
27+
lock="git-lock.xml"
28+
prefix="/db/apps/"
29+
suffix="-stage"
30+
><sm group="nogroup" mode="rw-r--r--" user="nobody" /></config>
31+
</tuttle>

test/fixtures/alt-tuttle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
<config prefix="/db/apps/" suffix="-stage" lock="git-lock.xml" apikeys="/db/system/auth/tuttle-token.xml">
3737
<sm user="nobody" group="nogroup" mode="rw-r--r--"/>
3838
</config>
39-
</tuttle>
39+
</tuttle>

test/tuttle.js

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default () =>
110110
await assert.doesNotReject(resultPromise, 'The request should succeed');
111111
res = await resultPromise;
112112
})
113-
113+
114114
it('returns status 200', async function () {
115115
assert.strictEqual(res.status, 200);
116116
});
@@ -176,27 +176,62 @@ export default () =>
176176
it('can also write hashes to repo.xml', async () => {
177177
await remove();
178178
await install();
179-
179+
180180
// Set up tuttle with a repo where repo.xml is used to store the git sha info
181181
const buffer = await readFile('./test/fixtures/alt-repoxml-tuttle.xml');
182182
await putResource(buffer, '/db/apps/tuttle/data/tuttle.xml');
183-
183+
184184
const resultPromise = axios.get('git/status', { auth });
185185
await assert.doesNotReject(resultPromise);
186-
186+
187187
const stagingPromise = axios.get('git/tuttle-sample-data', { auth });
188188
await assert.doesNotReject(stagingPromise, 'The request should succeed');
189189

190190
const deployPromise = axios.post('git/tuttle-sample-data', {}, { auth });
191191
await assert.doesNotReject(deployPromise, 'The request should succeed');
192-
192+
193193
const repoXML = await getResource('/db/apps/tuttle-sample-data/repo.xml');
194-
194+
195195
const repo = new DOMParser().parseFromString(repoXML.toString(), 'text/xml').documentElement;
196196
assert.ok(repo.getAttribute('commit-id'), 'The commit id should be set');
197197
assert.ok(repo.getAttribute('commit-time'), 'The commit time should be set');
198198
assert.ok(repo.getAttribute('commit-date'), 'The commit date should be set');
199199
});
200-
201-
});
202200

201+
describe('large histories', async () => {
202+
before(async () => {
203+
await remove();
204+
await install();
205+
});
206+
207+
await it('can upgrade over a few hundred commits', async () => {
208+
// Set up tuttle with a repo with a ton of commits that it can upgrade over
209+
const buffer = await readFile('./test/fixtures/alt-big-repo-tuttle.xml');
210+
await putResource(buffer, '/db/apps/tuttle/data/tuttle.xml');
211+
212+
const OLD_HASH = '41188098f120b6e70d1b0c3bb704a422eba43dfa';
213+
const stageOldVersionPromise = axios.get(`git/tuttle-sample-data?hash=${OLD_HASH}`, { auth });
214+
await assert.doesNotReject(stageOldVersionPromise);
215+
const deployOldVersionPromise = axios.post('git/tuttle-sample-data', {}, { auth });
216+
await assert.doesNotReject(deployOldVersionPromise, 'The request should succeed');
217+
218+
const beforeString = await getResource('/db/apps/tuttle-sample-data/data/regular-changing-document.xml');
219+
220+
const before = new DOMParser().parseFromString(beforeString.toString(), 'text/xml').documentElement;
221+
assert.strictEqual(before.textContent, 'Initial version');
222+
223+
console.log('deployed older version of the sample data on the long-history branch')
224+
225+
const resultPromise = axios.get('git/status', { auth });
226+
await assert.doesNotReject(resultPromise);
227+
228+
const incrementalPromise = axios.post('git/tuttle-sample-data/incremental', {}, { auth });
229+
await assert.doesNotReject(incrementalPromise, 'The incremental request should succeed');
230+
231+
const afterString = await getResource('/db/apps/tuttle-sample-data/data/regular-changing-document.xml');
232+
233+
const after = new DOMParser().parseFromString(afterString.toString(), 'text/xml').documentElement;
234+
assert.strictEqual(after.textContent, 'change for 200');
235+
});
236+
});
237+
});

0 commit comments

Comments
 (0)