From d1362552c0e1dfa3bd3d81035fe9ed1465b2e20e Mon Sep 17 00:00:00 2001 From: holys Date: Mon, 28 Jul 2014 01:58:55 +0800 Subject: [PATCH] add more error input params tests --- server/cmd_hash_test.go | 82 +++++++++++++++++++++++++++++++++++++++++ server/cmd_kv_test.go | 2 +- server/cmd_list_test.go | 58 +++++++++++++++++++++++++++++ server/const.go | 2 + 4 files changed, 143 insertions(+), 1 deletion(-) diff --git a/server/cmd_hash_test.go b/server/cmd_hash_test.go index 6b3cae3..61f513f 100644 --- a/server/cmd_hash_test.go +++ b/server/cmd_hash_test.go @@ -216,3 +216,85 @@ func TestHashGetAll(t *testing.T) { t.Fatal(n) } } + +func TestHashErrorParams(t *testing.T) { + c := getTestConn() + defer c.Close() + + if _, err := c.Do("hset", "test_hset"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hget", "test_hget"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hexists", "test_hexists"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hdel", "test_hdel"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hlen", "test_hlen", "a"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hincrby", "test_hincrby"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hmset", "test_hmset"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hmset", "test_hmset", "f1", "v1", "f2"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hmget", "test_hget"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hgetall"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hkeys"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hvals"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hclear"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hclear", "test_hclear", "a"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hmclear"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hexpire", "test_hexpire"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hexpireat", "test_hexpireat"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("httl"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("hpersist"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + +} diff --git a/server/cmd_kv_test.go b/server/cmd_kv_test.go index 56b2022..45ac11e 100644 --- a/server/cmd_kv_test.go +++ b/server/cmd_kv_test.go @@ -138,7 +138,7 @@ func TestKVIncrDecr(t *testing.T) { } } -func TestErrorParams(t *testing.T) { +func TestKVErrorParams(t *testing.T) { c := getTestConn() defer c.Close() diff --git a/server/cmd_list_test.go b/server/cmd_list_test.go index a319f7b..739020d 100644 --- a/server/cmd_list_test.go +++ b/server/cmd_list_test.go @@ -284,3 +284,61 @@ func TestPop(t *testing.T) { } } + +func TestListErrorParams(t *testing.T) { + c := getTestConn() + defer c.Close() + + if _, err := c.Do("lpush", "test_lpush"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("rpush", "test_rpush"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("lpop", "test_lpop", "a"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("rpop", "test_rpop", "a"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("llen", "test_llen", "a"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("lindex", "test_lindex"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("lrange", "test_lrange"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("lclear"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("lmclear"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("lexpire"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("lexpireat"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("lttl"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + + if _, err := c.Do("lpersist"); err == nil || err.Error() != SErrCmdParams { + t.Fatal("invalid err of %v", err) + } + +} diff --git a/server/const.go b/server/const.go index 9be33fa..f1424d2 100644 --- a/server/const.go +++ b/server/const.go @@ -9,6 +9,7 @@ var ( ErrNotFound = errors.New("command not found") ErrCmdParams = errors.New("invalid command param") ErrValue = errors.New("value is not an integer or out of range") + ErrSyntax = errors.New("syntax error") ) var ( @@ -21,4 +22,5 @@ var ( OK = "OK" SErrCmdParams = "ERR invalid command param" SErrValue = "ERR value is not an integer or out of range" + SErrSyntax = "ERR syntax error" )