-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
202 lines (184 loc) · 7.64 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
var assert = require('assert');
var ns = require('./');
describe('ns', function() {
describe('normal', function() {
it('should acccept `a`', function() {
assert(ns('a').normal);
});
it('should acccept `a.b`', function() {
assert(ns('a.b').normal);
});
it('should acccept `a.b.c`', function() {
assert(ns('a.b.c').normal);
});
it('should acccept `local.oplog.$main`', function() {
assert(ns('local.oplog.$main').normal);
});
it('should acccept `local.oplog.rs`', function() {
assert(ns('local.oplog.rs').normal);
});
it('should not acccept `a.b.$c`', function() {
assert.equal(ns('a.b.$c').normal, false);
});
it('should not acccept `a.b.$.c`', function() {
assert.equal(ns('a.b.$.c').normal, false);
});
});
it('should identify oplog namespaces', function() {
assert.equal(ns('a').oplog, false);
assert.equal(ns('a.b').oplog, false);
assert(ns('local.oplog.rs').oplog);
assert.equal(ns('local.oplog.foo').oplog, false);
assert(ns('local.oplog.$main').oplog);
assert.equal(ns('local.oplog.$foo').oplog, false);
});
it('should identify special namespaces', function() {
it('should acccept `a.$.b`', function() {
assert(ns('a.$.b').special);
});
it('should acccept `a.system.foo`', function() {
assert(ns('a.system.foo').special);
});
it('should acccept `a.enxcol_.foo`', function() {
assert(ns('a.enxcol_.foo').special);
});
it('should not accept `a.foo`', function() {
assert.equal(ns('a.foo').special, false);
});
it('should not accept `a.systemfoo`', function() {
assert.equal(ns('a.systemfoo').special, false);
});
it('should not accept `a.foo.system.bar`', function() {
assert.equal(ns('a.foo.system.bar').special, false);
});
});
describe('database name validation', function() {
it('should accept `foo` as a valid database name', function() {
assert.equal(ns('foo').validDatabaseName, true);
});
it('should not accept `foo/bar` as a valid database name', function() {
assert.equal(ns('foo/bar').validDatabaseName, false);
});
it('should not accept `foo bar` as a valid database name', function() {
assert.equal(ns('foo bar').validDatabaseName, false);
});
it('should not accept `foo\\bar` as a valid database name', function() {
assert.equal(ns('foo\\bar').validDatabaseName, false);
});
it('should not accept `foo\"bar` as a valid database name', function() {
assert.equal(ns('foo\"bar').validDatabaseName, false);
});
it.skip('should not accept `foo*bar` as a valid database name', function() {
assert.equal(ns('foo*bar').validDatabaseName, false);
});
it.skip('should not accept `foo<bar` as a valid database name', function() {
assert.equal(ns('foo<bar').validDatabaseName, false);
});
it.skip('should not accept `foo>bar` as a valid database name', function() {
assert.equal(ns('foo>bar').validDatabaseName, false);
});
it.skip('should not accept `foo:bar` as a valid database name', function() {
assert.equal(ns('foo:bar').validDatabaseName, false);
});
it.skip('should not accept `foo|bar` as a valid database name', function() {
assert.equal(ns('foo|bar').validDatabaseName, false);
});
it.skip('should not accept `foo?bar` as a valid database name', function() {
assert.equal(ns('foo?bar').validDatabaseName, false);
});
});
describe('collection name validation', function() {
it('should accept `a.b` as valid', function() {
assert.equal(ns('a.b').validCollectionName, true);
});
it('should accept `a.b` as valid', function() {
assert.equal(ns('a.b').validCollectionName, true);
});
it('should accept `a.b.` as valid', function() {
assert.equal(ns('a.b.').validCollectionName, true);
});
it('should accept `a.b` as valid', function() {
assert.equal(ns('a.b').validCollectionName, true);
});
it('should accept `a.b.` as valid', function() {
assert.equal(ns('a.b.').validCollectionName, true);
});
it('should accept `a$b` as valid', function() {
assert.equal(ns('a$b').validCollectionName, false);
});
it('should not accept `a.` as valid', function() {
assert.equal(ns('a.').validCollectionName, false);
});
it('should not accept `$a` as valid', function() {
assert.equal(ns('$a').validCollectionName, false);
});
it('should not accept `` as valid', function() {
assert.equal(ns('').validCollectionName, false);
});
});
describe('database hash', function() {
it('should have the same value for `foo` and `foo`', function() {
assert.equal(ns('foo').databaseHash, ns('foo').databaseHash);
});
it('should have the same value for `foo` and `foo.a`', function() {
assert.equal(ns('foo').databaseHash, ns('foo.a').databaseHash);
});
it('should have the same value for `foo` and `foo.`', function() {
assert.equal(ns('foo').databaseHash, ns('foo.').databaseHash);
});
it('should have the same value for `` and ``', function() {
assert.equal(ns('').databaseHash, ns('').databaseHash);
});
it('should have the same value for `` and `.a`', function() {
assert.equal(ns('').databaseHash, ns('.a').databaseHash);
});
it('should have the same value for `` and `.`', function() {
assert.equal(ns('').databaseHash, ns('.').databaseHash);
});
it('should not have the same value for `foo` and `food`', function() {
assert.notEqual(ns('foo').databaseHash, ns('food').databaseHash);
});
it('should not have the same value for `foo.` and `food`', function() {
assert.notEqual(ns('foo.').databaseHash, ns('food').databaseHash);
});
it('should not have the same value for `foo.d` and `food`', function() {
assert.notEqual(ns('foo.d').databaseHash, ns('food').databaseHash);
});
});
it('should extract database names', function() {
assert.equal(ns('foo').database, ns('foo').database);
assert.equal(ns('foo').database, ns('foo.a').database);
assert.equal(ns('foo.a').database, ns('foo.a').database);
assert.equal(ns('foo.a').database, ns('foo.b').database);
assert.equal(ns('').database, ns('').database);
assert.equal(ns('').database, ns('.').database);
assert.equal(ns('').database, ns('.x').database);
assert.notEqual(ns('foo').database, ns('bar').database);
assert.notEqual(ns('foo').database, ns('food').database);
assert.notEqual(ns('foo.').database, ns('food').database);
assert.notEqual(ns('').database, ns('x').database);
assert.notEqual(ns('').database, ns('x.').database);
assert.notEqual(ns('').database, ns('x.y').database);
assert.notEqual(ns('.').database, ns('x').database);
assert.notEqual(ns('.').database, ns('x.').database);
assert.notEqual(ns('.').database, ns('x.y').database);
assert.equal('foo', ns('foo.bar').database);
assert.equal('foo', ns('foo').database);
assert.equal('foo', ns('foo.bar').database);
assert.equal('foo', ns('foo').database);
assert.equal(ns('a.b').database, 'a');
assert.equal(ns('a.b').collection, 'b');
assert.equal(ns('a.b').database, 'a');
assert.equal(ns('a.b.c').collection, 'b.c');
assert.equal(ns('abc.').collection, '');
assert.equal(ns('abc.').database, 'abc');
});
describe('sorting', function() {
it('should sort them', function() {
var names = ['admin', 'canadian-things', 'github', 'local', 'scope_stat', 'statsd', 'test'];
var expect = ['canadian-things', 'github', 'scope_stat', 'statsd', 'test', 'admin', 'local'];
ns.sort(names);
assert.deepEqual(names, expect);
});
});
});