|
1 |
| -var tap = require("tap") |
| 1 | +var test = require('tap').test |
2 | 2 |
|
3 |
| -var server = require("./lib/server.js") |
4 |
| -var common = require("./lib/common.js") |
| 3 | +var server = require('./lib/server.js') |
| 4 | +var common = require('./lib/common.js') |
| 5 | +var client = common.freshClient() |
5 | 6 |
|
6 |
| -var DEP_USER = "username" |
7 |
| -var HOST = "localhost" |
| 7 | +function nop () {} |
8 | 8 |
|
9 |
| -var nerfed = "//" + HOST + ":" + server.port + "/:" |
| 9 | +var TOKEN = 'not-bad-meaning-bad-but-bad-meaning-wombat' |
| 10 | +var AUTH = { token: TOKEN } |
| 11 | +var PARAMS = { auth: AUTH } |
| 12 | +var DEP_USER = 'username' |
| 13 | +var HOST = 'localhost' |
10 | 14 |
|
11 |
| -var configuration = {} |
12 |
| -configuration[nerfed + "username"] = DEP_USER |
13 |
| -configuration[nerfed + "_password"] = new Buffer("%1234@asdf%").toString("base64") |
14 |
| -configuration[nerfed + "email"] = "[email protected]" |
| 15 | +test('ping call contract', function (t) { |
| 16 | + t.throws(function () { |
| 17 | + client.ping(undefined, AUTH, nop) |
| 18 | + }, 'requires a URI') |
15 | 19 |
|
16 |
| -var client = common.freshClient(configuration) |
| 20 | + t.throws(function () { |
| 21 | + client.ping([], AUTH, nop) |
| 22 | + }, 'requires URI to be a string') |
17 | 23 |
|
18 |
| -tap.test("ping registry", function (t) { |
19 |
| - t.plan(3) |
20 |
| - server.expect("GET", "/-/ping?write=true", function (req, res) { |
21 |
| - t.equal(req.method, "GET") |
| 24 | + t.throws(function () { |
| 25 | + client.ping(common.registry, undefined, nop) |
| 26 | + }, 'requires params object') |
| 27 | + |
| 28 | + t.throws(function () { |
| 29 | + client.ping(common.registry, '', nop) |
| 30 | + }, 'params must be object') |
| 31 | + |
| 32 | + t.throws(function () { |
| 33 | + client.ping(common.registry, AUTH, undefined) |
| 34 | + }, 'requires callback') |
| 35 | + |
| 36 | + t.throws(function () { |
| 37 | + client.ping(common.registry, AUTH, 'callback') |
| 38 | + }, 'callback must be function') |
| 39 | + |
| 40 | + t.throws( |
| 41 | + function () { |
| 42 | + var params = {} |
| 43 | + client.ping(common.registry, params, nop) |
| 44 | + }, |
| 45 | + { name: 'AssertionError', message: 'must pass auth to ping' }, |
| 46 | + 'must pass auth to ping' |
| 47 | + ) |
| 48 | + |
| 49 | + t.end() |
| 50 | +}) |
| 51 | + |
| 52 | +test('ping', function (t) { |
| 53 | + server.expect('GET', '/-/ping?write=true', function (req, res) { |
| 54 | + t.equal(req.method, 'GET') |
22 | 55 | res.statusCode = 200
|
23 | 56 | res.json({
|
24 |
| - ok: true |
25 |
| - , host: HOST |
26 |
| - , peer: HOST |
27 |
| - , username: DEP_USER |
| 57 | + ok: true, |
| 58 | + host: HOST, |
| 59 | + peer: HOST, |
| 60 | + username: DEP_USER |
28 | 61 | })
|
29 | 62 | })
|
30 | 63 |
|
31 |
| - client.ping(common.registry, function (er, found) { |
32 |
| - t.ifError(er, "no errors") |
| 64 | + client.ping(common.registry, PARAMS, function (error, found) { |
| 65 | + t.ifError(error, 'no errors') |
33 | 66 | var wanted = {
|
34 |
| - ok: true |
35 |
| - , host: HOST |
36 |
| - , peer: HOST |
37 |
| - , username: DEP_USER |
| 67 | + ok: true, |
| 68 | + host: HOST, |
| 69 | + peer: HOST, |
| 70 | + username: DEP_USER |
38 | 71 | }
|
39 | 72 | t.same(found, wanted)
|
40 | 73 | t.end()
|
|
0 commit comments