UNPKG

yandex-tank-ammo-generator

Version:

Cartridge generation for Yandex tank

44 lines (43 loc) 1.7 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs"); const ammo_1 = require("./lib/AmmoGenerator/ammo"); const exampleFile_1 = require("./lib/AmmoGenerator/exampleFile"); const program = require("commander"); const ammoConfJsonShema_1 = require("./lib/AmmoGenerator/ammoConfJsonShema"); program .option('-u,--user-agent <agent>', 'UserAgent') .option('-f,--file <file>', 'Special format file ') .option('-o <out>', 'Out filename') .option('-e,--example', 'Create example json file ') .parse(process.argv); let agent = 'Yandex-Tank'; if (program.userAgent) { agent = program.userAgent; } if (program.example) { console.log('Print example -> example.json'); fs.writeFileSync(`${process.env.PWD}/example.json`, JSON.stringify(exampleFile_1.default)); process.exit(0); } if (program.file) { const file = JSON.parse(fs.readFileSync(program.file, { encoding: 'utf8', })); const validateRes = ammoConfJsonShema_1.default.validate(file); if (validateRes.error) { console.error(validateRes.error); process.exit(1); } let tmp = ''; for (const item of file.data) { tmp += ammo_1.createAmmo(item.method.toUpperCase().trim(), file.host, item.path, item.tag, agent, JSON.stringify(item.body), item.headers || {}); } const filename = `${process.env.PWD || '.'}/${program.O ? program.O : `${file.host}`}.txt`; console.log(`Результаты сохранены в ${filename}`); console.log(`Колличество запросов === ${file.data.length}`); fs.writeFileSync(filename, tmp); process.exit(0); } program.help();