From e2990b5d0a617fc4d6b19ccd2671569b2c0176cf Mon Sep 17 00:00:00 2001 From: Vansh Chopra <76000026+vanshavenger@users.noreply.github.com> Date: Mon, 7 Oct 2024 00:08:04 +0530 Subject: [PATCH] FIX: Delete Command with 0 Arguments (#985) --- integration_tests/commands/async/del_test.go | 7 ++++++- internal/eval/eval.go | 4 ++++ internal/eval/eval_test.go | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/integration_tests/commands/async/del_test.go b/integration_tests/commands/async/del_test.go index 4f0284523..2e31fa76d 100644 --- a/integration_tests/commands/async/del_test.go +++ b/integration_tests/commands/async/del_test.go @@ -30,6 +30,11 @@ func TestDel(t *testing.T) { commands: []string{"GET k3", "DEL k3"}, expected: []interface{}{"(nil)", int64(0)}, }, + { + name: "DEL with no keys or arguments", + commands: []string{"DEL"}, + expected: []interface{}{"ERR wrong number of arguments for 'del' command"}, + }, } for _, tc := range testCases { @@ -45,4 +50,4 @@ func TestDel(t *testing.T) { } }) } -} +} \ No newline at end of file diff --git a/internal/eval/eval.go b/internal/eval/eval.go index e71b2d59e..295201541 100644 --- a/internal/eval/eval.go +++ b/internal/eval/eval.go @@ -1640,6 +1640,10 @@ func evalTTL(args []string, store *dstore.Store) []byte { func evalDEL(args []string, store *dstore.Store) []byte { var countDeleted = 0 + if len(args) < 1 { + return diceerrors.NewErrArity("DEL") + } + for _, key := range args { if ok := store.Del(key); ok { countDeleted++ diff --git a/internal/eval/eval_test.go b/internal/eval/eval_test.go index c99455823..2486f515b 100644 --- a/internal/eval/eval_test.go +++ b/internal/eval/eval_test.go @@ -1937,12 +1937,12 @@ func testEvalDel(t *testing.T, store *dstore.Store) { "nil value": { setup: func() {}, input: nil, - output: []byte(":0\r\n"), + output: clientio.Encode(errors.New("ERR wrong number of arguments for 'del' command"), false), }, "empty array": { setup: func() {}, input: []string{}, - output: []byte(":0\r\n"), + output: clientio.Encode(errors.New("ERR wrong number of arguments for 'del' command"), false), }, "key does not exist": { setup: func() {},