2017-04-19 14:15:28 -05:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
let assert = require('assert');
|
|
|
|
let async = require('async');
|
|
|
|
let _oksum = 0;
|
2013-12-19 10:11:54 -05:00
|
|
|
|
|
|
|
module.exports = function() {
|
2017-04-19 14:15:28 -05:00
|
|
|
let server = process.server;
|
2013-12-29 01:40:47 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
describe('race', function() {
|
2017-04-19 14:15:28 -05:00
|
|
|
before(function() {
|
2015-04-11 12:11:04 -05:00
|
|
|
return server.put_package('race', require('./lib/package')('race'))
|
|
|
|
.status(201)
|
2017-04-19 14:15:28 -05:00
|
|
|
.body_ok(/created new package/);
|
|
|
|
});
|
2013-12-19 10:11:54 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('creating new package', function() {});
|
2013-12-19 10:11:54 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
it('uploading 10 same versions', function(callback) {
|
|
|
|
let fns = [];
|
|
|
|
for (let i=0; i<10; i++) {
|
2014-11-12 06:14:37 -05:00
|
|
|
fns.push(function(cb_) {
|
2017-04-19 14:15:28 -05:00
|
|
|
let data = require('./lib/package')('race');
|
|
|
|
data.rand = Math.random();
|
2015-04-11 12:11:04 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
let _res;
|
2015-04-11 12:11:04 -05:00
|
|
|
server.put_version('race', '0.0.1', data)
|
2017-04-19 14:15:28 -05:00
|
|
|
.response(function(res) {
|
|
|
|
_res = res;
|
|
|
|
})
|
|
|
|
.then(function(body) {
|
|
|
|
cb_(null, [_res, body]);
|
|
|
|
});
|
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
}
|
2013-12-19 10:11:54 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
async.parallel(fns, function(err, res) {
|
2017-04-19 14:15:28 -05:00
|
|
|
let okcount = 0;
|
|
|
|
let failcount = 0;
|
2015-03-28 13:25:53 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
assert.equal(err, null);
|
2013-12-19 10:11:54 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
res.forEach(function(arr) {
|
2017-04-19 14:15:28 -05:00
|
|
|
let resp = arr[0];
|
|
|
|
let body = arr[1];
|
|
|
|
|
|
|
|
if (resp.statusCode === 201 && ~body.ok.indexOf('published')) okcount++;
|
|
|
|
if (resp.statusCode === 409 && ~body.error.indexOf('already present')) failcount++;
|
|
|
|
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) failcount++;
|
|
|
|
});
|
|
|
|
assert.equal(okcount + failcount, 10);
|
|
|
|
assert.equal(okcount, 1);
|
|
|
|
_oksum += okcount;
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uploading 10 diff versions', function(callback) {
|
|
|
|
let fns = [];
|
|
|
|
for (let i=0; i<10; i++) {
|
2014-11-12 06:14:37 -05:00
|
|
|
;(function(i) {
|
|
|
|
fns.push(function(cb_) {
|
2017-04-19 14:15:28 -05:00
|
|
|
let _res;
|
2015-04-11 12:11:04 -05:00
|
|
|
server.put_version('race', '0.1.'+String(i), require('./lib/package')('race'))
|
2017-04-19 14:15:28 -05:00
|
|
|
.response(function(res) {
|
|
|
|
_res = res;
|
|
|
|
})
|
|
|
|
.then(function(body) {
|
|
|
|
cb_(null, [_res, body]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})(i);
|
2014-11-12 06:14:37 -05:00
|
|
|
}
|
2013-12-19 10:11:54 -05:00
|
|
|
|
2014-11-12 06:14:37 -05:00
|
|
|
async.parallel(fns, function(err, res) {
|
2017-04-19 14:15:28 -05:00
|
|
|
let okcount = 0;
|
|
|
|
let failcount = 0;
|
2013-12-19 10:11:54 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
assert.equal(err, null);
|
2014-11-12 06:14:37 -05:00
|
|
|
res.forEach(function(arr) {
|
2017-04-19 14:15:28 -05:00
|
|
|
let resp = arr[0];
|
|
|
|
let body = arr[1];
|
|
|
|
if (resp.statusCode === 201 && ~body.ok.indexOf('published')) okcount++;
|
|
|
|
if (resp.statusCode === 409 && ~body.error.indexOf('already present')) failcount++;
|
|
|
|
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) failcount++;
|
|
|
|
});
|
|
|
|
assert.equal(okcount + failcount, 10);
|
|
|
|
assert.notEqual(okcount, 1);
|
|
|
|
_oksum += okcount;
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
after('downloading package', function() {
|
2015-04-11 12:11:04 -05:00
|
|
|
return server.get_package('race')
|
|
|
|
.status(200)
|
2017-04-19 14:15:28 -05:00
|
|
|
.then(function(body) {
|
|
|
|
assert.equal(Object.keys(body.versions).length, _oksum);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2013-12-19 10:11:54 -05:00
|
|
|
|