Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1022 Command Migration: ('HEXISTS', 'HKEYS', 'HVALS') #1087

Merged
merged 37 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6680fe2
migrated hexists
tarungka Oct 10, 2024
4982f5b
update: migrated evalKEYS
tarungka Oct 13, 2024
8d333d8
update: migrated hvals
tarungka Oct 14, 2024
5b26075
update: test cases
tarungka Oct 14, 2024
e84b741
reafactor: format and remove unecessary comments
tarungka Oct 15, 2024
14f5394
fix: eval tests
tarungka Oct 15, 2024
b4b8ff0
fix: command responses
tarungka Oct 15, 2024
6d2c34c
fix: test cases
tarungka Oct 17, 2024
da1e0d3
feat: add test case
tarungka Oct 17, 2024
5d9c5d6
feat: added integration tests for hkeys, hvals and hexists
tarungka Oct 17, 2024
793597f
feat: integration tests for http and ws
tarungka Oct 17, 2024
c506ec7
fix: integration test cases
tarungka Oct 17, 2024
ea52a01
chore: lint
tarungka Oct 17, 2024
7a5f829
refactor: remove unecessary comments
tarungka Oct 17, 2024
2993fc4
feat: migrated tests for hkeys and hexists
tarungka Oct 22, 2024
c8fae0d
feat: migrated test cases for kvals
tarungka Oct 22, 2024
46ad65f
fix: integration tests hexists
tarungka Oct 22, 2024
8ee9e3f
feat: added a test case for hexists
tarungka Oct 22, 2024
2093645
chore: merge upstream master and resolve conflicts
tarungka Oct 23, 2024
670cfe2
chore: merge upstream master and resolve conflicts
tarungka Oct 23, 2024
0975c25
fix: eval.go
tarungka Oct 23, 2024
ac4cc88
fix: integration tests
tarungka Oct 23, 2024
d89305a
fix: integration tests
tarungka Oct 23, 2024
2084a49
fix: integration tests
tarungka Oct 23, 2024
b67bdce
fix: more integration tests
tarungka Oct 23, 2024
80891e0
fix: integration tests
tarungka Oct 23, 2024
22d167f
fix: integration tests
tarungka Oct 24, 2024
e3c8296
fix: unit tests
tarungka Oct 24, 2024
c50a959
chore: delete migrated test cases
tarungka Oct 25, 2024
fe7c29f
feat: update the assert package
tarungka Oct 25, 2024
16c6053
fix: unittests
tarungka Oct 26, 2024
41bc1ce
fix: merge conflicts
tarungka Oct 26, 2024
9316e88
chore: format the code
tarungka Oct 26, 2024
af367d4
add docs for hexists
tarungka Oct 28, 2024
660b7cf
add docs for hkeys and hvals
tarungka Oct 28, 2024
39454c0
fix: docs
tarungka Oct 28, 2024
40cecb1
fix merge conflicts
tarungka Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 h1:y7y0Oa6UawqTFP
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140/go.mod h1:c9O8+fpSOX1DM8cPNSkX/qsBWdkD4yd2dpciOWQjpBw=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dicedb/go-dice v0.0.0-20241008164514-476ca02cf6b9 h1:e8fYQMtzhtbY29pTM5b1V5ll11YH4DswftICadMeAJw=
github.com/dicedb/go-dice v0.0.0-20241008164514-476ca02cf6b9/go.mod h1:8+VZrr14c2LW8fW4tWZ8Bv3P2lfvlg+PpsSn5cWWuiQ=
github.com/dicedb/go-dice v0.0.0-20241008182110-fc365d560804 h1:13mgInfjInxupefIfs2rvOQgvwiGO9E6wx2+rKFEUAo=
github.com/dicedb/go-dice v0.0.0-20241008182110-fc365d560804/go.mod h1:8+VZrr14c2LW8fW4tWZ8Bv3P2lfvlg+PpsSn5cWWuiQ=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/async/bitfield_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestBitfield(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()

FireCommand(conn, "FLUSHDB")
FireCommand(conn, "FLUSHDB")
defer FireCommand(conn, "FLUSHDB") // clean up after all test cases
syntaxErrMsg := "ERR syntax error"
bitFieldTypeErrMsg := "ERR Invalid bitfield type. Use something like i16 u8. Note that u64 is not supported but i64 is."
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/commands/async/check_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func TestErrorsForSetData(t *testing.T) {

setErrorMsg := "WRONGTYPE Operation against a key holding the wrong kind of value"
testCases := []struct {
name string
cmd []string
name string
cmd []string
expected []interface{}
assertType []string
delay []time.Duration
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/async/del_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ func TestDel(t *testing.T) {
}
})
}
}
}
4 changes: 2 additions & 2 deletions integration_tests/commands/async/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func TestDumpRestore(t *testing.T) {
return false
}
return len(decoded) > 11 &&
decoded[0] == 0x09 &&
decoded[1] == 0x00 &&
decoded[0] == 0x09 &&
decoded[1] == 0x00 &&
string(decoded[6:11]) == "hello" &&
decoded[11] == 0xFF
},
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/commands/async/hkeys_test.go
tarungka marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestHKEYS(t *testing.T) {
name: "HKEYS with wrong number of arguments",
commands: []string{"HKEYS key_hkeys03 x", "HKEYS"},
expected: []interface{}{"ERR wrong number of arguments for 'hkeys' command",
"ERR wrong number of arguments for 'hkeys' command"},
"ERR wrong number of arguments for 'hkeys' command"},
},
}

Expand All @@ -45,4 +45,4 @@ func TestHKEYS(t *testing.T) {
}
}
}
}
}
76 changes: 38 additions & 38 deletions integration_tests/commands/async/hsetnx_test.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
package async
import (
"testing"
"gotest.tools/v3/assert"
)
func TestHSETNX(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()
testCases := []TestCase{
{
commands: []string{"HSETNX key_nx_t1 field value", "HSET key_nx_t1 field value_new"},
expected: []interface{}{ONE, ZERO},
},
{
commands: []string{"HSETNX key_nx_t2 field1 value1"},
expected: []interface{}{ONE},
},
{
commands: []string{"HSETNX key_nx_t3 field value", "HSETNX key_nx_t3 field new_value", "HSETNX key_nx_t3"},
expected: []interface{}{ONE, ZERO, "ERR wrong number of arguments for 'hsetnx' command"},
},
{
commands: []string{"SET key_nx_t4 v", "HSETNX key_nx_t4 f v"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
},
}
for _, tc := range testCases {
for i, cmd := range tc.commands {
result := FireCommand(conn, cmd)
assert.DeepEqual(t, tc.expected[i], result)
}
}
}
package async

import (
"testing"

"gotest.tools/v3/assert"
)

func TestHSETNX(t *testing.T) {
conn := getLocalConnection()
defer conn.Close()

testCases := []TestCase{
{
commands: []string{"HSETNX key_nx_t1 field value", "HSET key_nx_t1 field value_new"},
expected: []interface{}{ONE, ZERO},
},
{
commands: []string{"HSETNX key_nx_t2 field1 value1"},
expected: []interface{}{ONE},
},
{
commands: []string{"HSETNX key_nx_t3 field value", "HSETNX key_nx_t3 field new_value", "HSETNX key_nx_t3"},
expected: []interface{}{ONE, ZERO, "ERR wrong number of arguments for 'hsetnx' command"},
},
{
commands: []string{"SET key_nx_t4 v", "HSETNX key_nx_t4 f v"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
},
}

for _, tc := range testCases {
for i, cmd := range tc.commands {
result := FireCommand(conn, cmd)
assert.DeepEqual(t, tc.expected[i], result)
}
}
}
7 changes: 4 additions & 3 deletions integration_tests/commands/async/hvals_test.go
tarungka marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package async

import (
testifyAssert "github.com/stretchr/testify/assert"
"testing"

testifyAssert "github.com/stretchr/testify/assert"

"gotest.tools/v3/assert"
)

Expand All @@ -26,12 +27,12 @@ func TestHvals(t *testing.T) {
{
name: "HVALS on wrong key type",
commands: []string{"SET hvalsKey02 field", "HVALS hvalsKey02"},
expected: []interface{}{"OK", "WRONGTYPE Operation against a key holding the wrong kind of value"},
expected: []interface{}{"OK", "ERR -WRONGTYPE Operation against a key holding the wrong kind of value"},
},
{
name: "HVALS with wrong number of arguments",
commands: []string{"HVALS hvalsKey03 x", "HVALS"},
expected: []interface{}{"ERR wrong number of arguments for 'hvals' command", "ERR wrong number of arguments for 'hvals' command"},
expected: []interface{}{"ERR wrong number of arguments for 'HVALS' command", "ERR wrong number of arguments for 'HVALS' command"},
},
}

Expand Down
6 changes: 3 additions & 3 deletions integration_tests/commands/async/json_arrpop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func TestJSONARRPOP(t *testing.T) {
testCases := []struct {
name string
commands []string
expected []interface{}
assertType []string
jsonResp []bool
expected []interface{}
assertType []string
jsonResp []bool
nestedArray bool
path string
}{
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/commands/async/mget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestMGET(t *testing.T) {

defer FireCommand(conn, "DEL k1")
defer FireCommand(conn, "DEL k2")

testCases := []struct {
name string
commands []string
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/commands/async/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func TestObjectCommand(t *testing.T) {
defer conn.Close()

testCases := []struct {
name string
commands []string
name string
commands []string
expected []interface{}
assertType []string
delay []time.Duration
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/commands/async/ttl_pttl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func TestTTLPTTL(t *testing.T) {
defer conn.Close()

testCases := []struct {
name string
commands []string
name string
commands []string
expected []interface{}
assertType []string
delay []time.Duration
Expand Down
51 changes: 51 additions & 0 deletions integration_tests/commands/http/hexists_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package http

import (
"testing"

"gotest.tools/v3/assert"
tarungka marked this conversation as resolved.
Show resolved Hide resolved
)

func TestHExists(t *testing.T) {
cmdExec := NewHTTPCommandExecutor()

tarungka marked this conversation as resolved.
Show resolved Hide resolved
testCases := []TestCase{
{
name: "HTTP Check if field exists when k f and v are set",
commands: []HTTPCommand{
{Command: "HSET", Body: map[string]interface{}{"key": "k", "field": "f", "value": "v"}},
{Command: "HEXISTS", Body: map[string]interface{}{"key": "k", "field": "f"}},
},
expected: []interface{}{float64(1), "1"},
},
{
name: "HTTP Check if field exists when k exists but not f and v",
commands: []HTTPCommand{
{Command: "HSET", Body: map[string]interface{}{"key": "k", "field": "f1", "value": "v"}},
{Command: "HEXISTS", Body: map[string]interface{}{"key": "k", "field": "f"}},
},
expected: []interface{}{float64(1), "0"},
},
{
name: "HTTP Check if field exists when no k,f and v exist",
commands: []HTTPCommand{
{Command: "HEXISTS", Body: map[string]interface{}{"key": "k", "field": "f"}},
},
expected: []interface{}{"0"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cmdExec.FireCommand(HTTPCommand{
Command: "HDEL",
Body: map[string]interface{}{"key": "k", "field": "f"},
})

for i, cmd := range tc.commands {
result, _ := cmdExec.FireCommand(cmd)
assert.DeepEqual(t, tc.expected[i], result)
}
})
}
}
49 changes: 49 additions & 0 deletions integration_tests/commands/http/hkeys_test.go
tarungka marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package http

import (
"testing"

"gotest.tools/v3/assert"
)

func TestHKeys(t *testing.T) {
cmdExec := NewHTTPCommandExecutor()

testCases := []TestCase{
{
name: "HTTP One or more keys exist",
commands: []HTTPCommand{
{Command: "HSET", Body: map[string]interface{}{"key": "k", "field": "f", "value": "v"}},
{Command: "HSET", Body: map[string]interface{}{"key": "k", "field": "f1", "value": "v"}},
{Command: "HKEYS", Body: map[string]interface{}{"key": "k"}},
},
expected: []interface{}{float64(1), float64(1), []interface{}{"f", "f1"}},
},
{
name: "HTTP No keys exist",
commands: []HTTPCommand{
{Command: "HKEYS", Body: map[string]interface{}{"key": "k"}},
},
expected: []interface{}{nil},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cmdExec.FireCommand(HTTPCommand{
Command: "HDEL",
Body: map[string]interface{}{"key": "k", "field": "f"},
})
cmdExec.FireCommand(HTTPCommand{
Command: "HDEL",
Body: map[string]interface{}{"key": "k", "field": "f1"},
})

for i, cmd := range tc.commands {
result, _ := cmdExec.FireCommand(cmd)
// fmt.Printf("%v | %v\n", result, tc.expected[i])
assert.DeepEqual(t, tc.expected[i], result)
}
})
}
}
50 changes: 50 additions & 0 deletions integration_tests/commands/http/hvals_test.go
tarungka marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package http

import (
"fmt"
"testing"

"gotest.tools/v3/assert"
)

func TestHVals(t *testing.T) {
cmdExec := NewHTTPCommandExecutor()

testCases := []TestCase{
{
name: "HTTP One or more keys exist",
commands: []HTTPCommand{
{Command: "HSET", Body: map[string]interface{}{"key": "k", "field": "f", "value": "v"}},
{Command: "HSET", Body: map[string]interface{}{"key": "k", "field": "f1", "value": "v1"}},
{Command: "HVALS", Body: map[string]interface{}{"key": "k"}},
},
expected: []interface{}{float64(1), float64(1), []interface{}{"v", "v1"}},
},
{
name: "HTTP No keys exist",
commands: []HTTPCommand{
{Command: "HVALS", Body: map[string]interface{}{"key": "k"}},
},
expected: []interface{}{[]interface{}{}},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cmdExec.FireCommand(HTTPCommand{
Command: "HDEL",
Body: map[string]interface{}{"key": "k", "field": "f"},
})
cmdExec.FireCommand(HTTPCommand{
Command: "HDEL",
Body: map[string]interface{}{"key": "k", "field": "f1"},
})

for i, cmd := range tc.commands {
result, _ := cmdExec.FireCommand(cmd)
fmt.Printf("%v | %v\n", result, tc.expected[i])
assert.DeepEqual(t, tc.expected[i], result)
}
})
}
}
Loading