add test cases against the cli command

This commit is contained in:
砚然
2018-05-05 15:43:11 +08:00
parent 71477d5aae
commit 3c2ddc3619
5 changed files with 504 additions and 422 deletions

View File

@@ -0,0 +1,27 @@
'use strict';
const path = require('path');
const childProcess = require('child_process');
const pkg = require('../../package');
const binFile = path.resolve(pkg.bin['anyproxy-ca']);
// TODO: more cases are wanted
describe('anyproxy line tool test', () => {
beforeAll(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
});
it('should check the ca status', done => {
childProcess.execFile(binFile, [''], (error, stdout, stderr) => {
if (error) {
console.error(error);
done.fail('anyproxy-ca failed');
}
// If the cert is already generated, the cli will print the info,
// If the cert is not generated, the cli will prompt to install, also contains the `AnyProxy CA/
expect(stdout).toMatch(/AnyProxy CA/);
done();
})
});
});

View File

@@ -0,0 +1,27 @@
'use strict';
const path = require('path');
const spawn = require('child_process').spawn;
const NoRuleSpecExec = require('../spec_rule/no_rule_spec_exec');
const { printLog } = require('../util/CommonUtil.js');
const pkg = require('../../package');
const binFile = path.resolve(pkg.bin.anyproxy);
const startProxyFunc = function () {
printLog('Start AnyProxy by cli');
const childProcessInstance = spawn(binFile, ['-i'], {});
printLog('Start AnyProxy by cli successfully');
return childProcessInstance;
}
const closeProxyFunc = function (instance) {
printLog('Close AnyProxy in cli');
instance.kill('SIGINT');
}
function testRequestByCli() {
NoRuleSpecExec(startProxyFunc, closeProxyFunc);
}
testRequestByCli();