mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
config files splitting + fwd
This commit is contained in:
parent
5dbc825892
commit
57b34a7637
7 changed files with 220 additions and 112 deletions
82
test/basic.js
Normal file
82
test/basic.js
Normal file
|
@ -0,0 +1,82 @@
|
|||
var assert = require('assert');
|
||||
var readfile = require('fs').readFileSync;
|
||||
var ex = module.exports;
|
||||
var server = process.server;
|
||||
var server2 = process.server2;
|
||||
|
||||
ex['trying to fetch non-existent package'] = function(cb) {
|
||||
server.get_package('testpkg', function(res, body) {
|
||||
// shouldn't exist yet
|
||||
assert(res.statusCode === 404);
|
||||
assert(~body.error.indexOf('no such package'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['creating new package'] = function(cb) {
|
||||
server.put_package('testpkg', readfile('fixtures/test-package.json'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(~body.ok.indexOf('created new package'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['downloading non-existent tarball'] = function(cb) {
|
||||
server.get_tarball('testpkg', 'blahblah', function(res, body) {
|
||||
assert(res.statusCode === 404);
|
||||
assert(~body.error.indexOf('no such file'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['uploading incomplete tarball'] = function(cb) {
|
||||
server.put_tarball_incomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000, function(res, body) {
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['uploading new tarball'] = function(cb) {
|
||||
server.put_tarball('testpkg', 'blahblah', readfile('fixtures/binary'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(body.ok);
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['downloading newly created tarball'] = function(cb) {
|
||||
server.get_tarball('testpkg', 'blahblah', function(res, body) {
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['uploading new package version'] = function(cb) {
|
||||
server.put_version('testpkg', '0.0.1', readfile('fixtures/test-package.json'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(~body.ok.indexOf('published'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['downloading newly created package'] = function(cb) {
|
||||
server.get_package('testpkg', function(res, body) {
|
||||
assert(res.statusCode === 200);
|
||||
assert(body.name === 'testpkg');
|
||||
assert(body.versions['0.0.1'].name === 'testpkg');
|
||||
assert(body.versions['0.0.1'].dist.tarball === 'http://localhost:55551/testpkg/-/blahblah');
|
||||
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'});
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['downloading package via server2'] = function(cb) {
|
||||
server2.get_package('testpkg', function(res, body) {
|
||||
assert(res.statusCode === 200);
|
||||
assert(body.name === 'testpkg');
|
||||
assert(body.versions['0.0.1'].name === 'testpkg');
|
||||
assert(body.versions['0.0.1'].dist.tarball === 'http://localhost:55552/testpkg/-/blahblah');
|
||||
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'});
|
||||
cb();
|
||||
});
|
||||
};
|
|
@ -4,7 +4,17 @@ users:
|
|||
test:
|
||||
password: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
||||
|
||||
uplinks:
|
||||
server2:
|
||||
url: http://localhost:55552/
|
||||
|
||||
packages:
|
||||
'testfwd':
|
||||
allow_access: all
|
||||
allow_publish: all
|
||||
proxy_access: server2
|
||||
proxy_publish: server2
|
||||
|
||||
'*':
|
||||
allow_access: test anonymous
|
||||
allow_publish: test anonymous
|
||||
|
|
|
@ -9,6 +9,10 @@ uplinks:
|
|||
url: http://localhost:55551/
|
||||
|
||||
packages:
|
||||
'testfwd':
|
||||
allow_access: all
|
||||
allow_publish: all
|
||||
|
||||
testpkg:
|
||||
allow_access: test anonymous
|
||||
allow_publish: test anonymous
|
||||
|
|
8
test/fixtures/fwd-package.json
vendored
Normal file
8
test/fixtures/fwd-package.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "testfwd",
|
||||
"version": "0.0.0",
|
||||
"dist": {
|
||||
"shasum": "fake",
|
||||
"tarball": "http://localhost:55551/testpkg/-/blahblah"
|
||||
}
|
||||
}
|
71
test/mirror.js
Normal file
71
test/mirror.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
var assert = require('assert');
|
||||
var readfile = require('fs').readFileSync;
|
||||
var ex = module.exports;
|
||||
var server = process.server;
|
||||
var server2 = process.server2;
|
||||
/*
|
||||
ex['creating new package'] = function(cb) {
|
||||
server.put_package('testfwd', readfile('fixtures/fwd-package.json'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(~body.ok.indexOf('created new package'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['uploading new package version'] = function(cb) {
|
||||
server.put_version('testfwd', '0.1.1', readfile('fixtures/fwd-package.json'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(~body.ok.indexOf('published'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['downloading package via server2'] = function(cb) {
|
||||
server2.get_package('testpkg', function(res, body) {
|
||||
assert(res.statusCode === 200);
|
||||
assert(body.name === 'testfwd');
|
||||
assert(body.versions['0.1.1'].name === 'testfwd');
|
||||
assert(body.versions['0.1.1'].dist.tarball === 'http://localhost:55552/testpkg/-/blahblah');
|
||||
cb();
|
||||
});
|
||||
};
|
||||
*/
|
||||
|
||||
ex['creating - srv1 (remove it)'] = function(cb) {
|
||||
server.put_package('testfwd', readfile('fixtures/fwd-package.json'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(~body.ok.indexOf('created new package'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['creating - srv2 (remove it)'] = function(cb) {
|
||||
server2.put_package('testfwd', readfile('fixtures/fwd-package.json'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(~body.ok.indexOf('created new package'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['uploading incomplete tarball'] = function(cb) {
|
||||
server.put_tarball_incomplete('testfwd', 'testfwd.bad', readfile('fixtures/binary'), 3000, function(res, body) {
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['uploading new tarball'] = function(cb) {
|
||||
server.put_tarball('testfwd', 'testfwd.file', readfile('fixtures/binary'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(body.ok);
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['downloading tarball from server2'] = function(cb) {
|
||||
server2.get_tarball('testfwd', 'testfwd.file', function(res, body) {
|
||||
assert(res.statusCode === 200);
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
39
test/startup.js
Normal file
39
test/startup.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
var rimraf = require('rimraf');
|
||||
var fork = require('child_process').fork;
|
||||
var assert = require('assert');
|
||||
var readfile = require('fs').readFileSync;
|
||||
var ex = module.exports;
|
||||
var server = process.server;
|
||||
var server2 = process.server2;
|
||||
var forks = process.forks;
|
||||
|
||||
ex['starting servers'] = function(cb) {
|
||||
var count = 0;
|
||||
function start(dir, conf) {
|
||||
count++;
|
||||
rimraf(dir, function() {
|
||||
var f = fork('../bin/sinopia', ['-c', conf]);;//, {silent: true});
|
||||
forks.push(f);
|
||||
f.on('message', function(msg) {
|
||||
if ('sinopia_started' in msg) {
|
||||
if (!--count) cb();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
start('./test-storage', './config-1.yaml', cb);
|
||||
start('./test-storage2', './config-2.yaml', cb);
|
||||
};
|
||||
|
||||
ex['authentication to servers'] = function(cb) {
|
||||
var count = 0;
|
||||
[server, server2].forEach(function(server) {
|
||||
count++;
|
||||
server.auth('test', 'test', function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert.notEqual(body.ok.indexOf('"test"'), -1);
|
||||
if (!--count) cb();
|
||||
});
|
||||
});
|
||||
};
|
118
test/tests.js
118
test/tests.js
|
@ -1,123 +1,17 @@
|
|||
var fs = require('fs');
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var rimraf = require('rimraf');
|
||||
var Server = require('./lib/server');
|
||||
var fork = require('child_process').fork;
|
||||
var readfile = require('fs').readFileSync;
|
||||
var forks = [];
|
||||
var ex = module.exports;
|
||||
|
||||
var server = new Server('http://localhost:55551/');
|
||||
var server2 = new Server('http://localhost:55552/');
|
||||
var forks = process.forks = [];
|
||||
process.server = new Server('http://localhost:55551/');
|
||||
process.server2 = new Server('http://localhost:55552/');
|
||||
|
||||
ex['starting servers'] = function(cb) {
|
||||
var count = 0;
|
||||
function start(dir, conf) {
|
||||
count++;
|
||||
rimraf(dir, function() {
|
||||
var f = fork('../bin/sinopia', ['-c', conf], {silent: true});
|
||||
forks.push(f);
|
||||
f.on('message', function(msg) {
|
||||
if ('sinopia_started' in msg) {
|
||||
if (!--count) cb();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
start('./test-storage', './config-1.yaml', cb);
|
||||
start('./test-storage2', './config-2.yaml', cb);
|
||||
};
|
||||
|
||||
ex['authentication to servers'] = function(cb) {
|
||||
var count = 0;
|
||||
[server, server2].forEach(function(server) {
|
||||
count++;
|
||||
server.auth('test', 'test', function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert.notEqual(body.ok.indexOf('"test"'), -1);
|
||||
if (!--count) cb();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
ex['trying to fetch non-existent package'] = function(cb) {
|
||||
server.get_package('testpkg', function(res, body) {
|
||||
// shouldn't exist yet
|
||||
assert(res.statusCode === 404);
|
||||
assert(~body.error.indexOf('no such package'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['creating new package'] = function(cb) {
|
||||
server.put_package('testpkg', readfile('fixtures/test-package.json'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(~body.ok.indexOf('created new package'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['downloading non-existent tarball'] = function(cb) {
|
||||
server.get_tarball('testpkg', 'blahblah', function(res, body) {
|
||||
assert(res.statusCode === 404);
|
||||
assert(~body.error.indexOf('no such file'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['uploading incomplete tarball'] = function(cb) {
|
||||
server.put_tarball_incomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000, function(res, body) {
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['uploading new tarball'] = function(cb) {
|
||||
server.put_tarball('testpkg', 'blahblah', readfile('fixtures/binary'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(body.ok);
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['downloading newly created tarball'] = function(cb) {
|
||||
server.get_tarball('testpkg', 'blahblah', function(res, body) {
|
||||
assert(res.statusCode === 200);
|
||||
assert.deepEqual(body, readfile('fixtures/binary').toString('utf8'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['uploading new package version'] = function(cb) {
|
||||
server.put_version('testpkg', '0.0.1', readfile('fixtures/test-package.json'), function(res, body) {
|
||||
assert(res.statusCode === 201);
|
||||
assert(~body.ok.indexOf('published'));
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['downloading newly created package'] = function(cb) {
|
||||
server.get_package('testpkg', function(res, body) {
|
||||
assert(res.statusCode === 200);
|
||||
assert(body.name === 'testpkg');
|
||||
assert(body.versions['0.0.1'].name === 'testpkg');
|
||||
assert(body.versions['0.0.1'].dist.tarball === 'http://localhost:55551/testpkg/-/blahblah');
|
||||
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'});
|
||||
cb();
|
||||
});
|
||||
};
|
||||
|
||||
ex['downloading package via server2'] = function(cb) {
|
||||
server2.get_package('testpkg', function(res, body) {
|
||||
assert(res.statusCode === 200);
|
||||
assert(body.name === 'testpkg');
|
||||
assert(body.versions['0.0.1'].name === 'testpkg');
|
||||
assert(body.versions['0.0.1'].dist.tarball === 'http://localhost:55552/testpkg/-/blahblah');
|
||||
assert.deepEqual(body['dist-tags'], {latest: '0.0.1'});
|
||||
cb();
|
||||
});
|
||||
};
|
||||
ex['Startup:'] = require('./startup');
|
||||
ex['Basic:'] = require('./basic');
|
||||
ex['Mirror:'] = require('./mirror');
|
||||
|
||||
process.on('exit', function() {
|
||||
if (forks[0]) forks[0].kill();
|
||||
|
|
Loading…
Reference in a new issue