Skip to content

Commit

Permalink
add test && optimize if branches
Browse files Browse the repository at this point in the history
  • Loading branch information
lisposter committed Jul 30, 2014
1 parent baefc67 commit 1524e22
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ function request(method, path, checksum, opts, body, localpath, cb){
UPYUN.prototype.getConf = function(key) {
if(_CONF[key]) {
return _CONF[key];
} else {
return;
}
}

Expand Down Expand Up @@ -142,8 +144,11 @@ UPYUN.prototype.getFileList = function(path) {

UPYUN.prototype.createDir = function(path, mkdir) {
return function(fn) {
var opts = { "Folder": true };
if(mkdir !== false) opts["Mkdir"] = true;
var opts = {
"Folder": true,
"Mkdir": true
};
if(mkdir === false) opts["Mkdir"] = false;
request('POST', path, null, opts, null, null, function(err, res) {
if(err) return fn(err);
fn(null, res);
Expand Down
10 changes: 10 additions & 0 deletions test/basic-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ describe('API', function() {
co(function *() {
var res = yield upyun.createDir('/createdirtest2/subdir/', true);
res.should.have.property('statusCode').be.exactly(200);
yield upyun.removeDir('/createdirtest2/subdir/');
yield upyun.removeDir('/createdirtest2/');
})(done)
})

it('should response 200', function(done) {
co(function *() {
var res = yield upyun.createDir('/createdirtest3/', false);
res.should.have.property('statusCode').be.exactly(200);
yield upyun.removeDir('/createdirtest3/');
})(done)
})
})
Expand Down
4 changes: 4 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ describe('utils', function() {
it('should get bucket name', function() {
upyun.getConf('bucket').should.be.exactly('travis');
})

it('should return nothing', function() {
(upyun.getConf('null') === undefined).should.be.true;
})
})

describe('.setEndpoint(ep)', function() {
Expand Down

0 comments on commit 1524e22

Please sign in to comment.