Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lisposter committed Jul 30, 2014
1 parent bdfec65 commit cfbe56b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ Delete a dir
---------------------------------------

<a name="uploadFile" />
### uploadFile(remote_path, file, make_dir, opts)
### uploadFile(remote_path, file, make_dir, checksum, opts)
Upload a file into UPYUN bucket.

__Arguments__
* `remote_path` Where the file will be stored in your UPYUN bucket.
* `file` The file you want to upload. It can be a `path` string or the file's raw data.
* `make_dir` Auto create parent dir if it isn't exists.(Default: `true`).
* `checksum` Set `true` to force SDK send a md5 of local file to UPYUN. Or set a md5value string by yourself.
* `opts` The additional http request headers. More detail in [Official Docs](http://docs.upyun.com/api/http_api/#上传文件)

---------------------------------------
Expand Down
30 changes: 29 additions & 1 deletion test/basic-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ describe('API', function() {
res.should.have.property('statusCode').be.exactly(200);
})(done)
})

it('should response 200', function(done) {
co(function *() {
var res = yield upyun.createDir('/createdirtest2/subdir/', true);
res.should.have.property('statusCode').be.exactly(200);
})(done)
})
})

describe('.removeDir(path)', function() {
Expand All @@ -45,13 +52,34 @@ describe('API', function() {
})
})

describe('.uploadFile(path, file, makedir, opts)', function() {
describe('.uploadFile(path, data, mkdir, checksum, opts)', function() {
it('should response 200', function(done) {
co(function *() {
var res = yield upyun.uploadFile('/lorem/lorem.txt', './LICENSE', true, null, null);
res.should.have.property('statusCode').be.exactly(200);
})(done)
})

it('should response 200', function(done) {
co(function *() {
var res = yield upyun.uploadFile('/lorem/lorem.txt', 'TESTTEST', true, null, null);
res.should.have.property('statusCode').be.exactly(200);
})(done)
})

it('should response 200', function(done) {
co(function *() {
var res = yield upyun.uploadFile('/lorem/lorem.txt', 'TESTTEST', true, true, null);
res.should.have.property('statusCode').be.exactly(200);
})(done)
})

it('should return not found', function(done) {
co(function *() {
var res = yield upyun.uploadFile('/lorem2/lorem.txt', './LICENSE', false, null, null);
res.should.have.property('statusCode').be.exactly(404);
})(done)
})
})

describe('.getFileInfo(path)', function() {
Expand Down
19 changes: 19 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var UPYUN = require('..');
var should = require('should');

var upyun = new UPYUN('travis', 'travisci', 'testtest', 'ctcc');

describe('utils', function() {
describe('.getConf(key)', function() {
it('should get bucket name', function() {
upyun.getConf('bucket').should.be.exactly('travis');
})
})

describe('.setEndpoint(ep)', function() {
it('should set endpoint', function() {
upyun.setEndpoint('ctcc');
upyun.getConf('endpoint').should.be.exactly('v1.api.upyun.com');
})
})
})

0 comments on commit cfbe56b

Please sign in to comment.