Skip to content

Commit

Permalink
test: 添加beforeRequest testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
hefangshi committed May 9, 2017
1 parent 6f0a6e0 commit 63f057c
Showing 1 changed file with 49 additions and 49 deletions.
98 changes: 49 additions & 49 deletions test/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,55 +495,55 @@ describe('http proxy', function () {
});
});

// describe('beforeRequest hook', function () {
// it('should trigger before request', function (done) {
// var getTest = require('./protocol/http_protocol_get_test.js');
// // start a http server for get
// var server = getTest.createServer();
// var httpProtocol = new HttpProtocol();
// var context = HttpProtocol.normalizeConfig(getTest.service);
// context.path = '/gziperror';
// context.disableGzip = false;
// context.beforeRequest = function (context) {
// context.server.port.should.be.eql(8934);
// context.server.host.should.be.eql('127.0.0.1');
// return context;
// }
// util.merge(context, getTest.request);
// httpProtocol.talk(context, function (res) {
// res.on('end', function (data) {
// server.close();
// data.toString().should.not.be.ok;
// done();
// });
// res.on('error', function (err) {
// server.close();
// err.message.should.be.match(/unexpected end of file/);
// done();
// });
// });
// });

// it('should cancel request by return false', function () {
// var getTest = require('./protocol/http_protocol_get_test.js');
// // start a http server for get
// // var server = getTest.createServer();
// var httpProtocol = new HttpProtocol();
// var context = HttpProtocol.normalizeConfig(getTest.service);
// context.path = '/gziperror';
// context.disableGzip = false;
// context.beforeRequest = function (context) {
// return false;
// }
// util.merge(context, getTest.request);
// try {
// httpProtocol.talk(context);
// } catch (ex) {
// // server.close();
// ex.message.toString().should.be.eql('Request was canceled by beforeRequest hook since returned context was false');
// }
// });
// });
describe('beforeRequest hook', function () {
it('should trigger before request', function (done) {
var getTest = require('./protocol/http_protocol_get_test.js');
// start a http server for get
var server = getTest.createServer();
var httpProtocol = new HttpProtocol();
var context = HttpProtocol.normalizeConfig(getTest.service);
context.path = '/gziperror';
context.disableGzip = false;
context.beforeRequest = function (context) {
context.server.port.should.be.eql(8934);
context.server.host.should.be.eql('127.0.0.1');
return context;
}
util.merge(context, getTest.request);
httpProtocol.talk(context, function (res) {
res.on('end', function (data) {
server.close();
data.toString().should.not.be.ok;
done();
});
res.on('error', function (err) {
server.close();
err.message.should.be.match(/unexpected end of file/);
done();
});
});
});

it('should cancel request by return false', function () {
var getTest = require('./protocol/http_protocol_get_test.js');
// start a http server for get
// var server = getTest.createServer();
var httpProtocol = new HttpProtocol();
var context = HttpProtocol.normalizeConfig(getTest.service);
context.path = '/gziperror';
context.disableGzip = false;
context.beforeRequest = function (context) {
return false;
}
util.merge(context, getTest.request);
try {
httpProtocol.talk(context);
} catch (ex) {
// server.close();
ex.message.toString().should.be.eql('Request was canceled by beforeRequest hook since returned context was false');
}
});
});

describe('soap protocol', function () {
it.skip('should request wsdl service successfully', function (done) {
Expand Down

0 comments on commit 63f057c

Please # to comment.