2018-10-21 16:45:09 +00:00
|
|
|
import 'package:angel_http_exception/angel_http_exception.dart';
|
2018-10-21 12:29:42 +00:00
|
|
|
import 'package:angel_redis/angel_redis.dart';
|
|
|
|
import 'package:resp_client/resp_client.dart';
|
|
|
|
import 'package:resp_client/resp_commands.dart';
|
2021-06-20 12:37:20 +00:00
|
|
|
import 'package:resp_client/resp_server.dart';
|
2018-10-21 12:29:42 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2021-06-20 12:37:20 +00:00
|
|
|
void main() async {
|
|
|
|
late RespServerConnection connection;
|
|
|
|
late RedisService service;
|
2018-10-21 12:29:42 +00:00
|
|
|
|
|
|
|
setUp(() async {
|
|
|
|
connection = await connectSocket('localhost');
|
2021-06-20 12:37:20 +00:00
|
|
|
service = RedisService(RespCommandsTier2(RespClient(connection)),
|
2018-10-21 12:29:42 +00:00
|
|
|
prefix: 'angel_redis_test');
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() => connection.close());
|
|
|
|
|
2018-10-21 17:26:56 +00:00
|
|
|
test('index', () async {
|
|
|
|
// Wipe
|
|
|
|
await service.respCommands.flushDb();
|
|
|
|
await service.create({'id': '0', 'name': 'Tobe'});
|
|
|
|
await service.create({'id': '1', 'name': 'Osakwe'});
|
|
|
|
|
|
|
|
var output = await service.index();
|
|
|
|
expect(output, hasLength(2));
|
|
|
|
expect(output[1], <String, dynamic>{'id': '0', 'name': 'Tobe'});
|
|
|
|
expect(output[0], <String, dynamic>{'id': '1', 'name': 'Osakwe'});
|
|
|
|
});
|
|
|
|
|
2018-10-21 12:29:42 +00:00
|
|
|
test('create with id', () async {
|
|
|
|
var input = {'id': 'foo', 'bar': 'baz'};
|
|
|
|
var output = await service.create(input);
|
|
|
|
expect(input, output);
|
|
|
|
});
|
2018-10-21 16:29:04 +00:00
|
|
|
|
2018-10-21 16:26:53 +00:00
|
|
|
test('create without id', () async {
|
|
|
|
var input = {'bar': 'baz'};
|
2021-06-20 12:37:20 +00:00
|
|
|
var output = await (service.create(input));
|
2018-10-21 16:26:53 +00:00
|
|
|
print(output);
|
|
|
|
expect(output.keys, contains('id'));
|
|
|
|
expect(output, containsPair('bar', 'baz'));
|
|
|
|
});
|
2018-10-21 16:29:04 +00:00
|
|
|
|
|
|
|
test('read', () async {
|
2021-02-21 02:47:23 +00:00
|
|
|
var id = 'poobah${DateTime.now().millisecondsSinceEpoch}';
|
2018-10-21 16:29:04 +00:00
|
|
|
var input = await service.create({'id': id, 'bar': 'baz'});
|
|
|
|
expect(await service.read(id), input);
|
|
|
|
});
|
2018-10-21 16:31:30 +00:00
|
|
|
|
2018-10-21 17:04:21 +00:00
|
|
|
test('modify', () async {
|
2021-02-21 02:47:23 +00:00
|
|
|
var id = 'jamboree${DateTime.now().millisecondsSinceEpoch}';
|
2018-10-21 17:04:21 +00:00
|
|
|
await service.create({'id': id, 'bar': 'baz', 'yes': 'no'});
|
|
|
|
var output = await service.modify(id, {'bar': 'quux'});
|
|
|
|
expect(output, {'id': id, 'bar': 'quux', 'yes': 'no'});
|
|
|
|
expect(await service.read(id), output);
|
|
|
|
});
|
|
|
|
|
2018-10-21 16:31:30 +00:00
|
|
|
test('update', () async {
|
2021-02-21 02:47:23 +00:00
|
|
|
var id = 'hoopla${DateTime.now().millisecondsSinceEpoch}';
|
2018-10-21 16:31:30 +00:00
|
|
|
await service.create({'id': id, 'bar': 'baz'});
|
2018-10-21 17:04:21 +00:00
|
|
|
var output = await service.update(id, {'yes': 'no'});
|
|
|
|
expect(output, {'id': id, 'yes': 'no'});
|
2018-10-21 16:31:30 +00:00
|
|
|
expect(await service.read(id), output);
|
|
|
|
});
|
2018-10-21 16:41:23 +00:00
|
|
|
|
|
|
|
test('remove', () async {
|
2021-02-21 02:47:23 +00:00
|
|
|
var id = 'gelatin${DateTime.now().millisecondsSinceEpoch}';
|
2018-10-21 16:41:23 +00:00
|
|
|
var input = await service.create({'id': id, 'bar': 'baz'});
|
|
|
|
expect(await service.remove(id), input);
|
2018-10-21 16:45:09 +00:00
|
|
|
expect(await service.respCommands.exists([id]), 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('remove nonexistent', () async {
|
|
|
|
expect(() => service.remove('definitely_does_not_exist'),
|
|
|
|
throwsA(const TypeMatcher<AngelHttpException>()));
|
2018-10-21 16:41:23 +00:00
|
|
|
});
|
2018-10-21 12:29:42 +00:00
|
|
|
}
|