-
Notifications
You must be signed in to change notification settings - Fork 29
/
redis_connection_tests.dart
98 lines (78 loc) · 2.97 KB
/
redis_connection_tests.dart
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
library redis_connection_tests;
import 'dart:async';
import 'package:test/test.dart';
import 'package:redis_client/redis_client.dart';
import 'helper.dart';
main() {
group('Basic hack tests', () {
RedisConnection connection;
setUp(() {
return RedisConnection.connect("127.0.0.1:6379")
.then((c) {
connection = c;
return connection.send([ "FLUSHALL" ]);
});
});
tearDown(() => connection.close());
test("random stuff", () {
async(
connection.send([ "SELECT", "1" ]).receive().then((_) => expect(_.status, equals("OK")))
.then((_) => connection.send([ "SELECT", "1" ]).receiveStatus().then((status) => expect(status, equals("OK"))))
.then((_) => connection.send([ "SADD", "test", "hallo" ]).receiveInteger().then((integer) => expect(integer, equals(1))))
.then((_) => connection.send([ "SADD", "test", "hallo" ]).receiveInteger().then((integer) => expect(integer, equals(0)))) /// Should return 0 because already inserted
.then((_) {
return connection.send([ "SET", "test1", "value1" ]).receiveStatus().then((status) {
expect(status, equals("OK"));
return connection.send([ "GET", "test1" ])
.receiveBulkString()
.then((response) {
expect(response, equals("value1"));
});
});
})
.then((_) {
return connection.rawSend([ "GET".codeUnits, "test1".codeUnits ]).receiveBulkString()
.then((response) => expect(response, equals("value1")));
})
.then((_) {
return connection.sendCommand(RedisCommand.GET, [ "test1" ]).receiveBulkString()
.then((response) => expect(response, equals("value1")));
})
);
});
});
group('Connection', () {
test('should connect to a different db', () {
var connectionString = "127.0.0.1:6379/1";
async(
RedisConnection.connect(connectionString)
.then((connectionResult) {
expect(connectionResult.db, equals(1));
connectionResult.close();
})
);
});
});
group('Connection', () {
var connectionString = "127.0.0.1:6379/1";
RedisConnection connection;
setUp(() {
return RedisConnection.connect(connectionString)
.then((RedisConnection c) {
connection = c;
});
});
tearDown(() {
connection.close();
});
/* change connection ip in setUp() and requirepass in redis config file (redis.conf)
test('should connect to a database with authentication', () {
async(
connection.auth('foobared')
.then((_) => connection.sendCommand(RedisCommand.SET, [ 'key', 'value' ]).receiveStatus('OK')
.then((sendResult) => expect(sendResult, equals('OK'))))
);
});
*/
});
}