remove nonexistent

This commit is contained in:
Tobe O 2018-10-21 12:45:09 -04:00
parent 7137dcad5b
commit 8cff7a3f2c
3 changed files with 14 additions and 1 deletions

1
.gitignore vendored
View file

@ -11,3 +11,4 @@ pubspec.lock
# If you don't generate documentation locally you can remove this line.
doc/api/
.dart_tool
dump.rdb

View file

@ -64,6 +64,11 @@ class RedisService extends Service<String, Map<String, dynamic>> {
await client.writeArrayOfBulk(['DEL', _applyPrefix(id)]);
var result = await client.writeArrayOfBulk(['EXEC']);
var str = result.payload[0] as RespBulkString;
return json.decode(str.payload);
if (str.payload == null)
throw new AngelHttpException.notFound(
message: 'No record found for ID $id');
else
return json.decode(str.payload);
}
}

View file

@ -1,3 +1,4 @@
import 'package:angel_http_exception/angel_http_exception.dart';
import 'package:angel_redis/angel_redis.dart';
import 'package:resp_client/resp_client.dart';
import 'package:resp_client/resp_commands.dart';
@ -47,5 +48,11 @@ main() async {
var id = 'gelatin${new DateTime.now().millisecondsSinceEpoch}';
var input = await service.create({'id': id, 'bar': 'baz'});
expect(await service.remove(id), input);
expect(await service.respCommands.exists([id]), 0);
});
test('remove nonexistent', () async {
expect(() => service.remove('definitely_does_not_exist'),
throwsA(const TypeMatcher<AngelHttpException>()));
});
}