mof-proxy
Version:
proxy middleware for floodesh
73 lines (58 loc) • 1.61 kB
JavaScript
const should = require('should')
const co = require('co')
const Mof = require('mof')
const proxy = require('../')
//const sinon = require('sinon')
//require('should-sinon')
describe('mof-proxy ', () => {
let log = function(a,b,c){console.log(a,b,c);};
let ctx, app,options, application={name:"tmall",logger:{debug:log,info:log,verbose:log,warn:log,error:log}, config:{downloader:{}}};
beforeEach(()=>{
app = new Mof();
ctx = {opt:{uri:'http://www.baidu.com'}, app:application, response:{},request:{},job:{uuid:"uuid"}};
options = {jar:true};
});
it('should acquire proxy from filtered proxy vendor',(done)=>{
app.use(co.wrap(proxy({
server:"http://localhost:1337",
filter: [{name: "kunpeng_wuba"}],
customedConfig: true
})));
const handle = app.callback(ctx => {
should.exist(ctx.opt.proxy);
ctx.opt.proxy.match(/:8888$/);
done();
}, (e) => {
console.error(e);
});
handle(ctx);
});
it('should acquire proxy from one of proxy vendors',(done)=>{
app.use(co.wrap(proxy({
server:"http://localhost:1337",
filter: [{name: "kunpeng_wuba"},{name:"fucking"}],
customedConfig: true
})));
const handle = app.callback(ctx => {
should.exist(ctx.opt.proxy);
ctx.opt.proxy.match(/:8888$/);
done();
}, (e) => {
console.error(e);
});
handle(ctx);
});
it("should get proxy from service",(done)=>{
app.use(co.wrap(proxy({
server:"http://localhost:1337"
})));
const handle = app.callback(ctx => {
should.exist(ctx.opt.proxy);
done();
}, (e) => {
console.error(e);
});
handle(ctx);
});
});