Added MessagePack tests and fixed status reply

master
Nicolas Favre-Felix 13 years ago
parent e676f59f66
commit 1cd57619fb

@ -175,11 +175,17 @@ msgpack_wrap_redis_reply(const struct cmd *cmd, struct msg_out *out, const redis
switch(r->type) {
case REDIS_REPLY_STATUS:
case REDIS_REPLY_ERROR:
msgpack_pack_array(pk, 2);
/* first element: book */
if(r->type == REDIS_REPLY_ERROR)
msgpack_pack_false(pk);
else
msgpack_pack_true(pk);
/* second element: message */
msgpack_pack_raw(pk, r->len);
msgpack_pack_raw_body(pk, r->str, r->len);
break;
case REDIS_REPLY_STRING:

@ -5,6 +5,10 @@ try:
import bson
except:
bson = None
try:
import msgpack
except:
msgpack = None
host = '127.0.0.1'
@ -177,6 +181,60 @@ class TestBSon(TestWebdis):
self.assertTrue(obj[0]['UNKNOWN'][0] == False)
self.assertTrue(isinstance(obj[0]['UNKNOWN'][1], bson.Binary))
def need_msgpack(fn):
def wrapper(self):
if msgpack:
fn(self)
return wrapper
class TestMsgPack(TestWebdis):
@need_msgpack
def test_set(self):
"success type (+OK)"
self.query('DEL/hello')
f = self.query('SET/hello/world.msg')
self.assertTrue(f.headers.getheader('Content-Type') == 'application/x-msgpack')
obj = msgpack.loads(f.read())
self.assertTrue(obj == {'SET': (True, 'OK')})
@need_msgpack
def test_get(self):
"string type"
self.query('SET/hello/world')
f = self.query('GET/hello.msg')
obj = msgpack.loads(f.read())
self.assertTrue(obj == {'GET': 'world'})
@need_msgpack
def test_incr(self):
"integer type"
self.query('DEL/hello')
f = self.query('INCR/hello.msg')
obj = msgpack.loads(f.read())
self.assertTrue(obj == {'INCR': 1})
@need_msgpack
def test_list(self):
"list type"
self.query('DEL/hello')
self.query('RPUSH/hello/abc')
self.query('RPUSH/hello/def')
f = self.query('LRANGE/hello/0/-1.msg')
obj = msgpack.loads(f.read())
self.assertTrue(obj == {'LRANGE': ('abc', 'def')})
@need_msgpack
def test_error(self):
"error return type"
f = self.query('UNKNOWN/COMMAND.msg')
obj = msgpack.loads(f.read())
self.assertTrue('UNKNOWN' in obj)
self.assertTrue(isinstance(obj, dict))
self.assertTrue(isinstance(obj['UNKNOWN'], tuple))
self.assertTrue(obj['UNKNOWN'][0] == False)
self.assertTrue(isinstance(obj['UNKNOWN'][1], str))
class TestETag(TestWebdis):
def test_etag_match(self):

Loading…
Cancel
Save