From 7a363194eb675878cc9d12f440a7f2345e65cd98 Mon Sep 17 00:00:00 2001 From: c-harish Date: Mon, 2 Dec 2024 15:33:40 +0530 Subject: [PATCH] fix: fix lints, failing TCs & bugs --- integration_tests/commands/http/geo_test.go | 2 +- integration_tests/commands/http/json_test.go | 6 +++--- integration_tests/commands/resp/geo_test.go | 2 +- integration_tests/commands/websocket/geo_test.go | 2 +- internal/clientio/resp_test.go | 1 - internal/eval/bytearray.go | 2 +- internal/eval/eval_test.go | 2 +- internal/eval/geo/geo.go | 4 ++-- internal/eval/sortedset/sorted_set.go | 1 - internal/eval/store_eval.go | 2 +- internal/server/cmd_meta.go | 4 ++-- 11 files changed, 13 insertions(+), 15 deletions(-) diff --git a/integration_tests/commands/http/geo_test.go b/integration_tests/commands/http/geo_test.go index a8e5c6e93..dbfa28351 100644 --- a/integration_tests/commands/http/geo_test.go +++ b/integration_tests/commands/http/geo_test.go @@ -71,7 +71,7 @@ func TestGeoDist(t *testing.T) { {Command: "GEODIST", Body: map[string]interface{}{"key": "points", "values": []interface{}{"Palermo", "Catania"}}}, {Command: "GEODIST", Body: map[string]interface{}{"key": "points", "values": []interface{}{"Palermo", "Catania", "km"}}}, }, - expected: []interface{}{float64(1), float64(1), float64(166274.144), float64(166.2741)}, + expected: []interface{}{float64(1), float64(1), float64(166274.1516), float64(166.2742)}, }, } diff --git a/integration_tests/commands/http/json_test.go b/integration_tests/commands/http/json_test.go index 8a3b862ec..9bc13f8e3 100644 --- a/integration_tests/commands/http/json_test.go +++ b/integration_tests/commands/http/json_test.go @@ -50,9 +50,9 @@ func runIntegrationTests(t *testing.T, exec *HTTPCommandExecutor, testCases []In out := tc.expected[i] result, _ := exec.FireCommand(cmd) - fmt.Println(cmd, result, out) - fmt.Printf("Type of value: %T\n", result) // Replace `value` with your actual variable - fmt.Printf("Type of value: %T\n", out) // Replace `value` with your actual variable + // fmt.Println(cmd, result, out) + // fmt.Printf("Type of value: %T\n", result) // Replace `value` with your actual variable + // fmt.Printf("Type of value: %T\n", out) // Replace `value` with your actual variable switch tc.assertType[i] { case "equal": diff --git a/integration_tests/commands/resp/geo_test.go b/integration_tests/commands/resp/geo_test.go index 57bd2656a..0d9cde76c 100644 --- a/integration_tests/commands/resp/geo_test.go +++ b/integration_tests/commands/resp/geo_test.go @@ -71,7 +71,7 @@ func TestGeoDist(t *testing.T) { "GEODIST points Palermo Catania", "GEODIST points Palermo Catania km", }, - expect: []interface{}{int64(1), int64(1), "166274.144", "166.2741"}, + expect: []interface{}{int64(1), int64(1), "166274.1516", "166.2742"}, }, } diff --git a/integration_tests/commands/websocket/geo_test.go b/integration_tests/commands/websocket/geo_test.go index e2c5d240b..e1c59ac91 100644 --- a/integration_tests/commands/websocket/geo_test.go +++ b/integration_tests/commands/websocket/geo_test.go @@ -71,7 +71,7 @@ func TestGeoDist(t *testing.T) { "GEODIST points Palermo Catania", "GEODIST points Palermo Catania km", }, - expect: []interface{}{float64(1), float64(1), float64(166274.144), float64(166.2741)}, + expect: []interface{}{float64(1), float64(1), float64(166274.1516), float64(166.2742)}, }, } diff --git a/internal/clientio/resp_test.go b/internal/clientio/resp_test.go index 2ff0c71cc..b04b4b25e 100644 --- a/internal/clientio/resp_test.go +++ b/internal/clientio/resp_test.go @@ -36,7 +36,6 @@ func TestSimpleStringDecode(t *testing.T) { if v != value { t.Fail() } - fmt.Println(v, value) } } diff --git a/internal/eval/bytearray.go b/internal/eval/bytearray.go index 91e9edc40..45900aa21 100644 --- a/internal/eval/bytearray.go +++ b/internal/eval/bytearray.go @@ -98,7 +98,7 @@ func ByteSliceToObj(store *dstore.Store, oldObj *object.Obj, b []byte, objType u func ByteSliceToIntObj(store *dstore.Store, oldObj *object.Obj, b []byte) (*object.Obj, error) { intVal, err := strconv.ParseInt(string(b), 10, 64) if err != nil { - return store.NewObj(string(b), -1, object.ObjTypeString, object.ObjEncodingEmbStr), nil + return store.NewObj(string(b), -1, object.ObjTypeString), nil } return store.NewObj(intVal, -1, object.ObjTypeInt), nil } diff --git a/internal/eval/eval_test.go b/internal/eval/eval_test.go index 8c45d6f69..b8659ab41 100644 --- a/internal/eval/eval_test.go +++ b/internal/eval/eval_test.go @@ -9256,7 +9256,7 @@ func testEvalGEORADIUSBYMEMBER(t *testing.T, store *dstore.Store) { }, "GEORADIUSBYMEMBER wrong type operation": { setup: func() { - store.Put("wrongtype", store.NewObj("string_value", -1, object.ObjTypeString, object.ObjEncodingRaw)) + store.Put("wrongtype", store.NewObj("string_value", -1, object.ObjTypeString)) }, input: []string{"wrongtype", "wtc one", "7", "km"}, migratedOutput: EvalResponse{ diff --git a/internal/eval/geo/geo.go b/internal/eval/geo/geo.go index de21193d6..0cfd2e776 100644 --- a/internal/eval/geo/geo.go +++ b/internal/eval/geo/geo.go @@ -228,7 +228,7 @@ func Area(centerHash, radius float64) (result [9]uint64, steps uint8) { steps = geohashEstimateStepsByRadius(radius, centerLat) centerRadiusHash := encodeHash(centerLon, centerLat, steps) - neighbors := geohashNeighbors(uint64(centerRadiusHash), steps) + neighbors := geohashNeighbors(centerRadiusHash, steps) area := areaBySteps(centerRadiusHash, steps) /* Check if the step is enough at the limits of the covered area. @@ -290,7 +290,7 @@ func Area(centerHash, radius float64) (result [9]uint64, steps uint8) { // HashMinMax returns the min and max hashes for a given hash and steps. This can be used to get the range of hashes // that a given hash and a radius (steps) will cover. -func HashMinMax(hash uint64, steps uint8) (minHash uint64, maxHash uint64) { +func HashMinMax(hash uint64, steps uint8) (minHash, maxHash uint64) { minHash = align52Bits(hash, steps) hash++ maxHash = align52Bits(hash, steps) diff --git a/internal/eval/sortedset/sorted_set.go b/internal/eval/sortedset/sorted_set.go index 3f8320a38..11e96b712 100644 --- a/internal/eval/sortedset/sorted_set.go +++ b/internal/eval/sortedset/sorted_set.go @@ -255,7 +255,6 @@ func (ss *Set) CountInRange(minVal, maxVal float64) int { // GetScoreRange returns a slice of members with scores between min and max, inclusive. // If withScores is true, the members will be returned with their scores. func (ss *Set) GetMemberScoresInRange(minScore, maxScore float64, count, maxCount int) (members []string, scores []float64) { - iterFunc := func(item btree.Item) bool { ssi := item.(*Item) if ssi.Score < minScore { diff --git a/internal/eval/store_eval.go b/internal/eval/store_eval.go index 493f51f11..5762ebbbe 100644 --- a/internal/eval/store_eval.go +++ b/internal/eval/store_eval.go @@ -7035,7 +7035,7 @@ func evalGEORADIUSBYMEMBER(args []string, store *dstore.Store) *EvalResponse { member := []interface{}{} member = append(member, members[indices[i]]) if opts.WithDist { - member = append(member, dists[indices[i]]) + member = append(member, utils.RoundToDecimals(dists[indices[i]], 4)) } if opts.WithHash { member = append(member, hashes[indices[i]]) diff --git a/internal/server/cmd_meta.go b/internal/server/cmd_meta.go index 8b2e2ca75..6880ac3eb 100644 --- a/internal/server/cmd_meta.go +++ b/internal/server/cmd_meta.go @@ -459,11 +459,11 @@ var ( Type: SingleShard, } geoRadiusByMemberCmdMeta = CmdMeta{ - Cmd: "GEORADIUSBYMEMBER", + Cmd: "GEORADIUSBYMEMBER", Type: SingleShard, } clientCmdMeta = CmdMeta{ - Cmd: "CLIENT", + Cmd: "CLIENT", Type: SingleShard, } latencyCmdMeta = CmdMeta{