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

#1033 Migrating GEOADD and GEODIST command #1185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
86 changes: 86 additions & 0 deletions integration_tests/commands/http/geo_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package http

import (
"testing"

"gotest.tools/v3/assert"
)

func TestGeoAdd(t *testing.T) {
exec := NewHTTPCommandExecutor()

testCases := []struct {
name string
commands []HTTPCommand
expected []interface{}
}{
{
name: "GEOADD with wrong number of arguments",
commands: []HTTPCommand{
{Command: "GEOADD", Body: map[string]interface{}{"key": "mygeo", "values": []interface{}{"1.2", "2.4"}}},
},
expected: []interface{}{"ERR wrong number of arguments for 'geoadd' command"},
},
{
name: "GEOADD Commands with new member and updating it",
commands: []HTTPCommand{
{Command: "GEOADD", Body: map[string]interface{}{"key": "mygeo", "values": []interface{}{"1.2", "2.4", "NJ"}}},
{Command: "GEOADD", Body: map[string]interface{}{"key": "mygeo", "values": []interface{}{"1.24", "2.48", "NJ"}}},
},
expected: []interface{}{float64(1), float64(0)},
},
{
name: "GEOADD Adding both XX and NX options together",
commands: []HTTPCommand{
{Command: "GEOADD", Body: map[string]interface{}{"key": "mygeo", "values": []interface{}{"XX", "NX", "1.2", "2.4", "NJ"}}},
},
expected: []interface{}{"ERR XX and NX options at the same time are not compatible"},
},
{
name: "GEOADD Invalid Longitude",
commands: []HTTPCommand{
{Command: "GEOADD", Body: map[string]interface{}{"key": "mygeo", "values": []interface{}{"181", "2.4", "MT"}}},
},
expected: []interface{}{"ERR invalid longitude"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for i, cmd := range tc.commands {
result, _ := exec.FireCommand(cmd)
assert.Equal(t, tc.expected[i], result, "Value mismatch for cmd %s", cmd)
}
})
}
}

func TestGeoDist(t *testing.T) {
exec := NewHTTPCommandExecutor()

testCases := []struct {
name string
commands []HTTPCommand
expected []interface{}
}{
{
name: "GEODIST b/w existing points",
commands: []HTTPCommand{
{Command: "GEOADD", Body: map[string]interface{}{"key": "points", "values": []interface{}{"13.361389", "38.115556", "Palermo"}}},
{Command: "GEOADD", Body: map[string]interface{}{"key": "points", "values": []interface{}{"15.087269", "37.502669", "Catania"}}},
{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)},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for i, cmd := range tc.commands {
result, _ := exec.FireCommand(cmd)
assert.Equal(t, tc.expected[i], result, "Value mismatch for cmd %s", cmd)
}
})
}
}
86 changes: 86 additions & 0 deletions integration_tests/commands/resp/geo_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package resp

import (
"testing"
"time"

"gotest.tools/v3/assert"
)

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

testCases := []struct {
name string
cmds []string
expect []interface{}
}{
{
name: "GeoAdd With Wrong Number of Arguments",
cmds: []string{"GEOADD mygeo 1 2"},
expect: []interface{}{"ERR wrong number of arguments for 'geoadd' command"},
},
{
name: "GeoAdd With Adding New Member And Updating it",
cmds: []string{"GEOADD mygeo 1.21 1.44 NJ", "GEOADD mygeo 1.22 1.54 NJ"},
expect: []interface{}{int64(1), int64(0)},
},
{
name: "GeoAdd With Adding New Member And Updating it with NX",
cmds: []string{"GEOADD mygeo 1.21 1.44 MD", "GEOADD mygeo 1.22 1.54 MD"},
expect: []interface{}{int64(1), int64(0)},
},
{
name: "GEOADD with both NX and XX options",
cmds: []string{"GEOADD mygeo NX XX 1.21 1.44 MD"},
expect: []interface{}{"ERR XX and NX options at the same time are not compatible"},
},
{
name: "GEOADD invalid longitude",
cmds: []string{"GEOADD mygeo 181.0 1.44 MD"},
expect: []interface{}{"ERR invalid longitude"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for i, cmd := range tc.cmds {
result := FireCommand(conn, cmd)
assert.Equal(t, tc.expect[i], result, "Value mismatch for cmd %s", cmd)
}
})
}
}

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

testCases := []struct {
name string
cmds []string
expect []interface{}
delays []time.Duration
}{
{
name: "GEODIST b/w existing points",
cmds: []string{
"GEOADD points 13.361389 38.115556 Palermo",
"GEOADD points 15.087269 37.502669 Catania",
"GEODIST points Palermo Catania",
"GEODIST points Palermo Catania km",
},
expect: []interface{}{int64(1), int64(1), "166274.144", "166.2741"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for i, cmd := range tc.cmds {
result := FireCommand(conn, cmd)
assert.Equal(t, tc.expect[i], result, "Value mismatch for cmd %s", cmd)
}
})
}
}
87 changes: 87 additions & 0 deletions integration_tests/commands/websocket/geo_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package websocket

import (
"testing"

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

func TestGeoAdd(t *testing.T) {
exec := NewWebsocketCommandExecutor()
conn := exec.ConnectToServer()

testCases := []struct {
name string
cmds []string
expect []interface{}
}{
{
name: "GeoAdd With Wrong Number of Arguments",
cmds: []string{"GEOADD mygeo 1 2"},
expect: []interface{}{"ERR wrong number of arguments for 'geoadd' command"},
},
{
name: "GeoAdd With Adding New Member And Updating it",
cmds: []string{"GEOADD mygeo 1.21 1.44 NJ", "GEOADD mygeo 1.22 1.54 NJ"},
expect: []interface{}{float64(1), float64(0)},
},
{
name: "GeoAdd With Adding New Member And Updating it with NX",
cmds: []string{"GEOADD mygeo NX 1.21 1.44 MD", "GEOADD mygeo 1.22 1.54 MD"},
expect: []interface{}{float64(1), float64(0)},
},
{
name: "GEOADD with both NX and XX options",
cmds: []string{"GEOADD mygeo NX XX 1.21 1.44 DEL"},
expect: []interface{}{"ERR XX and NX options at the same time are not compatible"},
},
{
name: "GEOADD invalid longitude",
cmds: []string{"GEOADD mygeo 181.0 1.44 MD"},
expect: []interface{}{"ERR invalid longitude"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for i, cmd := range tc.cmds {
result, err := exec.FireCommandAndReadResponse(conn, cmd)
assert.Nil(t, err)
assert.Equal(t, tc.expect[i], result, "Value mismatch for cmd %s", cmd)
}
})
}
}

func TestGeoDist(t *testing.T) {
exec := NewWebsocketCommandExecutor()
conn := exec.ConnectToServer()
defer conn.Close()

testCases := []struct {
name string
cmds []string
expect []interface{}
}{
{
name: "GEODIST b/w existing points",
cmds: []string{
"GEOADD points 13.361389 38.115556 Palermo",
"GEOADD points 15.087269 37.502669 Catania",
"GEODIST points Palermo Catania",
"GEODIST points Palermo Catania km",
},
expect: []interface{}{float64(1), float64(1), float64(166274.144), float64(166.2741)},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for i, cmd := range tc.cmds {
result, err := exec.FireCommandAndReadResponse(conn, cmd)
assert.Nil(t, err)
assert.Equal(t, tc.expect[i], result, "Value mismatch for cmd %s", cmd)
}
})
}
}
22 changes: 12 additions & 10 deletions internal/eval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,18 +1119,20 @@ var (
NewEval: evalHINCRBYFLOAT,
}
geoAddCmdMeta = DiceCmdMeta{
Name: "GEOADD",
Info: `Adds one or more members to a geospatial index. The key is created if it doesn't exist.`,
Arity: -5,
Eval: evalGEOADD,
KeySpecs: KeySpecs{BeginIndex: 1},
Name: "GEOADD",
Info: `Adds one or more members to a geospatial index. The key is created if it doesn't exist.`,
Arity: -5,
IsMigrated: true,
NewEval: evalGEOADD,
KeySpecs: KeySpecs{BeginIndex: 1},
}
geoDistCmdMeta = DiceCmdMeta{
Name: "GEODIST",
Info: `Returns the distance between two members in the geospatial index.`,
Arity: -4,
Eval: evalGEODIST,
KeySpecs: KeySpecs{BeginIndex: 1},
Name: "GEODIST",
Info: `Returns the distance between two members in the geospatial index.`,
Arity: -4,
IsMigrated: true,
NewEval: evalGEODIST,
KeySpecs: KeySpecs{BeginIndex: 1},
}
jsonstrappendCmdMeta = DiceCmdMeta{
Name: "JSON.STRAPPEND",
Expand Down
Loading