2013-12-19 16:11:54 +01:00
|
|
|
require('./lib/startup')
|
|
|
|
|
|
|
|
var assert = require('assert')
|
2014-11-12 12:14:37 +01:00
|
|
|
var crypto = require('crypto')
|
2013-12-19 16:11:54 +01:00
|
|
|
|
|
|
|
function readfile(x) {
|
2014-11-12 12:14:37 +01:00
|
|
|
return require('fs').readFileSync(__dirname + '/' + x)
|
2013-12-19 16:11:54 +01:00
|
|
|
}
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
module.exports = function () {
|
2014-11-12 12:14:37 +01:00
|
|
|
var server = process.server
|
|
|
|
var server2 = process.server2
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('trying to fetch non-existent package', function () {
|
|
|
|
return server.get_package('testpkg').status(404).body_error(/no such package/)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
describe('testpkg', function () {
|
|
|
|
before(function () {
|
|
|
|
return server.add_package('testpkg')
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('creating new package', function (){/* test for before() */})
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('downloading non-existent tarball', function () {
|
|
|
|
return server.get_tarball('testpkg', 'blahblah').status(404).body_error(/no such file/)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('uploading incomplete tarball', function () {
|
|
|
|
return server.put_tarball_incomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
describe('tarball', function () {
|
|
|
|
before(function () {
|
|
|
|
return server.put_tarball('testpkg', 'blahblah', readfile('fixtures/binary'))
|
|
|
|
.status(201)
|
|
|
|
.body_ok(/.*/)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('uploading new tarball', function (){/* test for before() */})
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('downloading newly created tarball', function () {
|
|
|
|
return server.get_tarball('testpkg', 'blahblah')
|
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
|
|
|
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'))
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('uploading new package version (bad sha)', function () {
|
2014-11-12 12:14:37 +01:00
|
|
|
var pkg = require('./lib/package')('testpkg')
|
|
|
|
pkg.dist.shasum = crypto.createHash('sha1').update('fake').digest('hex')
|
2015-04-11 19:11:04 +02:00
|
|
|
|
|
|
|
return server.put_version('testpkg', '0.0.1', pkg)
|
|
|
|
.status(400)
|
|
|
|
.body_error(/shasum error/)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
describe('version', function () {
|
|
|
|
before(function () {
|
2014-11-12 12:14:37 +01:00
|
|
|
var pkg = require('./lib/package')('testpkg')
|
|
|
|
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex')
|
2015-04-11 19:11:04 +02:00
|
|
|
return server.put_version('testpkg', '0.0.1', pkg)
|
|
|
|
.status(201)
|
|
|
|
.body_ok(/published/)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('uploading new package version', function (){/* test for before() */})
|
|
|
|
|
|
|
|
it('downloading newly created package', function () {
|
|
|
|
return server.get_package('testpkg')
|
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
|
|
|
assert.equal(body.name, 'testpkg')
|
|
|
|
assert.equal(body.versions['0.0.1'].name, 'testpkg')
|
|
|
|
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/testpkg/-/blahblah')
|
|
|
|
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'})
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('downloading package via server2', function () {
|
|
|
|
return server2.get_package('testpkg')
|
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
|
|
|
assert.equal(body.name, 'testpkg')
|
|
|
|
assert.equal(body.versions['0.0.1'].name, 'testpkg')
|
|
|
|
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah')
|
|
|
|
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'})
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('uploading new package version for bad pkg', function () {
|
|
|
|
return server.put_version('testpxg', '0.0.1', require('./lib/package')('testpxg'))
|
|
|
|
.status(404)
|
|
|
|
.body_error(/no such package/)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('doubleerr test', function () {
|
|
|
|
return server.put_tarball('testfwd2', 'blahblah', readfile('fixtures/binary'))
|
|
|
|
.status(404)
|
|
|
|
.body_error(/no such/)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('publishing package / bad ro uplink', function () {
|
|
|
|
return server.put_package('baduplink', require('./lib/package')('baduplink'))
|
|
|
|
.status(503)
|
|
|
|
.body_error(/one of the uplinks is down, refuse to publish/)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2014-12-05 02:53:37 +01:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('who am I?', function () {
|
|
|
|
return server.whoami().then(function (username) {
|
2015-04-11 15:09:19 +02:00
|
|
|
assert.equal(username, 'test')
|
2014-12-05 02:53:37 +01:00
|
|
|
})
|
|
|
|
})
|
2013-12-19 16:11:54 +01:00
|
|
|
}
|
|
|
|
|