mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-02 14:18:43 +08:00
dev: add cartesian case selector
This commit is contained in:
parent
405d9b35aa
commit
dd86724941
@ -3,7 +3,3 @@
|
|||||||
1. run `npm install`
|
1. run `npm install`
|
||||||
2. copy `example_config.yml` and add the correct values
|
2. copy `example_config.yml` and add the correct values
|
||||||
3. run `node apitest.js --config=your_config_file.yml`
|
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)
|
|
||||||
|
@ -12,12 +12,7 @@ const args = process.argv.slice(2);
|
|||||||
let config, report;
|
let config, report;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
({ values: {
|
const parsed = parseArgs({
|
||||||
config,
|
|
||||||
report,
|
|
||||||
bench,
|
|
||||||
unit,
|
|
||||||
}, positionals: [id] } = parseArgs({
|
|
||||||
options: {
|
options: {
|
||||||
config: {
|
config: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
@ -25,13 +20,24 @@ try {
|
|||||||
report: {
|
report: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
},
|
},
|
||||||
|
onlycase: { type: 'string' },
|
||||||
bench: { type: 'boolean' },
|
bench: { type: 'boolean' },
|
||||||
unit: { type: 'boolean' },
|
unit: { type: 'boolean' },
|
||||||
},
|
},
|
||||||
allowPositionals: true,
|
allowPositionals: true,
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
({ values: {
|
||||||
|
config,
|
||||||
|
report,
|
||||||
|
onlycase,
|
||||||
|
bench,
|
||||||
|
unit,
|
||||||
|
}, positionals: [id] } = parsed);
|
||||||
|
|
||||||
|
onlycase = Number.parseInt(onlycase);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if ( args.length < 1 ) {
|
console.error(e);
|
||||||
console.error(
|
console.error(
|
||||||
'Usage: apitest [OPTIONS]\n' +
|
'Usage: apitest [OPTIONS]\n' +
|
||||||
'\n' +
|
'\n' +
|
||||||
@ -41,15 +47,18 @@ try {
|
|||||||
''
|
''
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const conf = YAML.parse(fs.readFileSync(config).toString());
|
const conf = YAML.parse(fs.readFileSync(config).toString());
|
||||||
|
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
const ts = new TestSDK(conf);
|
const context = {
|
||||||
|
options: {
|
||||||
|
onlycase,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const ts = new TestSDK(conf, context);
|
||||||
try {
|
try {
|
||||||
await ts.delete('api_test', { recursive: true });
|
await ts.delete('api_test', { recursive: true });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -12,6 +12,12 @@ module.exports = class TestFactory {
|
|||||||
for ( let i=0 ; i < states.length ; i++ ) {
|
for ( let i=0 ; i < states.length ; i++ ) {
|
||||||
const state = states[i];
|
const state = states[i];
|
||||||
|
|
||||||
|
if ( t.context.options.onlycase !== undefined ) {
|
||||||
|
if ( i !== t.context.options.onlycase ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await t.case(`case ${i}`, async () => {
|
await t.case(`case ${i}`, async () => {
|
||||||
console.log('state', state);
|
console.log('state', state);
|
||||||
await each(t, state, i);
|
await each(t, state, i);
|
||||||
|
@ -9,8 +9,9 @@ const Assert = require('./Assert');
|
|||||||
const log_error = require('./log_error');
|
const log_error = require('./log_error');
|
||||||
|
|
||||||
module.exports = class TestSDK {
|
module.exports = class TestSDK {
|
||||||
constructor (conf) {
|
constructor (conf, context) {
|
||||||
this.conf = conf;
|
this.conf = conf;
|
||||||
|
this.context = context;
|
||||||
this.cwd = `/${conf.username}`;
|
this.cwd = `/${conf.username}`;
|
||||||
this.httpsAgent = new https.Agent({
|
this.httpsAgent = new https.Agent({
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
@ -100,7 +101,7 @@ module.exports = class TestSDK {
|
|||||||
process.stdout.write(strid + ' ... \n');
|
process.stdout.write(strid + ' ... \n');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fn();
|
await fn(this.context);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
process.stdout.write(`${tabs}...\x1B[31;1m[FAIL]\x1B[0m\n`);
|
process.stdout.write(`${tabs}...\x1B[31;1m[FAIL]\x1B[0m\n`);
|
||||||
this.recordResult({
|
this.recordResult({
|
||||||
|
Loading…
Reference in New Issue
Block a user