Skip to content

Commit 194ed55

Browse files
committed
Merge pull request #73 from lintianzhi/feature/kv_to_nil
{} -> nil
2 parents e7d7903 + 5399e17 commit 194ed55

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

qiniu/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ exports.generateAccessToken = function(uri, body) {
8080
exports.getResp = function(onret) {
8181
var onresp = function(res) {
8282
exports.readAll(res, function(data) {
83-
var ret = {};
84-
var err = {};
83+
var err, ret;
8584

8685
if (Math.floor(res.statusCode/100) === 2) {
8786
if (data.length !== 0) {
8887
try {
8988
ret = JSON.parse(data);
9089
} catch (e) {
90+
err = {code: res.statusCode, err: e.toString()};
9191
}
9292
}
9393
} else {

test/io.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('test start step1:', function() {
3030

3131
var client = new qiniu.rs.Client();
3232
client.batchDelete(entries, function(err, ret) {
33-
err.should.eql({});
33+
should.not.exist(err);
3434
done();
3535
});
3636
});
@@ -48,7 +48,7 @@ describe('test start step1:', function() {
4848
it('test upload from memory', function(done) {
4949
var key = 'filename' + Math.random(1000);
5050
qiniu.io.put(uptoken, key, 'content', null, function(err, ret) {
51-
err.should.eql({});
51+
should.not.exist(err);
5252
ret.should.have.keys('hash', 'key');
5353
ret.key.should.equal(key);
5454
keys.push(ret.key);
@@ -61,7 +61,7 @@ describe('test start step1:', function() {
6161
it('test upload from memory without key', function(done) {
6262
var content = 'content' + Math.random(1000);
6363
qiniu.io.putWithoutKey(uptoken, content, null, function(err, ret) {
64-
err.should.eql({});
64+
should.not.exist(err);
6565
ret.should.have.keys('hash', 'key');
6666
ret.key.should.equal(ret.hash);
6767
keys.push(ret.key);
@@ -74,7 +74,7 @@ describe('test start step1:', function() {
7474
it('test upload from a file', function(done) {
7575
var key = Math.random() + 'logo.png';
7676
qiniu.io.putFile(uptoken, key, imageFile, null, function(err, ret) {
77-
err.should.eql({});
77+
should.not.exist(err);
7878
ret.should.have.keys('key', 'hash');
7979
ret.key.should.equal(key);
8080
keys.push(ret.key);
@@ -87,7 +87,7 @@ describe('test start step1:', function() {
8787
extra.checkCrc = 1;
8888
var key = Math.random() + 'logo_crc32.png';
8989
qiniu.io.putFile(uptoken, key, imageFile, extra, function(err, ret) {
90-
err.should.eql({});
90+
should.not.exist(err);
9191
ret.should.have.keys('key', 'hash');
9292
ret.key.should.equal(key);
9393
keys.push(ret.key);
@@ -115,7 +115,7 @@ describe('test start step1:', function() {
115115
describe('rsf.listPrefix()', function() {
116116
it('list all file in test bucket', function(done) {
117117
qiniu.rsf.listPrefix(TEST_BUCKET, null, null, null, function(err, ret) {
118-
err.should.eql({});
118+
should.not.exist(err);
119119
// ret.data.items.length.should.equal(keys.length);
120120
for (i in ret.items) {
121121
ret.items[i].should.have.keys('key', 'putTime', 'hash', 'fsize', 'mimeType');

test/rs.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ describe('test start step2:', function() {
2828
var putPolicy = new qiniu.rs.PutPolicy(TEST_BUCKET);
2929
var uptoken = putPolicy.token();
3030
qiniu.io.putFile(uptoken, logo2, imageFile, null, function(err, ret) {
31-
err.should.eql({});
31+
should.not.exist(err);
3232
});
3333
qiniu.io.putFile(uptoken, logo, imageFile, null, function(err, ret) {
34-
err.should.eql({});
34+
should.not.exist(err);
3535
done();
3636
});
3737
});
3838

3939
describe('rs.Client#stat()', function() {
4040
it('get the stat of a file', function(done) {
4141
client.stat(TEST_BUCKET, logo, function(err, ret) {
42-
err.should.eql({});
42+
should.not.exist(err);
4343
ret.should.have.keys('hash', 'fsize', 'putTime', 'mimeType');
4444
done();
4545
});
@@ -49,7 +49,7 @@ describe('test start step2:', function() {
4949
describe('rs.Client#copy()', function() {
5050
it('copy logo.png to logo1.png', function(done) {
5151
client.copy(TEST_BUCKET, logo, TEST_BUCKET, logo1, function(err, ret) {
52-
err.should.eql({});
52+
should.not.exist(err);
5353
done();
5454
});
5555
});
@@ -58,7 +58,7 @@ describe('test start step2:', function() {
5858
describe('rs.Client#remove()', function() {
5959
it('remove logo.png', function(done) {
6060
client.remove(TEST_BUCKET, logo, function(err, ret) {
61-
err.should.eql({});
61+
should.not.exist(err);
6262
done();
6363
});
6464
});
@@ -67,7 +67,7 @@ describe('test start step2:', function() {
6767
describe('rs.Client#move()', function() {
6868
it('move logo1.png to logo.png', function(done) {
6969
client.move(TEST_BUCKET, logo1, TEST_BUCKET, logo, function(err, ret) {
70-
err.should.eql({});
70+
should.not.exist(err);
7171
done();
7272
});
7373
});
@@ -80,7 +80,7 @@ describe('test start step2:', function() {
8080
var entries = [new EntryPath(TEST_BUCKET, logo), new EntryPath(TEST_BUCKET, logo2)];
8181

8282
client.batchDelete(entries, function(err, ret) {
83-
err.should.eql({});
83+
should.not.exist(err);
8484
done();
8585
});
8686
});
@@ -92,7 +92,7 @@ describe('test start step2:', function() {
9292
new EntryPath(TEST_BUCKET, logo2)];
9393

9494
client.batchStat(entries, function(err, ret) {
95-
err.should.eql({});
95+
should.not.exist(err);
9696
ret.length.should.equal(2);
9797
for (i in ret) {
9898
ret[i].code.should.equal(200);
@@ -109,7 +109,7 @@ describe('test start step2:', function() {
109109
new EntryPath(TEST_BUCKET, 'not exist file')];
110110

111111
client.batchStat(entries, function(err, ret) {
112-
err.should.eql({}); // 298
112+
should.not.exist(err); // 298
113113
ret.length.should.equal(2);
114114

115115
for (i in ret) {
@@ -132,7 +132,7 @@ describe('test start step2:', function() {
132132

133133
it('copy from logo, logo2 to logo1, logo3', function(done) {
134134
client.batchCopy(entries, function(err, ret) {
135-
err.should.eql({});
135+
should.not.exist(err);
136136
console.log(ret);
137137
done();
138138
});
@@ -144,7 +144,7 @@ describe('test start step2:', function() {
144144

145145
it('delete logo.png, logo2.png', function(done) {
146146
client.batchDelete(entries, function(err, ret) {
147-
err.should.eql({});
147+
should.not.exist(err);
148148
done();
149149
});
150150
});
@@ -157,7 +157,7 @@ describe('test start step2:', function() {
157157

158158
it('move from logo1.png, logo3.png to logo.png, logo2.png', function(done) {
159159
client.batchMove(entries, function(err, ret) {
160-
err.should.eql({});
160+
should.not.exist(err);
161161
done();
162162
});
163163
});

0 commit comments

Comments
 (0)