11/**
22 * Created by klond on 05.04.15.
33 */
4+ var fs = require ( 'fs' ) ;
5+ var assert = require ( 'assert' ) ;
46var 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+ } ) ;
0 commit comments