Skip to content

Commit

Permalink
#1387: Remove validator field from evalTestCase. (#1400)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-harish authored Dec 26, 2024
1 parent 7609c70 commit b39869c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 89 deletions.
2 changes: 1 addition & 1 deletion config/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func applyDefaultValuesFromTags(config *Config, fieldName string) error {

func validateWALConfig(sl validator.StructLevel) {
config := sl.Current().Interface().(Config)

// LogDir validation
if config.WAL.LogDir == "" {
sl.ReportError(config.WAL.LogDir, "LogDir", "LogDir", "required", "cannot be empty")
Expand Down
60 changes: 29 additions & 31 deletions integration_tests/commands/http/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ func runIntegrationTests(t *testing.T, exec *HTTPCommandExecutor, testCases []In
case "range":
assert.True(t, result.(float64) <= out.(float64) && result.(float64) > 0, "Expected %v to be within 0 to %v", result, out)
case "json_equal":
// fmt.Println("hi expected : ", out)
// fmt.Println("hi actual :", result)
assert.JSONEq(t, out.(string), result.(string))
case "deep_equal":
assert.ElementsMatch(t, result.([]interface{}), out.([]interface{}))
Expand Down Expand Up @@ -1794,162 +1792,162 @@ func TestJSONARRINDEX(t *testing.T) {
exec.FireCommand(HTTPCommand{Command: "DEL", Body: map[string]interface{}{"key": "key"}})
defer exec.FireCommand(HTTPCommand{Command: "DEL", Body: map[string]interface{}{"key": "key"}})

normalArray := `[0,1,2,3,4,3]`
nestedArray := `{"arrays":[{"arr":[1,2,3]},{"arr":[2,3,4]},{"arr":[1]}]}`
normalArray := `[0,1,2,3,4,3]`
nestedArray := `{"arrays":[{"arr":[1,2,3]},{"arr":[2,3,4]},{"arr":[1]}]}`
nestedArray2 := `{"a":[3],"nested":{"a":{"b":2,"c":1}}}`

testCases := []IntegrationTestCase{
{
name: "should return array index when given element is present",
name: "should return array index when given element is present",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(normalArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$", "value": 3}},
},
expected: []interface{}{"OK", []interface{}{float64(3)}},
expected: []interface{}{"OK", []interface{}{float64(3)}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return -1 when given element is not present",
name: "should return -1 when given element is not present",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(normalArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$", "value": 10}},
},
expected: []interface{}{"OK", []interface{}{float64(-1)}},
expected: []interface{}{"OK", []interface{}{float64(-1)}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return array index with start optional param provided",
name: "should return array index with start optional param provided",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(normalArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$", "values": []string{"3", "4"}}},
},
expected: []interface{}{"OK", []interface{}{float64(5)}},
expected: []interface{}{"OK", []interface{}{float64(5)}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return array index with start and stop optional param provided",
name: "should return array index with start and stop optional param provided",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(normalArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$", "values": []string{"4", "4", "5"}}},
},
expected: []interface{}{"OK", []interface{}{float64(4)}},
expected: []interface{}{"OK", []interface{}{float64(4)}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return -1 with start and stop optional param provided where start > stop",
name: "should return -1 with start and stop optional param provided where start > stop",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(normalArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$", "values": []string{"3", "2", "1"}}},
},
expected: []interface{}{"OK", []interface{}{float64(-1)}},
expected: []interface{}{"OK", []interface{}{float64(-1)}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return -1 with start (out of boud) and stop (out of bound) optional param provided",
name: "should return -1 with start (out of boud) and stop (out of bound) optional param provided",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(normalArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$", "values": []string{"3", "6", "10"}}},
},
expected: []interface{}{"OK", []interface{}{float64(-1)}},
expected: []interface{}{"OK", []interface{}{float64(-1)}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return list of array indexes for nested json",
name: "should return list of array indexes for nested json",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(nestedArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$.arrays.*.arr", "value": 3}},
},
expected: []interface{}{"OK", []interface{}{float64(2), float64(1), float64(-1)}},
expected: []interface{}{"OK", []interface{}{float64(2), float64(1), float64(-1)}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return list of array indexes for multiple json path",
name: "should return list of array indexes for multiple json path",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(nestedArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$..arr", "value": 3}},
},
expected: []interface{}{"OK", []interface{}{float64(2), float64(1), float64(-1)}},
expected: []interface{}{"OK", []interface{}{float64(2), float64(1), float64(-1)}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return array of length 1 for nested json path, with index",
name: "should return array of length 1 for nested json path, with index",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(nestedArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$.arrays[1].arr", "value": 3}},
},
expected: []interface{}{"OK", []interface{}{float64(1)}},
expected: []interface{}{"OK", []interface{}{float64(1)}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return empty array for nonexistent path in nested json",
name: "should return empty array for nonexistent path in nested json",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(nestedArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$..arr1", "value": 3}},
},
expected: []interface{}{"OK", []interface{}{}},
expected: []interface{}{"OK", []interface{}{}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return -1 for each nonexisting value in nested json",
name: "should return -1 for each nonexisting value in nested json",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(nestedArray)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$..arr", "value": 5}},
},
expected: []interface{}{"OK", []interface{}{float64(-1), float64(-1), float64(-1)}},
expected: []interface{}{"OK", []interface{}{float64(-1), float64(-1), float64(-1)}},
assertType: []string{"equal", "equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return nil for non-array path and -1 for array path if value DNE",
name: "should return nil for non-array path and -1 for array path if value DNE",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(nestedArray2)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$..a", "value": 2}},
},
expected: []interface{}{"OK", []interface{}{float64(-1), nil}},
expected: []interface{}{"OK", []interface{}{float64(-1), nil}},
assertType: []string{"equal", "deep_equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "should return nil for non-array path if value DNE and valid index for array path if value exists",
name: "should return nil for non-array path if value DNE and valid index for array path if value exists",
commands: []HTTPCommand{
{Command: "JSON.SET", Body: map[string]interface{}{"key": "key", "path": "$", "json": json.RawMessage(nestedArray2)}},
{Command: "JSON.ARRINDEX", Body: map[string]interface{}{"key": "key", "path": "$..a", "value": 3}},
},
expected: []interface{}{"OK", []interface{}{float64(0), nil}},
expected: []interface{}{"OK", []interface{}{float64(0), nil}},
assertType: []string{"equal", "deep_equal"},
cleanUp: []HTTPCommand{
{Command: "DEL", Body: map[string]interface{}{"key": "key"}},
Expand All @@ -1960,4 +1958,4 @@ func TestJSONARRINDEX(t *testing.T) {
preTestChecksCommand := HTTPCommand{Command: "DEL", Body: map[string]interface{}{"key": "key"}}
postTestChecksCommand := HTTPCommand{Command: "DEL", Body: map[string]interface{}{"key": "key"}}
runIntegrationTests(t, exec, testCases, preTestChecksCommand, postTestChecksCommand)
}
}
6 changes: 3 additions & 3 deletions internal/eval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,9 @@ var (
Name: "JSON.ARRINDEX",
Info: `JSON.ARRINDEX key path value [start [stop]]
Search for the first occurrence of a JSON value in an array`,
NewEval: evalJSONARRINDEX,
Arity: -3,
KeySpecs: KeySpecs{BeginIndex: 1},
NewEval: evalJSONARRINDEX,
Arity: -3,
KeySpecs: KeySpecs{BeginIndex: 1},
IsMigrated: true,
}

Expand Down
2 changes: 1 addition & 1 deletion internal/eval/countminsketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func DeserializeCMS(buffer *bytes.Reader) (*CountMinSketch, error) {
if err := binary.Read(buffer, binary.BigEndian, &count); err != nil {
return nil, err
}
fmt.Println(depth, width, count, buffer.Len())
// fmt.Println(depth, width, count, buffer.Len())
// Validate data size
expectedSize := int(depth * width * 8) // Each uint64 takes 8 bytes
if buffer.Len() <= expectedSize {
Expand Down
Loading

0 comments on commit b39869c

Please sign in to comment.