-
Notifications
You must be signed in to change notification settings - Fork 19
/
test.js
62 lines (50 loc) · 1.91 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
/**
* Created by christophermina on 5/9/14.
*/
/**
* Module dependencies.
*/
var assert = require('assert')
, session = require('express-session')
, CouchbaseStore = require('./')(session);
var store = new CouchbaseStore({host:"127.0.0.1:8091", bucket:"default"});
store.on('connect', function(){
// #set()
store.set('123', { cookie: { maxAge: 2000 }, name: 'cm' }, function(err, ok){
assert.ok(!err, '#set() got an error');
assert.ok(ok, '#set() is not ok');
// #get()
store.get('123', function(err, data){
console.log("RETRIEVED: " + data.name);
assert.ok(!err, '#get() got an error');
assert.deepEqual({ cookie: { maxAge: 2000 }, name: 'cm' }, data);
// #all()
store.all(function(err, sessions) {
if (err) {
console.log("AN ERROR OCCURRED GETTING ALL SESSION: " + err);
}
if (sessions.length != 0) {
assert.deepEqual({ cookie: { maxAge: 2000 }, name: 'cm' }, sessions[0]);
}
// #set null
store.set('123', { cookie: { maxAge: 2000 }, name: 'cm' }, function(err){
if (err) {
console.log("AN ERROR OCCURRED SETTING SESSION: " + err);
}
store.destroy('123', function(err){
if (err) {
console.log("AN ERROR OCCURRED DESTROYING SESSION: " + err);
}
console.log('done');
store.client.disconnect();
process.exit(0);
});
});
});
throw new Error('Error in fn');
});
});
});
process.once('uncaughtException', function (err) {
assert.ok(err.message === 'Error in fn', '#get() catch wrong error');
});