From dd867249410c4612ea91687e0736931adb2ad17a Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Thu, 9 Jan 2025 16:36:37 -0500 Subject: [PATCH] dev: add cartesian case selector --- tools/api-tester/README.md | 4 --- tools/api-tester/apitest.js | 51 +++++++++++++++++------------ tools/api-tester/lib/TestFactory.js | 6 ++++ tools/api-tester/lib/TestSDK.js | 5 +-- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/tools/api-tester/README.md b/tools/api-tester/README.md index eeaa526a..31616b04 100644 --- a/tools/api-tester/README.md +++ b/tools/api-tester/README.md @@ -3,7 +3,3 @@ 1. run `npm install` 2. copy `example_config.yml` and add the correct values 3. run `node apitest.js --config=your_config_file.yml` - -## Here's what it looks like when it's working - -![image](https://github.com/HeyPuter/puter-api-test/assets/7225168/115aca70-02ea-4ce1-9d5c-1568feb1f851) diff --git a/tools/api-tester/apitest.js b/tools/api-tester/apitest.js index a7aba8ea..383d5703 100644 --- a/tools/api-tester/apitest.js +++ b/tools/api-tester/apitest.js @@ -12,12 +12,7 @@ const args = process.argv.slice(2); let config, report; try { - ({ values: { - config, - report, - bench, - unit, - }, positionals: [id] } = parseArgs({ + const parsed = parseArgs({ options: { config: { type: 'string', @@ -25,31 +20,45 @@ try { report: { type: 'string', }, + onlycase: { type: 'string' }, bench: { type: 'boolean' }, unit: { type: 'boolean' }, }, allowPositionals: true, - })); -} catch (e) { - if ( args.length < 1 ) { - console.error( - 'Usage: apitest [OPTIONS]\n' + - '\n' + - 'Options:\n' + - ' --config= (required) Path to configuration file\n' + - ' --report= (optional) Output file for full test results\n' + - '' - ); - process.exit(1); - } -} + }); + ({ values: { + config, + report, + onlycase, + bench, + unit, + }, positionals: [id] } = parsed); + + onlycase = Number.parseInt(onlycase); +} catch (e) { + console.error(e); + console.error( + 'Usage: apitest [OPTIONS]\n' + + '\n' + + 'Options:\n' + + ' --config= (required) Path to configuration file\n' + + ' --report= (optional) Output file for full test results\n' + + '' + ); + process.exit(1); +} const conf = YAML.parse(fs.readFileSync(config).toString()); const main = async () => { - const ts = new TestSDK(conf); + const context = { + options: { + onlycase, + } + }; + const ts = new TestSDK(conf, context); try { await ts.delete('api_test', { recursive: true }); } catch (e) { diff --git a/tools/api-tester/lib/TestFactory.js b/tools/api-tester/lib/TestFactory.js index 3f9e6719..12dcc85c 100644 --- a/tools/api-tester/lib/TestFactory.js +++ b/tools/api-tester/lib/TestFactory.js @@ -12,6 +12,12 @@ module.exports = class TestFactory { for ( let i=0 ; i < states.length ; i++ ) { const state = states[i]; + if ( t.context.options.onlycase !== undefined ) { + if ( i !== t.context.options.onlycase ) { + continue; + } + } + await t.case(`case ${i}`, async () => { console.log('state', state); await each(t, state, i); diff --git a/tools/api-tester/lib/TestSDK.js b/tools/api-tester/lib/TestSDK.js index 0043581b..8236c7d8 100644 --- a/tools/api-tester/lib/TestSDK.js +++ b/tools/api-tester/lib/TestSDK.js @@ -9,8 +9,9 @@ const Assert = require('./Assert'); const log_error = require('./log_error'); module.exports = class TestSDK { - constructor (conf) { + constructor (conf, context) { this.conf = conf; + this.context = context; this.cwd = `/${conf.username}`; this.httpsAgent = new https.Agent({ rejectUnauthorized: false @@ -100,7 +101,7 @@ module.exports = class TestSDK { process.stdout.write(strid + ' ... \n'); try { - await fn(); + await fn(this.context); } catch (e) { process.stdout.write(`${tabs}...\x1B[31;1m[FAIL]\x1B[0m\n`); this.recordResult({