blob: dc3ff884b672b95c107f7c028a44ca53f2b4999e [file] [log] [blame]
Ali Ghassemifcab3c32014-09-12 14:24:12 -07001var test = require('prova');
Ali Ghassemia8b15482014-10-20 12:47:01 -07002var mercury = require('mercury');
Ali Ghassemifcab3c32014-09-12 14:24:12 -07003var _ = require('lodash');
4var proxyquire = require('proxyquireify')(require);
5var mockLRUCache = require('./mocks/lru-cache');
Ali Ghassemic62063c2015-03-03 11:28:45 -08006var ItemTypes = require('../../../../src/services/namespace/item-types');
Ali Ghassemifcab3c32014-09-12 14:24:12 -07007
Ali Ghassemia35f0422014-09-26 09:04:04 -07008// @noCallThru ensures this completely overrdies the original config
9// instead of inheriting the properties that are not defined here from
10// the original dependency
Ali Ghassemi96317592015-03-10 15:08:38 -070011var vanadiumConfigForTest = {
Ali Ghassemia35f0422014-09-26 09:04:04 -070012 '@noCallThru': true
Ali Ghassemifcab3c32014-09-12 14:24:12 -070013};
14
Nicolas LaCasse8d22fb22015-01-22 17:26:31 -080015// The NAMESPACE_ROOT environment variable is set by servicerunner in the "make
16// test" target. That environment variable is picked up by the "envify" prova
17// transform and used to set process.env.NAMESPACE_ROOT.
18var globalRoot = process.env.NAMESPACE_ROOT;
19
Ali Ghassemifcab3c32014-09-12 14:24:12 -070020// Require namespaceService but using test specific mocks and configs
21var namespaceService =
22 proxyquire('../../../../src/services/namespace/service.js', {
Ali Ghassemi96317592015-03-10 15:08:38 -070023 '../../vanadium-config': vanadiumConfigForTest,
Ali Ghassemifcab3c32014-09-12 14:24:12 -070024 'lru-cache': function() {
25 return mockLRUCache;
26 }
27 });
28
Ali Ghassemifcab3c32014-09-12 14:24:12 -070029test('getChildren of default namespace root', function(t) {
Ali Ghassemibbb20532014-09-22 15:05:58 -070030 namespaceService.getChildren().
31 then(function assertResult(result) {
Ali Ghassemi11256942014-10-08 15:14:49 -070032 assertIsImmutable(t, result);
Ali Ghassemi9c5cc192014-11-19 18:31:05 -080033 // Wait until we finish, we expect 2 top level items: cottage, house
34 result.events.on('end', function validate() {
Ali Ghassemi2a60a252014-11-13 09:00:23 -080035 mercury.watch(result, function(children) {
Ali Ghassemi01811a32014-11-04 13:58:34 -080036 assertCottage(children[0]);
37 assertHouse(children[1]);
Ali Ghassemid94e91c2014-10-01 11:22:46 -070038 t.end();
Ali Ghassemi2a60a252014-11-13 09:00:23 -080039 });
Ali Ghassemi9c5cc192014-11-19 18:31:05 -080040 });
Ali Ghassemi65ee3262015-02-23 11:36:59 -080041 result.events.on('globError', function(error) {
42 t.notOk(error, 'did not expect any globs errors');
43 t.end();
44 });
Ali Ghassemid94e91c2014-10-01 11:22:46 -070045 }).catch(t.end);
Ali Ghassemifcab3c32014-09-12 14:24:12 -070046
Ali Ghassemif2540c92014-10-01 09:00:15 -070047 function assertCottage(item) {
Ali Ghassemi43064312014-10-14 17:24:32 -070048 assertServer(t, item, {
49 name: 'cottage',
50 objectName: 'cottage',
51 isGlobbable: true,
52 type: 'mounttable'
53 });
Ali Ghassemifcab3c32014-09-12 14:24:12 -070054 }
55
56 function assertHouse(item) {
Ali Ghassemi43064312014-10-14 17:24:32 -070057 assertServer(t, item, {
58 name: 'house',
59 objectName: 'house',
60 isGlobbable: true,
61 type: 'mounttable'
62 });
Ali Ghassemifcab3c32014-09-12 14:24:12 -070063 }
64});
65
66test('getChildren of cottage/lawn', function(t) {
Ali Ghassemibbb20532014-09-22 15:05:58 -070067 namespaceService.getChildren('cottage/lawn').
68 then(function assertResult(result) {
Ali Ghassemi11256942014-10-08 15:14:49 -070069 assertIsImmutable(t, result);
Ali Ghassemi9c5cc192014-11-19 18:31:05 -080070 // Wait until we finish, we expect 3 items back, front and master-sprinkler
71 result.events.on('end', function validate() {
72 mercury.watch(result, function(children) {
Ali Ghassemibbb20532014-09-22 15:05:58 -070073 assertBack(children[0]);
74 assertSprinkler(children[2]);
Ali Ghassemid94e91c2014-10-01 11:22:46 -070075 t.end();
Ali Ghassemi9c5cc192014-11-19 18:31:05 -080076 });
Ali Ghassemibbb20532014-09-22 15:05:58 -070077 });
Ali Ghassemi65ee3262015-02-23 11:36:59 -080078 result.events.on('globError', function(error) {
79 t.notOk(error, 'did not expect any globs errors');
80 t.end();
81 });
Ali Ghassemibbb20532014-09-22 15:05:58 -070082 }).catch(t.end);
Ali Ghassemifcab3c32014-09-12 14:24:12 -070083
84 function assertSprinkler(item) {
Ali Ghassemi43064312014-10-14 17:24:32 -070085 assertServer(t, item, {
86 name: 'master-sprinkler',
87 objectName: 'cottage/lawn/master-sprinkler',
88 isGlobbable: false,
89 type: 'unknown'
90 });
Ali Ghassemifcab3c32014-09-12 14:24:12 -070091 }
92
93 function assertBack(item) {
Wm Leleraffbbd72015-03-18 22:03:09 -070094 assertSubtableName(t, item, {
Ali Ghassemi43064312014-10-14 17:24:32 -070095 name: 'back',
96 objectName: 'cottage/lawn/back'
97 });
Ali Ghassemifcab3c32014-09-12 14:24:12 -070098 }
99});
100
Nicolas LaCasse8d22fb22015-01-22 17:26:31 -0800101test('getChildren of rooted ' + globalRoot + '/house/kitchen', function(t) {
102 namespaceService.getChildren(globalRoot + '/house/kitchen').
Ali Ghassemibbb20532014-09-22 15:05:58 -0700103 then(function assertResult(result) {
Ali Ghassemi11256942014-10-08 15:14:49 -0700104 assertIsImmutable(t, result);
Ali Ghassemi9c5cc192014-11-19 18:31:05 -0800105 // Wait until we finish, we expect 2 items, lights and smoke-detector
106 result.events.on('end', function validate() {
107 mercury.watch(result, function(children) {
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700108 assertLightSwitch(children[0]);
109 assertSmokeDetector(children[1]);
Ali Ghassemibbb20532014-09-22 15:05:58 -0700110 t.end();
Ali Ghassemi9c5cc192014-11-19 18:31:05 -0800111 });
Ali Ghassemibbb20532014-09-22 15:05:58 -0700112 });
Ali Ghassemi65ee3262015-02-23 11:36:59 -0800113 result.events.on('globError', function(error) {
114 t.notOk(error, 'did not expect any globs errors');
115 t.end();
116 });
Ali Ghassemibbb20532014-09-22 15:05:58 -0700117 }).catch(t.end);
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700118
Alex Fandrianto4204a882014-09-19 13:34:32 -0700119 function assertLightSwitch(item) {
Ali Ghassemi43064312014-10-14 17:24:32 -0700120 assertServer(t, item, {
121 name: 'lights',
Nicolas LaCasse8d22fb22015-01-22 17:26:31 -0800122 objectName: globalRoot + '/house/kitchen/lights',
Ali Ghassemi43064312014-10-14 17:24:32 -0700123 isGlobbable: false,
124 type: 'unknown'
125 });
Alex Fandrianto4204a882014-09-19 13:34:32 -0700126 }
127
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700128 function assertSmokeDetector(item) {
Ali Ghassemi43064312014-10-14 17:24:32 -0700129 assertServer(t, item, {
130 name: 'smoke-detector',
Nicolas LaCasse8d22fb22015-01-22 17:26:31 -0800131 objectName: globalRoot + '/house/kitchen/smoke-detector',
132 isGlobbable: false,
133 type: 'unknown'
134 });
135 }
136});
137
138// The HOUSE_MOUNTTABLE environment variable is set by run-tests.sh. That
139// environment variable is picked up by the "envify" prova transform and used to
140// set process.env.HOUSE_MOUNTTABLE.
141var hostPortRoot = process.env.HOUSE_MOUNTTABLE;
142
143test('getChildren of rooted ' + hostPortRoot + '/kitchen', function(t) {
144 namespaceService.getChildren(hostPortRoot + '/kitchen').
145 then(function assertResult(result) {
146 assertIsImmutable(t, result);
147 // Wait until we finish, we expect 2 items, lights and smoke-detector
148 result.events.on('end', function validate() {
149 mercury.watch(result, function(children) {
Nicolas LaCasse8d22fb22015-01-22 17:26:31 -0800150 assertLightSwitch(children[0]);
151 assertSmokeDetector(children[1]);
152 t.end();
153 });
154 });
Ali Ghassemi65ee3262015-02-23 11:36:59 -0800155 result.events.on('globError', function(error) {
156 t.notOk(error, 'did not expect any globs errors');
157 t.end();
158 });
Nicolas LaCasse8d22fb22015-01-22 17:26:31 -0800159 }).catch(t.end);
160
161 function assertLightSwitch(item) {
162 assertServer(t, item, {
163 name: 'lights',
164 objectName: hostPortRoot + '/kitchen/lights',
165 isGlobbable: false,
166 type: 'unknown'
167 });
168 }
169
170 function assertSmokeDetector(item) {
171 assertServer(t, item, {
172 name: 'smoke-detector',
173 objectName: hostPortRoot + '/kitchen/smoke-detector',
Ali Ghassemi43064312014-10-14 17:24:32 -0700174 isGlobbable: false,
175 type: 'unknown'
176 });
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700177 }
178});
179
Ali Ghassemic62063c2015-03-03 11:28:45 -0800180test('getChildren of' + globalRoot + '/house/master-bedroom/personal' +
181 ' - all inaccessible nodes',
182 function(t) {
183 namespaceService.getChildren(globalRoot + '/house/master-bedroom/personal').
184 then(function assertResult(result) {
185 assertIsImmutable(t, result);
Ali Ghassemi96317592015-03-10 15:08:38 -0700186 // Wait until we finish, we expect inaccessible toothbrush and hairbrush
Ali Ghassemic62063c2015-03-03 11:28:45 -0800187 result.events.on('end', function validate() {
188 mercury.watch(result, function(children) {
Ali Ghassemi96317592015-03-10 15:08:38 -0700189 children.sort();
190
191 var hairbrush = children[0];
192 assertMountedName(t, hairbrush, 'hairbrush');
193 assertIsInaccessible(t, hairbrush);
194 assertIsNotGlobbable(t, hairbrush);
195
196 var toothbrush = children[1];
Ali Ghassemic62063c2015-03-03 11:28:45 -0800197 assertMountedName(t, toothbrush, 'toothbrush');
198 assertIsInaccessible(t, toothbrush);
199 assertIsNotGlobbable(t, toothbrush);
Ali Ghassemi96317592015-03-10 15:08:38 -0700200
Ali Ghassemic62063c2015-03-03 11:28:45 -0800201 t.end();
202 });
203 });
204 result.events.on('globError', function(error) {
205 t.notOk(error, 'did not expect any globs errors');
206 t.end();
207 });
208 }).catch(t.end);
209 });
210
Ali Ghassemia7b255a2014-11-26 13:06:56 -0800211test('getChildren of non-existing mounttable', function(t) {
Ali Ghassemia8b15482014-10-20 12:47:01 -0700212 // TODO(aghassemi) why does namespace library return empty results instead of
213 // error when globbing rooted names that don't exist?
Ali Ghassemibbb20532014-09-22 15:05:58 -0700214 namespaceService.getChildren('/DoesNotExist:666/What/Ever').
Ali Ghassemia8b15482014-10-20 12:47:01 -0700215 then(function assertResult(result) {
Ali Ghassemi9c5cc192014-11-19 18:31:05 -0800216 result.events.on('end', function validate() {
217 // Expect empty results
218 mercury.watch(result, function(children) {
219 t.deepEqual(children, []);
220 t.end();
221 });
Ali Ghassemia8b15482014-10-20 12:47:01 -0700222 });
Ali Ghassemi65ee3262015-02-23 11:36:59 -0800223 result.events.on('globError', function(error) {
224 // we do actually expect a glob error in this case
Ali Ghassemi218fa082014-12-01 17:00:38 -0800225 t.ok(error);
226 });
Ali Ghassemia8b15482014-10-20 12:47:01 -0700227 }).catch(t.end);
Ali Ghassemibbb20532014-09-22 15:05:58 -0700228});
229
Ali Ghassemia8b15482014-10-20 12:47:01 -0700230test('getNamespaceItem of leaf server', function(t) {
Ali Ghassemi43064312014-10-14 17:24:32 -0700231 namespaceService.getNamespaceItem('cottage/lawn/master-sprinkler').
232 then(function assertItem(itemObs) {
233 assertIsImmutable(t, itemObs);
234 var item = itemObs();
235 assertServer(t, item, {
236 name: 'master-sprinkler',
237 objectName: 'cottage/lawn/master-sprinkler',
238 isGlobbable: false,
239 type: 'unknown'
240 });
241 t.end();
242 }).catch(t.end);
243});
244
Wm Leleraffbbd72015-03-18 22:03:09 -0700245test('getNamespaceItem of subtable', function(t) {
Ali Ghassemia8b15482014-10-20 12:47:01 -0700246 namespaceService.getNamespaceItem('cottage/lawn/back').
Ali Ghassemi43064312014-10-14 17:24:32 -0700247 then(function assertItem(itemObs) {
248 assertIsImmutable(t, itemObs);
249 var item = itemObs();
Wm Leleraffbbd72015-03-18 22:03:09 -0700250 assertSubtableName(t, item, {
Ali Ghassemi43064312014-10-14 17:24:32 -0700251 name: 'back',
252 objectName: 'cottage/lawn/back'
253 });
254 t.end();
255 }).catch(t.end);
256});
257
Ali Ghassemi9c5cc192014-11-19 18:31:05 -0800258test('getNamespaceItem of mounttable leaf server', function(t) {
Ali Ghassemi43064312014-10-14 17:24:32 -0700259 namespaceService.getNamespaceItem('cottage').
260 then(function assertItem(itemObs) {
261 assertIsImmutable(t, itemObs);
262 var item = itemObs();
263 assertServer(t, item, {
264 name: 'cottage',
265 objectName: 'cottage',
266 isGlobbable: true,
267 type: 'mounttable'
268 });
269 t.end();
270 }).catch(t.end);
271});
272
Ali Ghassemia8b15482014-10-20 12:47:01 -0700273test('search uses caching', function(t) {
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700274 mockLRUCache.reset();
275
Ali Ghassemia8b15482014-10-20 12:47:01 -0700276 namespaceService.search('house', '*').
Ali Ghassemibbb20532014-09-22 15:05:58 -0700277 then(function assertNoCacheHit() {
Ali Ghassemia8b15482014-10-20 12:47:01 -0700278 t.notOk(mockLRUCache.wasCacheHit('glob|house/*'),
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700279 'first glob call is not a cache hit');
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700280
Ali Ghassemibbb20532014-09-22 15:05:58 -0700281 // Call second time, there should have been a cache hit
Ali Ghassemia8b15482014-10-20 12:47:01 -0700282 return namespaceService.search('house', '*');
Ali Ghassemi43064312014-10-14 17:24:32 -0700283 }).then(function assertCacheHit() {
Ali Ghassemia8b15482014-10-20 12:47:01 -0700284 t.ok(mockLRUCache.wasCacheHit('glob|house/*'),
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700285 'second glob call is a cache hit');
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700286
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700287 // Call glob with same name, different query
Ali Ghassemia8b15482014-10-20 12:47:01 -0700288 return namespaceService.search('house', 'foo*');
Ali Ghassemibbb20532014-09-22 15:05:58 -0700289 }).then(function assertNoCacheHit() {
Ali Ghassemia8b15482014-10-20 12:47:01 -0700290 t.notOk(mockLRUCache.wasCacheHit('glob|house/foo*'),
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700291 'third glob call with different query is not a cache hit');
292 t.end();
Ali Ghassemibbb20532014-09-22 15:05:58 -0700293 }).catch(t.end);
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700294});
295
296test('getSignature uses caching', function(t) {
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700297 mockLRUCache.reset();
298
299 namespaceService.getSignature('house/alarm').then(function() {
Ali Ghassemia8b15482014-10-20 12:47:01 -0700300 t.notOk(mockLRUCache.wasCacheHit('getSignature|house/alarm'),
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700301 'first getSignature call is not a cache hit');
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700302 // Call a second time
303 return namespaceService.getSignature('house/alarm');
304 }).then(function() {
Ali Ghassemia8b15482014-10-20 12:47:01 -0700305 t.ok(mockLRUCache.wasCacheHit('getSignature|house/alarm'),
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700306 'second getSignature call is a cache hit');
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700307 // Call a different name
308 return namespaceService.getSignature('house/kitchen/smoke-detector');
309 }).then(function() {
Ali Ghassemia8b15482014-10-20 12:47:01 -0700310 t.notOk(mockLRUCache.wasCacheHit(
311 'getSignature|house/kitchen/smoke-detector'
Ali Ghassemic62063c2015-03-03 11:28:45 -0800312 ), 'third getSignature call to a different name is not a cache hit');
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700313 t.end();
Ali Ghassemi980a3792014-10-01 13:54:03 -0700314 }).catch(t.end);
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700315});
316
317//TODO(aghassemi)
318//Tests for:
319// Recursive glob
320// Glob with some keyword
321// Ensuring array is updated when nodes get mounted and unmounted (when we use
322// watchGlob)
Alex Fandrianto81b31842014-10-14 09:54:02 -0700323
324// Make RPC: good inputs => no error
325var okRPCs = {
Ali Ghassemic62063c2015-03-03 11:28:45 -0800326 'no input': ['house/alarm', 'status', []],
327 'bool input': ['house/living-room/lights', 'flipSwitch', [true]],
328 'int input': ['cottage/smoke-detector', 'sensitivity', [2]],
329 'float input': ['house/alarm', 'delayArm', [2.5]],
Alex Fandrianto81b31842014-10-14 09:54:02 -0700330 'string input': ['cottage/pool/speaker', 'playSong', ['Happy Birthday']],
Ali Ghassemic62063c2015-03-03 11:28:45 -0800331 'slice input': ['house/master-bedroom/speaker', 'addSongs', [
332 ['A', 'B']
333 ]],
334 '2+ inputs': ['cottage/pool/heater', 'start', [70, 5]],
Alex Fandrianto81b31842014-10-14 09:54:02 -0700335};
336
337_.forOwn(okRPCs, function run(params, inputType) {
338 test(
339 'makeRPC accepts good input - ' + inputType,
340 testMakeRPCNoError.bind(null, params)
341 );
342});
343
344// Make RPC: bad inputs => error
345var badRPCs = {
Ali Ghassemi78e3bc82014-11-30 11:53:43 -0800346 //TODO(aghassemi) re-enable after #483
347 //'no service': ['mansion/smoke-detector', 'status', []],
Ali Ghassemic62063c2015-03-03 11:28:45 -0800348 'no method': ['cottage/pool/speaker', 'status', []],
349 'no input': ['cottage/lights', 'flipSwitch', null],
350 'bad type': ['cottage/lights', 'flipSwitch', ['notBool']],
351 'lacks input': ['cottage/pool/heater', 'start', [80]],
352 'invalid input': ['house/living-room/blast-speaker', 'playSong', ['notThere']]
Alex Fandrianto81b31842014-10-14 09:54:02 -0700353};
354
355_.forOwn(badRPCs, function run(params, inputType) {
356 test(
357 'makeRPC errors on bad input - ' + inputType,
358 testMakeRPCHasError.bind(null, params)
359 );
360});
361
362// Make RPC: outputs have the expected # of outputs
363test('makeRPC returns output properly', function(t) {
364 namespaceService.makeRPC('cottage/alarm', 'panic', []).then(
Alex Fandriantodb090a62015-01-16 15:05:03 -0800365 function got0Outputs(res) { // 0 outputs: has no result.
366 t.ok(res === undefined, '0 outputs => is undefined');
Alex Fandrianto81b31842014-10-14 09:54:02 -0700367
368 return namespaceService.makeRPC('house/alarm', 'status', []);
369 }
370 ).then( // 1 output: (Non-array/slice output) is not an Array.
371 function got1Output(res) {
372 t.notOk(res instanceof Array, '1 output => not an Array');
373
374 return namespaceService.makeRPC('cottage/smoke-detector', 'test', []);
375 }
376 ).then( // 1 output: Delayed return. Also not an array.
377 function got1OutputDelayed(res) {
378 t.notOk(res instanceof Array, '1 output => not an Array');
379
380 return namespaceService.makeRPC('cottage/pool/heater', 'status', []);
381 }
382 ).then( // 2 outputs: Is an Array of the correct length.
383 function got2Outputs(res) {
384 var ok = res instanceof Array && res.length === 2;
385 t.ok(ok, '2 outputs => length 2 Array');
386 t.end();
387 }
388 ).catch(t.end);
389});
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700390
391/*
392 * Test helpers
393 */
Ali Ghassemi43064312014-10-14 17:24:32 -0700394function assertServer(t, item, vals) {
395 assertMountedName(t, item, vals.name);
396 assertObjectName(t, item, vals.objectName);
397 assertIsServer(t, item);
Ali Ghassemic62063c2015-03-03 11:28:45 -0800398 assertIsAccessible(t, item);
Ali Ghassemi43064312014-10-14 17:24:32 -0700399 if (vals.isGlobbable === true) {
400 assertIsGlobbable(t, item);
Ali Ghassemic62063c2015-03-03 11:28:45 -0800401 } else if (vals.isGlobbable === false) {
Ali Ghassemi43064312014-10-14 17:24:32 -0700402 assertIsNotGlobbable(t, item);
403 }
Ali Ghassemi43064312014-10-14 17:24:32 -0700404
405 if (vals.type === 'unknown') {
406 assertUnknownServiceTypeInfo(t, item);
407 } else if (vals.type === 'mounttable') {
408 assertMounttableServiceTypeInfo(t, item);
409 } else {
410 t.fail('Unknown type: ' + vals.type);
411 }
412}
413
Wm Leleraffbbd72015-03-18 22:03:09 -0700414function assertSubtableName(t, item, vals) {
Ali Ghassemi43064312014-10-14 17:24:32 -0700415 assertMountedName(t, item, vals.name);
416 assertObjectName(t, item, vals.objectName);
Ali Ghassemi43064312014-10-14 17:24:32 -0700417 assertIsGlobbable(t, item);
Ali Ghassemic62063c2015-03-03 11:28:45 -0800418 assertIsAccessible(t, item);
Wm Leleraffbbd72015-03-18 22:03:09 -0700419 t.equal(item.itemType, ItemTypes.subtable, item.mountedName +
420 ': is subtable node');
Ali Ghassemic62063c2015-03-03 11:28:45 -0800421}
422
423function assertIsAccessible(t, item) {
424 t.notEqual(item.itemType, ItemTypes.inaccessible, item.mountedName +
425 ': is accessible');
Alex Fandriantoaffd5ac2015-03-05 15:52:16 -0800426 t.notOk(item.itemError, item.mountedName + ': has no item errors');
Ali Ghassemic62063c2015-03-03 11:28:45 -0800427}
428
429function assertIsInaccessible(t, item) {
430 t.equal(item.itemType, ItemTypes.inaccessible, item.mountedName +
431 ': is inaccessible');
432 t.ok(typeof item.itemError === 'string',
433 item.mountedName + ': has item error');
Ali Ghassemi43064312014-10-14 17:24:32 -0700434}
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700435
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700436function assertMountedName(t, item, val) {
437 t.ok(item.mountedName, item.mountedName + ': has a mounted name');
438 t.equal(item.mountedName, val, item.mountedName + ': mounted name matches');
439}
440
441function assertObjectName(t, item, val) {
442 t.ok(item.objectName, item.mountedName + ': has an object name');
Ali Ghassemi43064312014-10-14 17:24:32 -0700443 t.equal(item.objectName, val, item.mountedName + ': object name matches');
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700444}
445
446function assertIsServer(t, item) {
Ali Ghassemic62063c2015-03-03 11:28:45 -0800447 t.equal(item.itemType, ItemTypes.server, item.mountedName + ': is a server');
Ali Ghassemi43064312014-10-14 17:24:32 -0700448 t.ok(item.serverInfo, item.mountedName + ': has server info');
Alex Fandriantof87d2a02015-01-27 10:42:52 -0800449 t.ok(item.serverInfo.endpoints.length > 0, item.mountedName +
450 ': has at least 1 endpoint');
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700451}
452
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700453function assertIsGlobbable(t, item) {
Ali Ghassemi43064312014-10-14 17:24:32 -0700454 t.equal(item.isGlobbable, true, item.mountedName + ': is globbable');
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700455}
456
457function assertIsNotGlobbable(t, item) {
Ali Ghassemi43064312014-10-14 17:24:32 -0700458 t.equal(item.isGlobbable, false, item.mountedName + ': is not globbable');
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700459}
460
Ali Ghassemi11256942014-10-08 15:14:49 -0700461function assertIsImmutable(t, observable) {
462 t.ok(observable.set === undefined, 'is immutable');
463}
464
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700465/*
Alex Fandrianto4204a882014-09-19 13:34:32 -0700466 * Asserts that a ServiceTypeInfo is of predefined type of Unknown Service.
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700467 */
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700468function assertUnknownServiceTypeInfo(t, item) {
469 var typeInfo = item.serverInfo.typeInfo;
Alex Fandrianto277a1f12015-03-19 17:58:32 -0700470 t.equal(typeInfo.key, 'vanadium-unknown',
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700471 item.mountedName + ': unknown type info has the right key');
472
473 t.equal(typeInfo.typeName, 'Service',
474 item.mountedName + ': unknown type info has the type name');
475
476 t.equal(typeInfo.description, null,
477 item.mountedName + ': unknown type info does not have description');
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700478}
479
480/*
Alex Fandrianto4204a882014-09-19 13:34:32 -0700481 * Asserts that a ServiceTypeInfo is of predefined type of mounttable.
Ali Ghassemifcab3c32014-09-12 14:24:12 -0700482 */
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700483function assertMounttableServiceTypeInfo(t, item) {
Ali Ghassemic62063c2015-03-03 11:28:45 -0800484 var typeInfo = item.serverInfo.typeInfo;
Alex Fandrianto277a1f12015-03-19 17:58:32 -0700485 t.equal(typeInfo.key, 'vanadium-mounttable',
Ali Ghassemic62063c2015-03-03 11:28:45 -0800486 item.mountedName + ': mounttable type info has the right key');
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700487
Ali Ghassemic62063c2015-03-03 11:28:45 -0800488 t.equal(typeInfo.typeName, 'Mount Table',
489 item.mountedName + ': mounttable type info has the type name');
Ali Ghassemid94e91c2014-10-01 11:22:46 -0700490
Ali Ghassemic62063c2015-03-03 11:28:45 -0800491 t.ok(typeInfo.description,
492 item.mountedName + ': mounttable type info has a description');
493 }
494 /*
495 * Runs a test to ensure the makeRPC call terminates without error.
496 */
Alex Fandrianto81b31842014-10-14 09:54:02 -0700497function testMakeRPCNoError(args, t) {
498 namespaceService.makeRPC.apply(null, args).then(function(result) {
499 t.pass('completed without error');
500 t.end();
501 }).catch(function(err) {
Ali Ghassemi442851c2014-12-12 13:47:40 -0800502 t.end(err);
Alex Fandrianto81b31842014-10-14 09:54:02 -0700503 });
504}
505
506/*
507 * Runs a test to ensure the makeRPC call terminates with an error.
508 */
509function testMakeRPCHasError(args, t) {
510 namespaceService.makeRPC.apply(null, args).then(function(result) {
511 t.fail('should not have completed without error');
512 t.end();
513 }).catch(function(err) {
514 t.pass('correctly returned an error');
515 t.end();
516 });
Wm Leleraffbbd72015-03-18 22:03:09 -0700517}