Repository: DiceDB/dice
File: integration_tests/commands/http/geo_test.go (Go)

Code before:

    testCases := []struct {
        name     string
        commands []HTTPCommand
        expected []interface{}
    }{
        {
            name: "GEOPOS for existing points",
            commands: []HTTPCommand{
                {Command: "GEOADD", Body: map[string]interface{}{"key": "index", "values": []interface{}{"13.361389", "38.115556", "Palermo"}}},
                {Command: "GEOPOS", Body: map[string]interface{}{"key": "index", "values": []interface{}{"Palermo"}}},
            },
			expected: []interface{}{
				float64(1),
				[]interface{}{[]interface{}{float64(13.361387), float64(38.115556)}},
			},
        },
        {	
            name: "GEOPOS for non-existing points",
            commands: []HTTPCommand{
                {Command: "GEOPOS", Body: map[string]interface{}{"key": "index", "values": []interface{}{"NonExisting"}}},
            },
			expected: []interface{}{[]interface{}{nil}},
        },
        {
            name: "GEOPOS for non-existing index",
            commands: []HTTPCommand{
                {Command: "GEOPOS", Body: map[string]interface{}{"key": "NonExisting", "values": []interface{}{"Palermo"}}},
            },
            expected: []interface{}{nil},
        },
    }

    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 %v", cmd)
            }
        })
    }
}


Review comment (bug):
Shall we add a test for below case?
```
redis> SET k1 v1
"OK"
redis> GEOPOS k1 v1
(error) WRONGTYPE Operation against a key holding the wrong kind of value
```



Code after:

    testCases := []struct {
        name     string
        commands []HTTPCommand
        expected []interface{}
    }{
        {
            name: "GEOPOS for existing points",
            commands: []HTTPCommand{
                {Command: "GEOADD", Body: map[string]interface{}{"key": "index", "values": []interface{}{"13.361389", "38.115556", "Palermo"}}},
                {Command: "GEOPOS", Body: map[string]interface{}{"key": "index", "values": []interface{}{"Palermo"}}},
            },
			expected: []interface{}{
				float64(1),
				[]interface{}{[]interface{}{float64(13.361387), float64(38.115556)}},
			},
        },
        {	
            name: "GEOPOS for non-existing points",
            commands: []HTTPCommand{
                {Command: "GEOPOS", Body: map[string]interface{}{"key": "index", "values": []interface{}{"NonExisting"}}},
            },
			expected: []interface{}{[]interface{}{nil}},
        },
        {
            name: "GEOPOS for non-existing index",
            commands: []HTTPCommand{
                {Command: "GEOPOS", Body: map[string]interface{}{"key": "NonExisting", "values": []interface{}{"Palermo"}}},
            },
            expected: []interface{}{nil},
        },
		{
            name: "GEOPOS for a key not used for setting geospatial values",
            commands: []HTTPCommand{
				{Command: "SET", Body: map[string]interface{}{"key": "k", "value": "v"}},                
				{Command: "GEOPOS", Body: map[string]interface{}{"key": "k", "values": []interface{}{"v"}}},            
			},
            expected: []interface{}{
				"OK",
				"WRONGTYPE Operation against a key holding the wrong kind of value",
			},
        },
    }

    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 %v", cmd)
            }
        })