mirror of https://github.com/tidwall/tile38.git
parent
714cca6d6c
commit
fc3e8b4359
|
@ -342,7 +342,7 @@ func (sw *scanWriter) testObject(id string, o geojson.Object, fields []float64,
|
|||
if !ignoreGlobMatch {
|
||||
match, kg := sw.globMatch(id, o)
|
||||
if !match {
|
||||
return true, kg, fieldVals
|
||||
return false, kg, fieldVals
|
||||
}
|
||||
}
|
||||
nf, ok := sw.fieldMatch(fields, o)
|
||||
|
|
|
@ -413,7 +413,7 @@ func (server *Server) nearestNeighbors(
|
|||
if server.hasExpired(s.key, id) {
|
||||
return true
|
||||
}
|
||||
ok, keepGoing, _ := sw.testObject(id, o, fields, true)
|
||||
ok, keepGoing, _ := sw.testObject(id, o, fields, false)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
## Tile38 Integation Testing
|
||||
|
||||
- Uses Redis protocol
|
||||
- The Tile38 data is flushed before every `DoBatch`
|
||||
|
||||
A basic test operation looks something like:
|
||||
|
||||
```go
|
||||
func keys_SET_test(mc *mockServer) error {
|
||||
return mc.DoBatch([][]interface{}{
|
||||
{"SET", "fleet", "truck1", "POINT", 33.0001, -112.0001}, {"OK"},
|
||||
{"GET", "fleet", "truck1", "POINT"}, {"[33.0001 -112.0001]"},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Using a custom function:
|
||||
|
||||
```go
|
||||
func keys_MATCH_test(mc *mockServer) error {
|
||||
return mc.DoBatch([][]interface{}{
|
||||
{"SET", "fleet", "truck1", "POINT", 33.0001, -112.0001}, {
|
||||
func(v interface{}) (resp, expect interface{}) {
|
||||
// v is the value as strings or slices of strings
|
||||
// test will pass as long as `resp` and `expect` are the same.
|
||||
return v, "OK"
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -15,6 +17,7 @@ func subTestSearch(t *testing.T, mc *mockServer) {
|
|||
runStep(t, mc, "INTERSECTS_CURSOR", keys_INTERSECTS_CURSOR_test)
|
||||
runStep(t, mc, "SCAN_CURSOR", keys_SCAN_CURSOR_test)
|
||||
runStep(t, mc, "SEARCH_CURSOR", keys_SEARCH_CURSOR_test)
|
||||
runStep(t, mc, "MATCH", keys_MATCH_test)
|
||||
}
|
||||
|
||||
func keys_KNN_test(mc *mockServer) error {
|
||||
|
@ -302,3 +305,63 @@ func keys_SEARCH_CURSOR_test(mc *mockServer) error {
|
|||
{"SEARCH", "mykey", "LIMIT", 3, "DESC", "IDS"}, {"[3 [id9 id8 id7]]"},
|
||||
})
|
||||
}
|
||||
|
||||
func keys_MATCH_test(mc *mockServer) error {
|
||||
return mc.DoBatch([][]interface{}{
|
||||
{"SET", "fleet", "truck1", "POINT", "33.0001", "-112.0001"}, {"OK"},
|
||||
{"SET", "fleet", "truck2", "POINT", "33.0002", "-112.0002"}, {"OK"},
|
||||
{"SET", "fleet", "luck1", "POINT", "33.0003", "-112.0003"}, {"OK"},
|
||||
{"SET", "fleet", "luck2", "POINT", "33.0004", "-112.0004"}, {"OK"},
|
||||
|
||||
{"SCAN", "fleet", "IDS"}, {"[0 [luck1 luck2 truck1 truck2]]"},
|
||||
{"SCAN", "fleet", "MATCH", "*", "IDS"}, {"[0 [luck1 luck2 truck1 truck2]]"},
|
||||
{"SCAN", "fleet", "MATCH", "truck*", "IDS"}, {"[0 [truck1 truck2]]"},
|
||||
{"SCAN", "fleet", "MATCH", "luck*", "IDS"}, {"[0 [luck1 luck2]]"},
|
||||
{"SCAN", "fleet", "MATCH", "*2", "IDS"}, {"[0 [luck2 truck2]]"},
|
||||
{"SCAN", "fleet", "MATCH", "*2*", "IDS"}, {"[0 [luck2 truck2]]"},
|
||||
{"SCAN", "fleet", "MATCH", "*u*", "IDS"}, {"[0 [luck1 luck2 truck1 truck2]]"},
|
||||
|
||||
{"NEARBY", "fleet", "IDS", "POINT", 33.00005, -112.00005, 100000}, {
|
||||
match("[0 [luck1 luck2 truck1 truck2]]"),
|
||||
},
|
||||
{"NEARBY", "fleet", "MATCH", "*", "IDS", "POINT", 33.00005, -112.00005, 100000}, {
|
||||
match("[0 [luck1 luck2 truck1 truck2]]"),
|
||||
},
|
||||
{"NEARBY", "fleet", "MATCH", "t*", "IDS", "POINT", 33.00005, -112.00005, 100000}, {
|
||||
match("[0 [truck1 truck2]]"),
|
||||
},
|
||||
{"NEARBY", "fleet", "MATCH", "t*2", "IDS", "POINT", 33.00005, -112.00005, 100000}, {
|
||||
match("[0 [truck2]]"),
|
||||
},
|
||||
{"NEARBY", "fleet", "MATCH", "*2", "IDS", "POINT", 33.00005, -112.00005, 100000}, {
|
||||
match("[0 [luck2 truck2]]"),
|
||||
},
|
||||
|
||||
{"INTERSECTS", "fleet", "IDS", "BOUNDS", 33, -113, 34, -112}, {
|
||||
match("[0 [luck1 luck2 truck1 truck2]]"),
|
||||
},
|
||||
{"INTERSECTS", "fleet", "MATCH", "*", "IDS", "BOUNDS", 33, -113, 34, -112}, {
|
||||
match("[0 [luck1 luck2 truck1 truck2]]"),
|
||||
},
|
||||
{"INTERSECTS", "fleet", "MATCH", "t*", "IDS", "BOUNDS", 33, -113, 34, -112}, {
|
||||
match("[0 [truck1 truck2]]"),
|
||||
},
|
||||
{"INTERSECTS", "fleet", "MATCH", "t*2", "IDS", "BOUNDS", 33, -113, 34, -112}, {
|
||||
match("[0 [truck2]]"),
|
||||
},
|
||||
{"INTERSECTS", "fleet", "MATCH", "*2", "IDS", "BOUNDS", 33, -113, 34, -112}, {
|
||||
match("[0 [luck2 truck2]]"),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// match sorts the response and compares to the expected input
|
||||
func match(expectIn string) func(org, v interface{}) (resp, expect interface{}) {
|
||||
return func(v, org interface{}) (resp, expect interface{}) {
|
||||
sort.Slice(org.([]interface{})[1], func(i, j int) bool {
|
||||
return org.([]interface{})[1].([]interface{})[i].(string) <
|
||||
org.([]interface{})[1].([]interface{})[j].(string)
|
||||
})
|
||||
return fmt.Sprintf("%v", org), expectIn
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,12 +226,24 @@ func (mc *mockServer) DoExpect(expect interface{}, commandName string, args ...i
|
|||
resp = string([]byte(b))
|
||||
}
|
||||
}
|
||||
err = func() (err error) {
|
||||
defer func() {
|
||||
v := recover()
|
||||
if v != nil {
|
||||
err = fmt.Errorf("panic '%v'", v)
|
||||
}
|
||||
}()
|
||||
if fn, ok := expect.(func(v, org interface{}) (resp, expect interface{})); ok {
|
||||
resp, expect = fn(resp, oresp)
|
||||
}
|
||||
if fn, ok := expect.(func(v interface{}) (resp, expect interface{})); ok {
|
||||
resp, expect = fn(resp)
|
||||
}
|
||||
return nil
|
||||
}()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fmt.Sprintf("%v", resp) != fmt.Sprintf("%v", expect) {
|
||||
return fmt.Errorf("expected '%v', got '%v'", expect, resp)
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
package tests
|
Loading…
Reference in New Issue