Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zengjialuo committed Jun 23, 2014
1 parent 6d700dd commit e7e0d92
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ BaiduCloudStorage.prototype.realUpload = function(data,
objectName) {
var def = new edp.Deferred();

objectName = '/' + objectName;
objectName = objectName.replace(/\/+/g, '/');

var targetUrl = this.sign( 'PUT', bucketName, objectName );
Expand Down
39 changes: 39 additions & 0 deletions test/sdk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,45 @@ describe('sdk', function(){
});
});

it('upload data', function(){
var bucket = 'adtest';
var ak = 'ak';
var sk = 'sk';

var maxSize = 10 * 1024 * 1024;
var autoUri = false;

var data = 'for upload data';
var objectName = '/prefix/name.js';

var sdk = new bcs.BaiduCloudStorage( ak, sk, maxSize, autoUri );
sdk._sendRequest = createSpy('sdk._sendRequest').andCallFake(function( options, data, targetUrl, def ){
setTimeout(function(){
var bcsUrl = decodeURIComponent( targetUrl.replace(/\?.*/g, '') );
def.resolve( bcsUrl );
}, 500);
});

var errorMsg = null;
var result;
var d = sdk.realUpload( data, bucket, objectName );
d.fail(function(e){
errorMsg = e.toString().trim();
});
d.done(function(x){
result = x;
});

waitsFor(function(){ return d.state !== 'pending'; });

runs(function(){
expect( d.state ).toBe( 'resolved' );
expect( errorMsg ).toBe( null );
expect( result ).toBe( 'http://bs.baidu.com/adtest/prefix/name.js' );
});
});


it('upload directory', function(){
var bucket = 'adtest';
var ak = 'ak';
Expand Down

0 comments on commit e7e0d92

Please sign in to comment.