refactor command table

This commit is contained in:
hdt3213
2021-05-24 23:17:55 +08:00
parent 68ae54f596
commit f1455534d4
24 changed files with 776 additions and 899 deletions

View File

@@ -10,52 +10,52 @@ import (
)
func TestGeoHash(t *testing.T) {
FlushDB(testDB, utils.ToBytesList())
execFlushDB(testDB, utils.ToBytesList())
key := utils.RandString(10)
pos := utils.RandString(10)
result := GeoAdd(testDB, utils.ToBytesList(key, "13.361389", "38.115556", pos))
result := execGeoAdd(testDB, utils.ToBytesList(key, "13.361389", "38.115556", pos))
asserts.AssertIntReply(t, result, 1)
result = GeoHash(testDB, utils.ToBytesList(key, pos))
result = execGeoHash(testDB, utils.ToBytesList(key, pos))
asserts.AssertMultiBulkReply(t, result, []string{"sqc8b49rnys00"})
}
func TestGeoRadius(t *testing.T) {
FlushDB(testDB, utils.ToBytesList())
execFlushDB(testDB, utils.ToBytesList())
key := utils.RandString(10)
pos1 := utils.RandString(10)
pos2 := utils.RandString(10)
GeoAdd(testDB, utils.ToBytesList(key,
execGeoAdd(testDB, utils.ToBytesList(key,
"13.361389", "38.115556", pos1,
"15.087269", "37.502669", pos2,
))
result := GeoRadius(testDB, utils.ToBytesList(key, "15", "37", "200", "km"))
result := execGeoRadius(testDB, utils.ToBytesList(key, "15", "37", "200", "km"))
asserts.AssertMultiBulkReplySize(t, result, 2)
}
func TestGeoRadiusByMember(t *testing.T) {
FlushDB(testDB, utils.ToBytesList())
execFlushDB(testDB, utils.ToBytesList())
key := utils.RandString(10)
pos1 := utils.RandString(10)
pos2 := utils.RandString(10)
pivot := utils.RandString(10)
GeoAdd(testDB, utils.ToBytesList(key,
execGeoAdd(testDB, utils.ToBytesList(key,
"13.361389", "38.115556", pos1,
"17.087269", "38.502669", pos2,
"13.583333", "37.316667", pivot,
))
result := GeoRadiusByMember(testDB, utils.ToBytesList(key, pivot, "100", "km"))
result := execGeoRadiusByMember(testDB, utils.ToBytesList(key, pivot, "100", "km"))
asserts.AssertMultiBulkReplySize(t, result, 2)
}
func TestGeoPos(t *testing.T) {
FlushDB(testDB, utils.ToBytesList())
execFlushDB(testDB, utils.ToBytesList())
key := utils.RandString(10)
pos1 := utils.RandString(10)
pos2 := utils.RandString(10)
GeoAdd(testDB, utils.ToBytesList(key,
execGeoAdd(testDB, utils.ToBytesList(key,
"13.361389", "38.115556", pos1,
))
result := GeoPos(testDB, utils.ToBytesList(key, pos1, pos2))
result := execGeoPos(testDB, utils.ToBytesList(key, pos1, pos2))
expected := "*2\r\n*2\r\n$18\r\n13.361386698670685\r\n$17\r\n38.11555536696687\r\n*0\r\n"
if string(result.ToBytes()) != expected {
t.Error("test failed")
@@ -63,15 +63,15 @@ func TestGeoPos(t *testing.T) {
}
func TestGeoDist(t *testing.T) {
FlushDB(testDB, utils.ToBytesList())
execFlushDB(testDB, utils.ToBytesList())
key := utils.RandString(10)
pos1 := utils.RandString(10)
pos2 := utils.RandString(10)
GeoAdd(testDB, utils.ToBytesList(key,
execGeoAdd(testDB, utils.ToBytesList(key,
"13.361389", "38.115556", pos1,
"15.087269", "37.502669", pos2,
))
result := GeoDist(testDB, utils.ToBytesList(key, pos1, pos2, "km"))
result := execGeoDist(testDB, utils.ToBytesList(key, pos1, pos2, "km"))
bulkReply, ok := result.(*reply.BulkReply)
if !ok {
t.Error(fmt.Sprintf("expected bulk reply, actually %s", result.ToBytes()))
@@ -86,7 +86,7 @@ func TestGeoDist(t *testing.T) {
t.Errorf("expected 166.274, actual: %f", dist)
}
result = GeoDist(testDB, utils.ToBytesList(key, pos1, pos2, "m"))
result = execGeoDist(testDB, utils.ToBytesList(key, pos1, pos2, "m"))
bulkReply, ok = result.(*reply.BulkReply)
if !ok {
t.Error(fmt.Sprintf("expected bulk reply, actually %s", result.ToBytes()))