]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/update-index.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / update-index.js
1 var common = require('../common-tap.js')
2 var test = require('tap').test
3 var npm = require('../../')
4 var mkdirp = require('mkdirp')
5 var rimraf = require('rimraf')
6 var path = require('path')
7 var mr = require('npm-registry-mock')
8
9 var updateIndex = require('../../lib/cache/update-index.js')
10
11 var PKG_DIR = path.resolve(__dirname, 'get-basic')
12 var CACHE_DIR = path.resolve(PKG_DIR, 'cache')
13
14 var server
15
16 var mocks = {
17   basic: function (mock) {
18     mock.get('/-/all').reply(200, allMock)
19   },
20   auth: function (mock) {
21     var littleBobbyTablesAuth = new Buffer('bobby:tables').toString('base64')
22     var auth = 'Basic ' + littleBobbyTablesAuth
23     mock.get('/-/all', { authorization: auth }).reply(200, allMock)
24     mock.get('/-/all').reply(401, {
25       error: 'unauthorized',
26       reason: 'You are not authorized to access this db.'
27     })
28   }
29 }
30
31 var allMock = {
32   '_updated': 1411727900 + 25,
33   'generator-frontcow': {
34       'name': 'generator-frontcow',
35       'description': 'f36b6a6123da50959741e2ce4d634f96ec668c56 This is a fake description to ensure we do not accidentally search the real npm registry or use some kind of cache',
36       'dist-tags': {
37           'latest': '0.1.19'
38       },
39       'maintainers': [
40           {
41               'name': 'bcabanes',
42               'email': 'contact@benjamincabanes.com'
43           }
44       ],
45       'homepage': 'https://github.com/bcabanes/generator-frontcow',
46       'keywords': [
47           'sass',
48           'frontend',
49           'yeoman-generator',
50           'atomic',
51           'design',
52           'sass',
53           'foundation',
54           'foundation5',
55           'atomic design',
56           'bourbon',
57           'polyfill',
58           'font awesome'
59       ],
60       'repository': {
61           'type': 'git',
62           'url': 'https://github.com/bcabanes/generator-frontcow'
63       },
64       'author': {
65           'name': 'ben',
66           'email': 'contact@benjamincabanes.com',
67           'url': 'https://github.com/bcabanes'
68       },
69       'bugs': {
70           'url': 'https://github.com/bcabanes/generator-frontcow/issues'
71       },
72       'license': 'MIT',
73       'readmeFilename': 'README.md',
74       'time': {
75           'modified': '2014-10-03T02:26:18.406Z'
76       },
77       'versions': {
78           '0.1.19': 'latest'
79       }
80   },
81   'marko': {
82       'name': 'marko',
83       'description': 'Marko is an extensible, streaming, asynchronous, high performance, HTML-based templating language that can be used in Node.js or in the browser.',
84       'dist-tags': {
85           'latest': '1.2.16'
86       },
87       'maintainers': [
88           {
89               'name': 'pnidem',
90               'email': 'pnidem@gmail.com'
91           },
92           {
93               'name': 'philidem',
94               'email': 'phillip.idem@gmail.com'
95           }
96       ],
97       'homepage': 'https://github.com/raptorjs/marko',
98       'keywords': [
99           'templating',
100           'template',
101           'async',
102           'streaming'
103       ],
104       'repository': {
105           'type': 'git',
106           'url': 'https://github.com/raptorjs/marko.git'
107       },
108       'author': {
109           'name': 'Patrick Steele-Idem',
110           'email': 'pnidem@gmail.com'
111       },
112       'bugs': {
113           'url': 'https://github.com/raptorjs/marko/issues'
114       },
115       'license': 'Apache License v2.0',
116       'readmeFilename': 'README.md',
117       'users': {
118           'pnidem': true
119       },
120       'time': {
121           'modified': '2014-10-03T02:27:31.775Z'
122       },
123       'versions': {
124           '1.2.16': 'latest'
125       }
126   }
127 }
128
129 function setup (t, mock, extra) {
130   mkdirp.sync(CACHE_DIR)
131   mr({ port: common.port, plugin: mock }, function (er, s) {
132     npm.load({ cache: CACHE_DIR, registry: common.registry }, function (err) {
133       if (extra) {
134         Object.keys(extra).forEach(function (k) {
135           npm.config.set(k, extra[k], 'user')
136         })
137       }
138       t.ifError(err, 'no error')
139       server = s
140       t.end()
141     })
142   })
143 }
144
145 function cleanup (t) {
146   server.close(function () {
147     rimraf.sync(PKG_DIR)
148
149     t.end()
150   })
151 }
152
153 test('setup basic', function (t) {
154   setup(t, mocks.basic)
155 })
156
157 test('request basic', function (t) {
158   updateIndex(0, function (er) {
159     t.ifError(er, 'no error')
160     t.end()
161   })
162 })
163
164 test('cleanup basic', cleanup)
165
166 test('setup auth', function (t) {
167   setup(t, mocks.auth)
168 })
169
170 test('request auth failure', function (t) {
171   updateIndex(0, function (er) {
172     t.equals(er.code, 'E401', 'gotta get that auth')
173     t.ok(/^unauthorized/.test(er.message), 'unauthorized message')
174     t.end()
175   })
176 })
177
178 test('cleanup auth failure', cleanup)
179
180 test('setup auth', function (t) {
181   // mimic as if alwaysAuth had been set
182   setup(t, mocks.auth, {
183     _auth: new Buffer('bobby:tables').toString('base64'),
184     'always-auth': true
185   })
186 })
187
188 test('request auth success', function (t) {
189   updateIndex(0, function (er) {
190     t.ifError(er, 'no error')
191     t.end()
192   })
193 })
194
195 test('cleanup auth', cleanup)