From d5d2a8bdcc5bf6bd2dfd07e9b45c3053d278f411 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Mon, 16 Dec 2013 00:54:50 +0400 Subject: [PATCH] moving unit tests to separate folder --- test/dos/README.md | 1 - test/dos/get-tarball.js | 41 --------------------------------- test/start.sh | 2 +- test/{ => unit}/no_proxy.js | 4 ++-- test/{ => unit}/st_merge.js | 4 ++-- test/{ => unit}/transaction.js | 2 +- test/unit/utils.js | 42 ++++++++++++++++++++++++++++++++++ 7 files changed, 48 insertions(+), 48 deletions(-) delete mode 100644 test/dos/README.md delete mode 100755 test/dos/get-tarball.js rename test/{ => unit}/no_proxy.js (97%) rename test/{ => unit}/st_merge.js (89%) rename test/{ => unit}/transaction.js (97%) create mode 100644 test/unit/utils.js diff --git a/test/dos/README.md b/test/dos/README.md deleted file mode 100644 index bd48ce000..000000000 --- a/test/dos/README.md +++ /dev/null @@ -1 +0,0 @@ -stuff used for stress-testing, using against real servers is unadvisable diff --git a/test/dos/get-tarball.js b/test/dos/get-tarball.js deleted file mode 100755 index 356a257d6..000000000 --- a/test/dos/get-tarball.js +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env node - -var async = require('async'); -var assert = require('assert'); -var Server = require('../lib/server'); -var readfile = require('fs').readFileSync; -var binary = readfile('../fixtures/binary'); -var count = 10000; - -var server = new Server('http://localhost:55551/'); -async.series([ - function(cb) { - server.auth('test', 'test', function(res, body) { - cb(); - }); - }, - function(cb) { - server.put_package('testpkg', readfile('../fixtures/test-package.json'), function(res, body) { - cb(); - }); - }, - function(cb) { - server.put_tarball('testpkg', 'blahblah', binary, function(res, body) { - cb(); - }); - }, - function dos(cb) { - server.get_tarball('testpkg', 'blahblah', function(res, body) { - assert(res.statusCode === 200); - assert.deepEqual(body, binary.toString('utf8')); - if (count-- > 0) { - dos(cb); - } else { - cb(); - } - }); - }, -], function() { - process.exit(); -}); - diff --git a/test/start.sh b/test/start.sh index 3ebdfeca9..cbfd4f9de 100755 --- a/test/start.sh +++ b/test/start.sh @@ -4,7 +4,7 @@ CWD=$(pwd) PATH='../node_modules/.bin':$PATH TESTDIR=$(dirname $0) cd $TESTDIR -mocha -R list --ui exports ./tests.js ./no_proxy.js ./st_merge.js +mocha -R list --ui exports ./tests.js ./unit TESTRES=$? cd $CWD exit $TESTRES diff --git a/test/no_proxy.js b/test/unit/no_proxy.js similarity index 97% rename from test/no_proxy.js rename to test/unit/no_proxy.js index 775f2dc67..1bcbbb301 100644 --- a/test/no_proxy.js +++ b/test/unit/no_proxy.js @@ -1,7 +1,7 @@ var assert = require('assert') - , Storage = require('../lib/up-storage') + , Storage = require('../../lib/up-storage') -require('../lib/logger').setup() +require('../../lib/logger').setup() function setup(host, config, mainconfig) { config.url = host diff --git a/test/st_merge.js b/test/unit/st_merge.js similarity index 89% rename from test/st_merge.js rename to test/unit/st_merge.js index 6e0d4c7ce..35b78e178 100644 --- a/test/st_merge.js +++ b/test/unit/st_merge.js @@ -1,6 +1,6 @@ var assert = require('assert') - , semver_sort = require('../lib/storage')._semver_sort - , merge = require('../lib/storage')._merge_versions + , semver_sort = require('../../lib/storage')._semver_sort + , merge = require('../../lib/storage')._merge_versions //require('../lib/logger').setup() diff --git a/test/transaction.js b/test/unit/transaction.js similarity index 97% rename from test/transaction.js rename to test/unit/transaction.js index 2f58a442e..79ea1a58f 100644 --- a/test/transaction.js +++ b/test/unit/transaction.js @@ -1,4 +1,4 @@ -var transaction = require('../lib/transaction') +var transaction = require('../../lib/transaction') var assert = require('assert') function call_back(cb, value) { diff --git a/test/unit/utils.js b/test/unit/utils.js new file mode 100644 index 000000000..fcd7bd010 --- /dev/null +++ b/test/unit/utils.js @@ -0,0 +1,42 @@ +var assert = require('assert') + , validate = require('../../lib/utils').validate_name + +exports['Validate'] = { + 'good ones': function() { + assert(validate('sinopia')) + assert(validate('some.weird.package-zzz')) + }, + + 'uppercase': function() { + assert(validate('EVE')) + assert(validate('JSONStream')) + }, + + 'no package.json': function() { + assert(!validate('package.json')) + }, + + 'no path seps': function() { + assert(!validate('some/thing')) + assert(!validate('some\\thing')) + }, + + 'no hidden': function() { + assert(!validate('.bin')) + }, + + 'no reserved': function() { + assert(!validate('favicon.ico')) + assert(!validate('node_modules')) + assert(!validate('__proto__')) + }, + + 'other': function() { + assert(!validate('pkg@')) + assert(!validate('pk g')) + assert(!validate('pk\tg')) + assert(!validate('pk%20g')) + assert(!validate('pk+g')) + assert(!validate('pk:g')) + }, +}