Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix test #115

Merged
merged 2 commits into from Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@ coverage.html
*.out
*.pid
*.gz
.DS_Store

pids
logs
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -8,4 +8,4 @@ install:
script:
- npm run ci
after_script:
- npm i codecov && codecov
- npminstall codecov && codecov
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -5,7 +5,7 @@ environment:

install:
- ps: Install-Product node $env:nodejs_version
- npm i npminstall && npminstall
- npm i npminstall && node_modules\.bin\npminstall

test_script:
- node --version
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -24,9 +24,9 @@
"egg-ci": "^1.0.2",
"istanbul": "*",
"jshint": "^2.9.2",
"mocha": "2",
"mocha": "^3.1.2",
"pedding": "1",
"should": "8",
"should": "^11.1.1",
"should-http": "*"
},
"homepage": "https://github.com/node-modules/qn",
Expand Down
10 changes: 5 additions & 5 deletions test/config.json
@@ -1,7 +1,7 @@
{
"accessKey": "5UyUq-l6jsWqZMU6tuQ85Msehrs3Dr58G-mCZ9rE",
"secretKey": "YaRsPKiYm4nGUt8mdz2QxeV5Q_yaUzVxagRuWTfM",
"bucket": "qiniu-sdk-test",
"domain": "http://qiniu-sdk-test.qiniudn.com",
"uploadURL": "http://up.qiniug.com/"
"accessKey": "QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm",
"secretKey": "Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz",
"bucket": "nodesdk",
"domain": "http://nodesdk.qiniudn.com",
"uploadURL": "http://upload.qiniu.com/"
}
5 changes: 3 additions & 2 deletions test/doc.test.js
Expand Up @@ -13,6 +13,7 @@
var should = require('should');
var urllib = require('urllib');
var path = require('path');
var config = require('./config.json');

describe('doc.test.js', function () {
before(function () {
Expand Down Expand Up @@ -41,9 +42,9 @@ describe('doc.test.js', function () {

it('should convert markdown to html with css', function (done) {
var url = this.client.md2html('qn/test/fixtures/readme.md', {
css: 'http://qiniu-sdk-test.qiniudn.com/qn/test/fixtures/github.css'
css: config.domain + '/qn/test/fixtures/github.css'
});
url.should.containEql('.qiniudn.com/qn/test/fixtures/readme.md?md2html/0/css/aHR0cDovL3Fpbml1LXNkay10ZXN0LnFpbml1ZG4uY29tL3FuL3Rlc3QvZml4dHVyZXMvZ2l0aHViLmNzcw==');
url.should.containEql('.qiniudn.com/qn/test/fixtures/readme.md?md2html/0/css/aHR0cDovL25vZGVzZGsucWluaXVkbi5jb20vcW4vdGVzdC9maXh0dXJlcy9naXRodWIuY3Nz');
urllib.request(url, function (err, data, res) {
should.not.exist(err);
data.length.should.above(0);
Expand Down
Binary file added test/fixtures/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions test/image.test.js
Expand Up @@ -22,12 +22,15 @@ describe('image.test.js', function () {
});

before(function (done) {
done = pedding(3, done);
this.client.uploadFile(path.join(__dirname, 'fixtures', 'logo.png'), {key: 'qn/fixtures/logo.png'}, done);
this.client.uploadFile(path.join(__dirname, 'fixtures', 'big.txt'), {key: 'qn/fixtures/big.txt'}, done);
this.client.uploadFile(path.join(__dirname, 'fixtures', 'gogopher.jpg'), {key: 'qn/fixtures/gogopher.jpg'}, done);
});

describe('imageInfo()', function () {
it('should return image info', function (done) {
this.client.imageInfo('qn/logo.png', function (err, info) {
this.client.imageInfo('qn/fixtures/logo.png', function (err, info) {
should.not.exist(err);
info.should.have.keys('format', 'width', 'height', 'colorModel');
info.should.eql({ format: 'png', width: 190, height: 150, colorModel: 'nrgba' });
Expand Down Expand Up @@ -80,7 +83,7 @@ describe('image.test.js', function () {
});

it('should return error when file is not image', function (done) {
var url = this.client.imageView('qn/big.txt', {mode: 1, width: 50, height: 50});
var url = this.client.imageView('qn/fixtures/big.txt', {mode: 1, width: 50, height: 50});
url.should.match(/\?imageView\/1\/w\/50\/h\/50$/);
urllib.request(url, function (err, data, res) {
should.not.exist(err);
Expand Down Expand Up @@ -118,7 +121,7 @@ describe('image.test.js', function () {

describe('imageMogr()', function () {
it('should rotate a image', function (done) {
var url = this.client.imageMogr('qn/logo.png', {
var url = this.client.imageMogr('qn/fixtures/logo.png', {
thumbnail: '!50p',
gravity: 'NorthWest',
quality: 50,
Expand All @@ -138,7 +141,7 @@ describe('image.test.js', function () {

describe('watermark()', function () {
it('should return text watermark image', function (done) {
var url = this.client.watermark('qn/logo.png', {
var url = this.client.watermark('qn/fixtures/logo.png', {
mode: 2,
text: 'Node.js 哈哈',
font: '宋体',
Expand Down
4 changes: 2 additions & 2 deletions test/rs.test.js
Expand Up @@ -238,9 +238,9 @@ describe('rs.test.js', function () {
result.items.should.length(5);
result.marker.should.be.a.String;
// next page
that.client.list({prefix: '/qn', limit: 11, marker: result.marker}, function (err, result2) {
that.client.list({prefix: '/qn', limit: 5, marker: result.marker}, function (err, result2) {
should.not.exist(err);
result2.items.should.length(11);
result2.items.should.length(5);
result2.marker.should.be.a.String;
done();
});
Expand Down
40 changes: 21 additions & 19 deletions test/up.test.js
Expand Up @@ -16,6 +16,7 @@ var fs = require('fs');
var path = require('path');
var utility = require('utility');
var qn = require('../');
var config = require('./config.json');

var root = path.dirname(__dirname);
var fixtures = path.join(__dirname, 'fixtures');
Expand Down Expand Up @@ -91,7 +92,7 @@ describe('up.test.js', function () {
result.should.have.keys('hash', 'key', 'url', 'x:ctime', 'x:filename', 'x:mtime', 'x:size');
result.hash.should.equal('FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki');
result.key.should.equal('qn/test/logo.png');
result.url.should.equal('http://qiniu-sdk-test.qiniudn.com/qn/test/logo.png');
result.url.should.equal(config.domain + '/qn/test/logo.png');
result["x:filename"].should.equal('logo.png');
result["x:ctime"].should.be.match(/^[\d\.]+$/);
result["x:mtime"].should.be.match(/^[\d\.]+$/);
Expand Down Expand Up @@ -127,10 +128,11 @@ describe('up.test.js', function () {

it('should success when upload same key and same content', function (done) {
this.client.upload('foo bar 哈哈', {filename: 'foo', key: 'foo'}, function (err, result) {
should.exist(err);
err.name.should.equal('QiniuFileExistsError');
err.code.should.equal(614);
err.message.should.equal('file exists');
should.not.exist(err);
should.exist(result);
result.hash.should.equal('FiuFB_kYboxBnU6VCMirPzLtIpIq');
result.key.should.equal('foo');
result.url.should.containEql('.qiniudn.com/foo');
done();
});
});
Expand All @@ -150,7 +152,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FptOdeKmWhcYHUXa5YmNZxJC934B',
key: 'foobar.txt',
url: 'http://qiniu-sdk-test.qiniudn.com/foobar.txt',
url: config.domain + '/foobar.txt',
'x:foo': 'bar哈哈',
"x:ctime": "2013-09-02T19:32:51.000Z",
"x:filename": "logo.png",
Expand All @@ -169,7 +171,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'Fto5o-5ea0sNMlW_75VgGJCv2AcJ',
key: 'Fto5o-5ea0sNMlW_75VgGJCv2AcJ',
url: 'http://qiniu-sdk-test.qiniudn.com/Fto5o-5ea0sNMlW_75VgGJCv2AcJ'
url: config.domain + '/Fto5o-5ea0sNMlW_75VgGJCv2AcJ'
});
done();
});
Expand Down Expand Up @@ -204,7 +206,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
key: 'FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
url: 'http://qiniu-sdk-test.qiniudn.com/FhRP7GIsuzMrSOp0AQnVVymMNsXJ'
url: config.domain + '/FhRP7GIsuzMrSOp0AQnVVymMNsXJ'
});
done();
});
Expand All @@ -218,7 +220,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
key: 'qn/big.txt',
url: 'http://qiniu-sdk-test.qiniudn.com/qn/big.txt'
url: config.domain + '/qn/big.txt'
});
done();
});
Expand All @@ -231,7 +233,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki',
key: 'FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki',
url: 'http://qiniu-sdk-test.qiniudn.com/FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki'
url: config.domain + '/FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki'
});
done();
});
Expand All @@ -244,7 +246,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki',
key: 'FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki',
url: 'http://qiniu-sdk-test.qiniudn.com/FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki'
url: config.domain + '/FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki'
});
done();
});
Expand All @@ -257,7 +259,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki',
key: 'qn/logo.png',
url: 'http://qiniu-sdk-test.qiniudn.com/qn/logo.png'
url: config.domain + '/qn/logo.png'
});
done();
});
Expand All @@ -273,7 +275,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
key: 'FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
url: 'http://qiniu-sdk-test.qiniudn.com/FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
url: config.domain + '/FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
"x:filename": "big.txt",
});
done();
Expand All @@ -289,7 +291,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FvnDEnGu6pjzxxxc5d6IlNMrbDnH',
key: 'foo_chunked.txt',
url: 'http://qiniu-sdk-test.qiniudn.com/foo_chunked.txt',
url: config.domain + '/foo_chunked.txt',
"x:filename": "foo.txt",
});
done();
Expand All @@ -304,7 +306,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FvnDEnGu6pjzxxxc5d6IlNMrbDnH',
key: 'FvnDEnGu6pjzxxxc5d6IlNMrbDnH',
url: 'http://qiniu-sdk-test.qiniudn.com/FvnDEnGu6pjzxxxc5d6IlNMrbDnH',
url: config.domain + '/FvnDEnGu6pjzxxxc5d6IlNMrbDnH',
"x:filename": "foo.txt",
});
done();
Expand All @@ -321,7 +323,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FvnDEnGu6pjzxxxc5d6IlNMrbDnH',
key: 'FvnDEnGu6pjzxxxc5d6IlNMrbDnH',
url: 'http://qiniu-sdk-test.qiniudn.com/FvnDEnGu6pjzxxxc5d6IlNMrbDnH',
url: config.domain + '/FvnDEnGu6pjzxxxc5d6IlNMrbDnH',
"x:filename": "foo.txt",
});
done();
Expand All @@ -337,7 +339,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
key: 'FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
url: 'http://qiniu-sdk-test.qiniudn.com/FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
url: config.domain + '/FhRP7GIsuzMrSOp0AQnVVymMNsXJ',
"x:filename": "big.txt",
});
done();
Expand All @@ -351,7 +353,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki',
key: 'FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki',
url: 'http://qiniu-sdk-test.qiniudn.com/FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki',
url: config.domain + '/FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki',
"x:filename": "logo.png",
});
done();
Expand Down Expand Up @@ -383,7 +385,7 @@ describe('up.test.js', function () {
result.should.eql({
hash: 'FvzqAF1oWlYgQ9t62k_xn_mzZ1Ki',
key: 'qn/logo_chunked.png',
url: 'http://qiniu-sdk-test.qiniudn.com/qn/logo_chunked.png',
url: config.domain + '/qn/logo_chunked.png',
"x:filename": "logo.png",
});
done();
Expand Down