2014-11-12 12:14:37 +01:00
|
|
|
var assert = require('assert')
|
|
|
|
var async = require('async')
|
|
|
|
var _oksum = 0
|
2013-12-19 16:11:54 +01:00
|
|
|
|
|
|
|
module.exports = function() {
|
2014-11-12 12:14:37 +01:00
|
|
|
var server = process.server
|
2013-12-29 07:40:47 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
describe('race', function() {
|
2015-04-11 19:11:04 +02:00
|
|
|
before(function () {
|
|
|
|
return server.put_package('race', require('./lib/package')('race'))
|
|
|
|
.status(201)
|
|
|
|
.body_ok(/created new package/)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
it('creating new package', function(){})
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('uploading 10 same versions', function (callback) {
|
2014-11-12 12:14:37 +01:00
|
|
|
var fns = []
|
|
|
|
for (var i=0; i<10; i++) {
|
|
|
|
fns.push(function(cb_) {
|
|
|
|
var data = require('./lib/package')('race')
|
|
|
|
data.rand = Math.random()
|
2015-04-11 19:11:04 +02:00
|
|
|
|
|
|
|
var _res
|
|
|
|
server.put_version('race', '0.0.1', data)
|
|
|
|
.response(function (res) { _res = res })
|
|
|
|
.then(function (body) {
|
|
|
|
cb_(null, [ _res, body ])
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
}
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
async.parallel(fns, function(err, res) {
|
|
|
|
var okcount = 0
|
2015-03-28 19:25:53 +01:00
|
|
|
var failcount = 0
|
|
|
|
|
|
|
|
assert.equal(err, null)
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
res.forEach(function(arr) {
|
|
|
|
var resp = arr[0]
|
2015-03-28 19:25:53 +01:00
|
|
|
var body = arr[1]
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
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
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
callback()
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
})
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('uploading 10 diff versions', function (callback) {
|
2014-11-12 12:14:37 +01:00
|
|
|
var fns = []
|
|
|
|
for (var i=0; i<10; i++) {
|
|
|
|
;(function(i) {
|
|
|
|
fns.push(function(cb_) {
|
2015-04-11 19:11:04 +02:00
|
|
|
var _res
|
|
|
|
server.put_version('race', '0.1.'+String(i), require('./lib/package')('race'))
|
|
|
|
.response(function (res) { _res = res })
|
|
|
|
.then(function (body) {
|
|
|
|
cb_(null, [ _res, body ])
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
})(i)
|
|
|
|
}
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
async.parallel(fns, function(err, res) {
|
|
|
|
var okcount = 0
|
2015-03-28 19:25:53 +01:00
|
|
|
var failcount = 0
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2015-03-28 19:25:53 +01:00
|
|
|
assert.equal(err, null)
|
2014-11-12 12:14:37 +01:00
|
|
|
res.forEach(function(arr) {
|
|
|
|
var resp = arr[0]
|
2015-03-28 19:25:53 +01:00
|
|
|
var body = arr[1]
|
2014-11-12 12:14:37 +01:00
|
|
|
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)
|
2015-04-11 19:11:04 +02:00
|
|
|
assert.notEqual(okcount, 1)
|
2014-11-12 12:14:37 +01:00
|
|
|
_oksum += okcount
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
callback()
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
})
|
2013-12-19 16:11:54 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
after('downloading package', function () {
|
|
|
|
return server.get_package('race')
|
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
|
|
|
assert.equal(Object.keys(body.versions).length, _oksum)
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
})
|
2013-12-19 16:11:54 +01:00
|
|
|
}
|
|
|
|
|