From 57b34a7637940fb9dc8c993eea789b2b85fd7d26 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 27 Sep 2013 16:36:10 +0400 Subject: [PATCH] config files splitting + fwd --- test/basic.js | 82 +++++++++++++++++++++++ test/config-1.yaml | 10 +++ test/config-2.yaml | 4 ++ test/fixtures/fwd-package.json | 8 +++ test/mirror.js | 71 ++++++++++++++++++++ test/startup.js | 39 +++++++++++ test/tests.js | 118 ++------------------------------- 7 files changed, 220 insertions(+), 112 deletions(-) create mode 100644 test/basic.js create mode 100644 test/fixtures/fwd-package.json create mode 100644 test/mirror.js create mode 100644 test/startup.js diff --git a/test/basic.js b/test/basic.js new file mode 100644 index 000000000..66d7552f6 --- /dev/null +++ b/test/basic.js @@ -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(); + }); +}; diff --git a/test/config-1.yaml b/test/config-1.yaml index 2efa15bdd..cd64458db 100644 --- a/test/config-1.yaml +++ b/test/config-1.yaml @@ -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 diff --git a/test/config-2.yaml b/test/config-2.yaml index ba2e609c6..fa97f1ad6 100644 --- a/test/config-2.yaml +++ b/test/config-2.yaml @@ -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 diff --git a/test/fixtures/fwd-package.json b/test/fixtures/fwd-package.json new file mode 100644 index 000000000..4f6371b61 --- /dev/null +++ b/test/fixtures/fwd-package.json @@ -0,0 +1,8 @@ +{ + "name": "testfwd", + "version": "0.0.0", + "dist": { + "shasum": "fake", + "tarball": "http://localhost:55551/testpkg/-/blahblah" + } +} diff --git a/test/mirror.js b/test/mirror.js new file mode 100644 index 000000000..94bcfb35d --- /dev/null +++ b/test/mirror.js @@ -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(); + }); +}; + diff --git a/test/startup.js b/test/startup.js new file mode 100644 index 000000000..7c0fc6e68 --- /dev/null +++ b/test/startup.js @@ -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(); + }); + }); +}; diff --git a/test/tests.js b/test/tests.js index c6e9011b4..de00b88cf 100644 --- a/test/tests.js +++ b/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();