Skip to content

Commit 5b2f236

Browse files
author
root
committed
add test with mocha
1 parent 3e7c6fe commit 5b2f236

File tree

4 files changed

+133
-22
lines changed

4 files changed

+133
-22
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules/
22
node_modules/*
33
.idea/
4-
.idea/*
4+
.idea/*
5+
*.snap
6+
*.xlog

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626
"msgpack": "^0.2.6",
2727
"underscore": "^1.8.3",
2828
"vow": "^0.4.9"
29+
},
30+
"devDependencies": {
31+
"mocha": "^2.2.4"
2932
}
3033
}

test/app.js

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,97 @@
11
/**
22
* Created by klond on 05.04.15.
33
*/
4+
var fs = require('fs');
5+
var assert = require('assert');
46
var TarantoolConnection = require('../lib/connection');
7+
//var cp = require('child_process');
58

6-
var conn = new TarantoolConnection({port: 33013, host: '95.85.55.64'});
7-
conn.connect()
8-
.then(function(){
9-
console.log('resolve');
10-
return conn.ping();
11-
}, function(e){
12-
console.log('reject');
13-
})
14-
.then(function(ss){
15-
console.log(ss);
16-
console.log('start request select')
17-
return conn.select(512, 0, 1, 0, 'eq', [2]);
18-
}, function(e){
19-
console.log(e);
20-
})
21-
.then(function(ff){
22-
console.log('select result');
23-
console.log(ff);
24-
}, function(e){
25-
console.log('err on select', e)
26-
})
9+
10+
describe('Tarantool Connection tests', function(){
11+
before(function(){
12+
// cp.execFile('./box.lua');
13+
});
14+
var conn;
15+
beforeEach(function(){
16+
conn = new TarantoolConnection({port: 33013});
17+
});
18+
describe('connection test', function(){
19+
it('connect', function(done){
20+
conn.connect().then(function(){
21+
done();
22+
}, function(e){ throw 'not connected'; done();});
23+
});
24+
it('auth', function(done){
25+
conn.connect().then(function(){
26+
return conn.auth('test', 'test');
27+
}, function(e){ throw 'not connected'; done();})
28+
.then(function(){
29+
done();
30+
}, function(e){ throw 'not auth'; done();})
31+
});
32+
});
33+
describe('requests', function(){
34+
var insertTuple = [50, 10, 'my key', 30];
35+
beforeEach(function(done){
36+
conn.connect().then(function(){
37+
return conn.auth('test', 'test');
38+
}, function(e){ throw 'not connected'; done();})
39+
.then(function(){
40+
done();
41+
}, function(e){ throw 'not auth'; done();})
42+
});
43+
it('replace', function(done){
44+
conn.replace(512, insertTuple)
45+
.then(function(a){
46+
assert.equal(a.length, 1);
47+
for (var i = 0; i<a[0].length; i++)
48+
assert.equal(a[0][i], insertTuple[i]);
49+
done();
50+
}, function(e){done(e);});
51+
});
52+
it('simple select', function(done){
53+
conn.select(512, 0, 1, 0, 'eq', [50])
54+
.then(function(a){
55+
assert.equal(a.length, 1);
56+
for (var i = 0; i<a[0].length; i++)
57+
assert.equal(a[0][i], insertTuple[i]);
58+
done();
59+
}, function(e){done(e);});
60+
});
61+
it('composite select', function(done){
62+
conn.select(512, 1, 1, 0, 'eq', [10, 'my key'])
63+
.then(function(a){
64+
assert.equal(a.length, 1);
65+
for (var i = 0; i<a[0].length; i++)
66+
assert.equal(a[0][i], insertTuple[i]);
67+
done();
68+
}).catch(function(e){ done(e); });
69+
});
70+
it('delete', function(done){
71+
conn.delete(512, 0, [50])
72+
.then(function(a){
73+
assert.equal(a.length, 1);
74+
for (var i = 0; i<a[0].length; i++)
75+
assert.equal(a[0][i], insertTuple[i]);
76+
done();
77+
}).catch(function(e){ done(e); });
78+
});
79+
it('insert', function(done){
80+
conn.insert(512, insertTuple)
81+
.then(function(a){
82+
assert.equal(a.length, 1);
83+
for (var i = 0; i<a[0].length; i++)
84+
assert.equal(a[0][i], insertTuple[i]);
85+
done();
86+
}, function(e){done(e);});
87+
});
88+
it('update', function(done){
89+
conn.update(512, 0, [50], [['+',3,10]])
90+
.then(function(a){
91+
assert.equal(a.length, 1);
92+
assert.equal(a[0][3], insertTuple[3]+10);
93+
done();
94+
}).catch(function(e){ done(e) });
95+
});
96+
});
97+
});

test/box.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env tarantool
2+
box.cfg{listen=33013}
3+
lp = {
4+
test = 'test',
5+
test_empty = '',
6+
test_big = '123456789012345678901234567890123456789012345678901234567890' -- '1234567890' * 6
7+
}
8+
9+
for k, v in pairs(lp) do
10+
if #box.space._user.index.name:select{k} == 0 then
11+
box.schema.user.create(k, { password = v })
12+
if k == 'test' then
13+
box.schema.user.grant('test', 'read', 'space', '_space')
14+
box.schema.user.grant('test', 'read', 'space', '_index')
15+
box.schema.user.grant('test', 'execute', 'universe')
16+
end
17+
end
18+
end
19+
20+
if not box.space.test then
21+
local test = box.schema.space.create('test')
22+
test:create_index('primary', {type = 'TREE', unique = true, parts = {1, 'NUM'}})
23+
test:create_index('secondary', {type = 'TREE', unique = false, parts = {2, 'NUM', 3, 'STR'}})
24+
box.schema.user.grant('test', 'read,write', 'space', 'test')
25+
end
26+
27+
if not box.space.msgpack then
28+
local msgpack = box.schema.space.create('msgpack')
29+
msgpack:create_index('primary', {parts = {1, 'NUM'}})
30+
box.schema.user.grant('test', 'read,write', 'space', 'msgpack')
31+
msgpack:insert{1, 'float as key', {[2.7] = {1, 2, 3}}}
32+
msgpack:insert{2, 'array as key', {[{2, 7}] = {1, 2, 3}}}
33+
msgpack:insert{3, 'array with float key as key', {[{[2.7] = 3, [7] = 7}] = {1, 2, 3}}}
34+
msgpack:insert{6, 'array with string key as key', {['megusta'] = {1, 2, 3}}}
35+
end

0 commit comments

Comments
 (0)