From 942e2e05fa7b9b01820c833031a3466ae8d6e423 Mon Sep 17 00:00:00 2001 From: svkaizoku Date: Sat, 5 Oct 2024 14:24:22 +0200 Subject: [PATCH] #734 : Http Commands Error Messages Test (#900) --- .../commands/http/check_type_test.go | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 integration_tests/commands/http/check_type_test.go diff --git a/integration_tests/commands/http/check_type_test.go b/integration_tests/commands/http/check_type_test.go new file mode 100644 index 000000000..75f623a72 --- /dev/null +++ b/integration_tests/commands/http/check_type_test.go @@ -0,0 +1,121 @@ +package http + +import ( + "testing" + "time" + + "gotest.tools/v3/assert" +) + +// This file may contain test cases for checking error messages accross all commands +func TestErrorsForSetData(t *testing.T) { + exec := NewHTTPCommandExecutor() + setErrorMsg := "WRONGTYPE Operation against a key holding the wrong kind of value" + testCases := []struct { + name string + commands []HTTPCommand + expected []interface{} + delays []time.Duration + assertType []string + }{ + { + name: "GET a key holding a set", + commands: []HTTPCommand{ + {Command: "SADD", Body: map[string]interface{}{"key": "foo", "member": "bar"}}, + {Command: "GET", Body: map[string]interface{}{"key": "foo"}}, + }, + expected: []interface{}{float64(1), setErrorMsg}, + assertType: []string{"equal", "equal"}, + delays: []time.Duration{0, 0}, + }, + { + name: "GETDEL a key holding a set", + commands: []HTTPCommand{ + {Command: "SADD", Body: map[string]interface{}{"key": "foo", "member": "bar"}}, + {Command: "GETDEL", Body: map[string]interface{}{"key": "foo"}}, + }, + expected: []interface{}{float64(1), setErrorMsg}, + assertType: []string{"equal", "equal"}, + delays: []time.Duration{0, 0}, + }, + { + name: "INCR a key holding a set", + commands: []HTTPCommand{ + {Command: "SADD", Body: map[string]interface{}{"key": "foo", "member": "bar"}}, + {Command: "INCR", Body: map[string]interface{}{"key": "foo"}}, + }, + expected: []interface{}{float64(1), setErrorMsg}, + assertType: []string{"equal", "equal"}, + delays: []time.Duration{0, 0}, + }, + { + name: "DECR a key holding a set", + commands: []HTTPCommand{ + {Command: "SADD", Body: map[string]interface{}{"key": "foo", "member": "bar"}}, + {Command: "DECR", Body: map[string]interface{}{"key": "foo"}}, + }, + expected: []interface{}{float64(1), setErrorMsg}, + assertType: []string{"equal", "equal"}, + delays: []time.Duration{0, 0}, + }, + { + name: "BIT operations on a key holding a set", + commands: []HTTPCommand{ + {Command: "SADD", Body: map[string]interface{}{"key": "foo", "member": "bar"}}, + {Command: "GETBIT", Body: map[string]interface{}{"key": "foo", "offset": 1}}, + {Command: "BITCOUNT", Body: map[string]interface{}{"key": "foo"}}, + }, + expected: []interface{}{float64(1), setErrorMsg, setErrorMsg}, + assertType: []string{"equal", "equal", "equal"}, + delays: []time.Duration{0, 0, 0}, + }, + { + name: "GETEX a key holding a set", + commands: []HTTPCommand{ + {Command: "SADD", Body: map[string]interface{}{"key": "foo", "member": "bar"}}, + {Command: "GETEX", Body: map[string]interface{}{"key": "foo"}}, + }, + expected: []interface{}{float64(1), setErrorMsg}, + assertType: []string{"equal", "equal"}, + delays: []time.Duration{0, 0}, + }, + { + name: "GETSET a key holding a set", + commands: []HTTPCommand{ + {Command: "SADD", Body: map[string]interface{}{"key": "foo", "member": "bar"}}, + {Command: "GETSET", Body: map[string]interface{}{"key": "foo", "value": "bar"}}, + }, + expected: []interface{}{float64(1), setErrorMsg}, + assertType: []string{"equal", "equal"}, + delays: []time.Duration{0, 0}, + }, + { + name: "LPUSH, LPOP, RPUSH, RPOP a key holding a set", + commands: []HTTPCommand{ + {Command: "SADD", Body: map[string]interface{}{"key": "foo", "member": "bar"}}, + {Command: "LPUSH", Body: map[string]interface{}{"key": "foo", "value": "bar"}}, + {Command: "LPOP", Body: map[string]interface{}{"key": "foo"}}, + {Command: "RPUSH", Body: map[string]interface{}{"key": "foo", "value": "bar"}}, + {Command: "RPOP", Body: map[string]interface{}{"key": "foo"}}, + }, + expected: []interface{}{float64(1), setErrorMsg, setErrorMsg, setErrorMsg, setErrorMsg}, + assertType: []string{"equal", "equal", "equal", "equal", "equal"}, + delays: []time.Duration{0, 0, 0, 0, 0}, + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + exec.FireCommand(HTTPCommand{Command: "DEL", Body: map[string]interface{}{"key": "foo"}}) + for i, cmd := range tc.commands { + if tc.delays[i] > 0 { + time.Sleep(tc.delays[i]) + } + result, _ := exec.FireCommand(cmd) + switch tc.assertType[i] { + case "equal": + assert.Equal(t, tc.expected[i], result, "Value mismatch for cmd %s", cmd) + } + } + }) + } +}