Skip to content

Commit

Permalink
fix ctx.RAL_MOCK is null when RAL_MOCK is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
hefangshi committed Jul 25, 2016
1 parent 722301c commit 5e7076c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function MockManager(options) {
var ralMockEnv = process.env.RAL_MOCK ? process.env.RAL_MOCK.toString() : 'false';
if (ralMockEnv === 'true' || ralMockEnv === '1') {
ctx.RAL_MOCK_ALL = true;
ctx.RAL_MOCK = null;
ctx.RAL_MOCK = {};
}
else {
if (process.env.RAL_MOCK) {
Expand All @@ -44,7 +44,7 @@ function MockManager(options) {
}, {});
}
else {
ctx.RAL_MOCK = null;
ctx.RAL_MOCK = {};
}
ctx.RAL_MOCK_ALL = false;
}
Expand Down
31 changes: 31 additions & 0 deletions test/mock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/**
* @file node-ral
* @author [email protected]
* http://fis.baidu.com/
Expand Down Expand Up @@ -205,4 +209,31 @@ describe('mock', function () {
});
});


it.only('should dont mock anything when RAL_MOCK is null', function (done) {
delete process.env.RAL_MOCK;
ral.init({
confDir: path.join(__dirname, './ral/config'),
mockDir: path.join(__dirname, './ral/mock'),
logger: {
log_path: path.join(__dirname, '../logs'),
app: 'yog-ral'
},
currentIDC: 'tc'
});
// should degrade since POST_QS_SERV's enableMock=true
var req = ral('POST_QS_SERV', {
data: {
msg: 'hi',
name: '何方石'
}
});
req.on('data', function (data) {
done();
});
req.on('error', function (err) {
err.message.should.eql('mock fatal hit');
done();
});
});
});

0 comments on commit 5e7076c

Please sign in to comment.