Skip to content

Commit

Permalink
DiceDB#1114: changes for issue (DiceDB#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashasv-Prajapati authored Nov 22, 2024
1 parent d78f0bf commit 56641e9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
24 changes: 24 additions & 0 deletions integration_tests/commands/http/bit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,30 @@ func TestBitCount(t *testing.T) {
},
Out: []interface{}{float64(0)},
},
{
InCmds: []HTTPCommand{
{Command: "SETBIT", Body: map[string]interface{}{"key": "mykey", "values": []interface{}{-1, 1}}},
},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []HTTPCommand{
{Command: "SETBIT", Body: map[string]interface{}{"key": "mykey", "values": []interface{}{-1, 0}}},
},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []HTTPCommand{
{Command: "SETBIT", Body: map[string]interface{}{"key": "mykey", "values": []interface{}{-10000, 1}}},
},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []HTTPCommand{
{Command: "SETBIT", Body: map[string]interface{}{"key": "mykey", "values": []interface{}{-10000, 0}}},
},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []HTTPCommand{
{Command: "GETBIT", Body: map[string]interface{}{"key": "mykey", "values": []interface{}{122}}},
Expand Down
16 changes: 16 additions & 0 deletions integration_tests/commands/resp/bit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,22 @@ func TestBitCount(t *testing.T) {
InCmds: []string{"SETBIT mykey 122 1"},
Out: []interface{}{int64(0)},
},
{
InCmds: []string{"SETBIT mykey -1 1"},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []string{"SETBIT mykey -1 0"},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []string{"SETBIT mykey -10000 1"},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []string{"SETBIT mykey -10000 0"},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []string{"GETBIT mykey 122"},
Out: []interface{}{int64(1)},
Expand Down
16 changes: 16 additions & 0 deletions integration_tests/commands/websocket/bit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,22 @@ func TestBitCount(t *testing.T) {
InCmds: []string{"SETBIT mykey 122 1"},
Out: []interface{}{float64(0)},
},
{
InCmds: []string{"SETBIT mykey -1 1"},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []string{"SETBIT mykey -1 0"},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []string{"SETBIT mykey -10000 1"},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []string{"SETBIT mykey -10000 0"},
Out: []interface{}{"ERR bit offset is not an integer or out of range"},
},
{
InCmds: []string{"GETBIT mykey 122"},
Out: []interface{}{float64(1)},
Expand Down
2 changes: 1 addition & 1 deletion internal/eval/store_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -5152,7 +5152,7 @@ func evalSETBIT(args []string, store *dstore.Store) *EvalResponse {

key := args[0]
offset, err := strconv.ParseInt(args[1], 10, 64)
if err != nil {
if err != nil || offset < 0 {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrGeneral("bit offset is not an integer or out of range"),
Expand Down

0 comments on commit 56641e9

Please sign in to comment.