-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain_test.go
More file actions
42 lines (35 loc) · 944 Bytes
/
main_test.go
File metadata and controls
42 lines (35 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package rupture
import (
"strconv"
"testing"
"github.com/blevesearch/bleve/v2"
"github.com/stretchr/testify/assert"
)
// vehicle an example struct for testing.
type vehicle struct {
NumWheels int
MaxSpeed int
}
// add a collection of vehicles for testing
func addVehicles(t *testing.T, index func(string, interface{}) error) {
for i := 0; i < 30; i++ {
assert.NoError(t, index(strconv.Itoa(i), &vehicle{
NumWheels: i % 3,
MaxSpeed: i,
}))
}
}
// search request for vehicles with one wheel, and a max speed of at least 10
func vehicleSearchRequest() *bleve.SearchRequest {
one := float64(1)
two := float64(2)
numWheelsQuery := bleve.NewNumericRangeQuery(&one, &two)
numWheelsQuery.SetField("NumWheels")
ten := float64(10)
maxSpeedQuery := bleve.NewNumericRangeQuery(&ten, nil)
maxSpeedQuery.SetField("MaxSpeed")
return bleve.NewSearchRequest(bleve.NewConjunctionQuery(
numWheelsQuery,
maxSpeedQuery,
))
}