From ee16b06b3a6f6900ab80172db109b5d482f583c8 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 13 Dec 2013 18:00:46 +0400 Subject: [PATCH] style fix --- test/basic.js | 136 ++++++++++++++++++++++++------------------------ test/config.js | 14 ++--- test/mirror.js | 96 +++++++++++++++++----------------- test/startup.js | 54 +++++++++---------- 4 files changed, 150 insertions(+), 150 deletions(-) diff --git a/test/basic.js b/test/basic.js index 805797436..956590482 100644 --- a/test/basic.js +++ b/test/basic.js @@ -8,113 +8,113 @@ var assert = require('assert') ex['trying to fetch non-existent package'] = function(cb) { server.get_package('testpkg', function(res, body) { // shouldn't exist yet - assert.equal(res.statusCode, 404); - assert(~body.error.indexOf('no such package')); - cb(); - }); -}; + assert.equal(res.statusCode, 404) + assert(~body.error.indexOf('no such package')) + cb() + }) +} ex['creating new package'] = function(cb) { server.put_package('testpkg', require('./lib/package')('testpkg'), function(res, body) { - assert.equal(res.statusCode, 201); - assert(~body.ok.indexOf('created new package')); - cb(); - }); -}; + assert.equal(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.equal(res.statusCode, 404); - assert(~body.error.indexOf('no such file')); - cb(); - }); -}; + assert.equal(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(); - }); -}; + cb() + }) +} ex['uploading new tarball'] = function(cb) { server.put_tarball('testpkg', 'blahblah', readfile('fixtures/binary'), function(res, body) { - assert.equal(res.statusCode, 201); - assert(body.ok); - cb(); - }); -}; + assert.equal(res.statusCode, 201) + assert(body.ok) + cb() + }) +} ex['doubleerr test'] = function(cb) { server.put_tarball('testfwd2', 'blahblah', readfile('fixtures/binary'), function(res, body) { - assert.equal(res.statusCode, 404); - assert(body.error); - cb(); - }); -}; + assert.equal(res.statusCode, 404) + assert(body.error) + 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(); - }); -}; + assert.equal(res.statusCode, 200) + assert.deepEqual(body, readfile('fixtures/binary').toString('utf8')) + cb() + }) +} ex['uploading new package version for bad pkg'] = function(cb) { server.put_version('testpxg', '0.0.1', require('./lib/package')('testpxg'), function(res, body) { - assert.equal(res.statusCode, 404); - assert(~body.error.indexOf('no such package')); - cb(); - }); -}; + assert.equal(res.statusCode, 404) + assert(~body.error.indexOf('no such package')) + cb() + }) +} ex['uploading new package version (bad sha)'] = function(cb) { var pkg = require('./lib/package')('testpkg') pkg.dist.shasum = crypto.createHash('sha1').update('fake').digest('hex') server.put_version('testpkg', '0.0.1', pkg, function(res, body) { - assert.equal(res.statusCode, 400); - assert(~body.error.indexOf('shasum error')); - cb(); - }); -}; + assert.equal(res.statusCode, 400) + assert(~body.error.indexOf('shasum error')) + cb() + }) +} ex['uploading new package version'] = function(cb) { var pkg = require('./lib/package')('testpkg') pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex') server.put_version('testpkg', '0.0.1', pkg, function(res, body) { - assert.equal(res.statusCode, 201); - assert(~body.ok.indexOf('published')); - cb(); - }); -}; + assert.equal(res.statusCode, 201) + assert(~body.ok.indexOf('published')) + cb() + }) +} ex['downloading newly created package'] = function(cb) { server.get_package('testpkg', function(res, body) { - assert.equal(res.statusCode, 200); - 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'}); - cb(); - }); -}; + assert.equal(res.statusCode, 200) + 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'}) + cb() + }) +} ex['downloading package via server2'] = function(cb) { server2.get_package('testpkg', function(res, body) { - assert.equal(res.statusCode, 200); - 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'}); - cb(); - }); -}; + assert.equal(res.statusCode, 200) + 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'}) + cb() + }) +} ex['publishing package / bad ro uplink'] = function(cb) { server.put_package('baduplink', require('./lib/package')('baduplink'), function(res, body) { - assert.equal(res.statusCode, 503); - assert(~body.error.indexOf('one of the uplinks is down, refuse to publish')); - cb(); - }); + assert.equal(res.statusCode, 503) + assert(~body.error.indexOf('one of the uplinks is down, refuse to publish')) + cb() + }) } diff --git a/test/config.js b/test/config.js index 31a02f0d1..42cee09af 100644 --- a/test/config.js +++ b/test/config.js @@ -1,13 +1,13 @@ -var assert = require('assert'); -var ex = module.exports; +var assert = require('assert') + , ex = module.exports ex['trying to fetch non-existent package'] = function(cb) { - var f = fork('../bin/sinopia', ['-c', './config/log-1.yaml'], {silent: true}); + var f = fork('../bin/sinopia', ['-c', './config/log-1.yaml'], {silent: true}) f.on('message', function(msg) { if ('sinopia_started' in msg) { - f.kill(); - cb(); + f.kill() + cb() } - }); -}; + }) +} diff --git a/test/mirror.js b/test/mirror.js index a7caab0b6..a53ebb63f 100644 --- a/test/mirror.js +++ b/test/mirror.js @@ -1,75 +1,75 @@ -var assert = require('assert'); -var readfile = require('fs').readFileSync; -var ex = module.exports; -var server = process.server; -var server2 = process.server2; +var assert = require('assert') + , readfile = require('fs').readFileSync + , ex = module.exports + , server = process.server + , server2 = process.server2 ex['testing anti-loop'] = function(cb) { server2.get_package('testloop', function(res, body) { - assert.equal(res.statusCode, 404); - assert(~body.error.indexOf('no such package')); - cb(); - }); -}; + assert.equal(res.statusCode, 404) + assert(~body.error.indexOf('no such package')) + cb() + }) +} ['fwd', /*'loop'*/].forEach(function(pkg) { - var prefix = pkg+': '; - pkg = 'test'+pkg; + var prefix = pkg + ': ' + pkg = 'test' + pkg ex[prefix+'creating new package'] = function(cb) { server.put_package(pkg, require('./lib/package')(pkg), function(res, body) { - assert.equal(res.statusCode, 201); - assert(~body.ok.indexOf('created new package')); - cb(); - }); - }; + assert.equal(res.statusCode, 201) + assert(~body.ok.indexOf('created new package')) + cb() + }) + } ex[prefix+'uploading new package version'] = function(cb) { server.put_version(pkg, '0.1.1', require('./lib/package')(pkg), function(res, body) { - assert.equal(res.statusCode, 201); - assert(~body.ok.indexOf('published')); - cb(); - }); - }; + assert.equal(res.statusCode, 201) + assert(~body.ok.indexOf('published')) + cb() + }) + } ex[prefix+'downloading package via server2'] = function(cb) { server2.get_package(pkg, function(res, body) { - assert.equal(res.statusCode, 200); - assert.equal(body.name, pkg); - assert.equal(body.versions['0.1.1'].name, pkg); - assert.equal(body.versions['0.1.1'].dist.tarball, 'http://localhost:55552/'+pkg+'/-/blahblah'); - cb(); - }); - }; + assert.equal(res.statusCode, 200) + assert.equal(body.name, pkg) + assert.equal(body.versions['0.1.1'].name, pkg) + assert.equal(body.versions['0.1.1'].dist.tarball, 'http://localhost:55552/'+pkg+'/-/blahblah') + cb() + }) + } ex[prefix+'uploading incomplete tarball'] = function(cb) { server.put_tarball_incomplete(pkg, pkg+'.bad', readfile('fixtures/binary'), 3000, function(res, body) { - cb(); - }); - }; + cb() + }) + } ex[prefix+'uploading new tarball'] = function(cb) { server.put_tarball(pkg, pkg+'.file', readfile('fixtures/binary'), function(res, body) { - assert.equal(res.statusCode, 201); - assert(body.ok); - cb(); - }); - }; + assert.equal(res.statusCode, 201) + assert(body.ok) + cb() + }) + } ex[prefix+'downloading tarball from server1'] = function(cb) { server.get_tarball(pkg, pkg+'.file', function(res, body) { - assert.equal(res.statusCode, 200); - assert.deepEqual(body, readfile('fixtures/binary').toString('utf8')); - cb(); - }); - }; + assert.equal(res.statusCode, 200) + assert.deepEqual(body, readfile('fixtures/binary').toString('utf8')) + cb() + }) + } ex[prefix+'downloading tarball from server2'] = function(cb) { server2.get_tarball(pkg, pkg+'.file', function(res, body) { - assert.equal(res.statusCode, 200); - assert.deepEqual(body, readfile('fixtures/binary').toString('utf8')); - cb(); - }); - }; -}); + assert.equal(res.statusCode, 200) + assert.deepEqual(body, readfile('fixtures/binary').toString('utf8')) + cb() + }) + } +}) diff --git a/test/startup.js b/test/startup.js index eb5d73d08..2abeefe9f 100644 --- a/test/startup.js +++ b/test/startup.js @@ -1,42 +1,42 @@ -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; +var rimraf = require('rimraf') + , fork = require('child_process').fork + , assert = require('assert') + , readfile = require('fs').readFileSync + , ex = module.exports + , server = process.server + , server2 = process.server2 + , forks = process.forks ex['starting servers'] = function(cb) { - var count = 0; + var count = 0 function start(dir, conf) { - count++; + count++ rimraf(dir, function() { var f = fork('../bin/sinopia' , ['-c', conf] , {silent: true} - ); - forks.push(f); + ) + forks.push(f) f.on('message', function(msg) { if ('sinopia_started' in msg) { - if (!--count) cb(); + if (!--count) cb() } - }); - }); - }; + }) + }) + } - start('./test-storage', './config-1.yaml', cb); - start('./test-storage2', './config-2.yaml', cb); -}; + start('./test-storage', './config-1.yaml', cb) + start('./test-storage2', './config-2.yaml', cb) +} ex['authentication to servers'] = function(cb) { - var count = 0; + var count = 0 [server, server2].forEach(function(server) { - count++; + count++ server.auth('test', 'test', function(res, body) { - assert.equal(res.statusCode, 201); - assert.notEqual(body.ok.indexOf('"test"'), -1); - if (!--count) cb(); - }); - }); -}; + assert.equal(res.statusCode, 201) + assert.notEqual(body.ok.indexOf('"test"'), -1) + if (!--count) cb() + }) + }) +}