refactor filterext test to table-driven
@@ -7,19 +7,27 @@ import (
"github.com/semi-technologies/weaviate/entities/models"
"github.com/semi-technologies/weaviate/entities/schema"
"github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
)
func Test_ExtractFlatFilters(t *testing.T) {
t.Parallel()
- input := &models.WhereFilter{
+ type test struct {
+ name string
+ input *models.WhereFilter
+ expectedFilter *filters.LocalFilter
+ expectedErr error
+ }
+
+ tests := []test{
+ test{
+ name: "valid int filter",
+ input: &models.WhereFilter{
Operator: "Equal",
ValueInt: ptInt(42),
Path: []string{"intField"},
- }
-
- expected := &filters.LocalFilter{Root: &filters.Clause{
+ },
+ expectedFilter: &filters.LocalFilter{Root: &filters.Clause{
Operator: filters.OperatorEqual,
On: &filters.Path{
Class: schema.AssertValidClassName("Todo"),
@@ -29,11 +37,17 @@ func Test_ExtractFlatFilters(t *testing.T) {
Value: 42,
Type: schema.DataTypeInt,
},
- }}
+ }},
+ },
+ }
- actual, err := Parse(input)
- require.Nil(t, err)
- assert.Equal(t, expected, actual)
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ filter, err := Parse(test.input)
+ assert.Equal(t, test.expectedErr, err)
+ assert.Equal(t, test.expectedFilter, filter)
+ })
+ }
}
func ptInt(in int) *int64 {
