Tests
This commit is contained in:
@ -98,4 +98,34 @@ func TestGetFilterFields(t *testing.T) {
|
|||||||
assert.Equal(t, createdTime, result[10].value.Elem().Interface())
|
assert.Equal(t, createdTime, result[10].value.Elem().Interface())
|
||||||
assert.Equal(t, "created_at,LT", result[10].tagValue)
|
assert.Equal(t, "created_at,LT", result[10].tagValue)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Skip nil fields", func(t *testing.T) {
|
||||||
|
type TestFilter struct {
|
||||||
|
Alive *bool `filterfield:"alive,EQ"`
|
||||||
|
Id *int64 `filterfield:"id,EQ"`
|
||||||
|
Ids *[]uint `filterfield:"id,IN"`
|
||||||
|
IdsNot *[]uint `filterfield:"id,NOT_IN"`
|
||||||
|
FirstName *string `filterfield:"first_name,EQ"`
|
||||||
|
}
|
||||||
|
filter := TestFilter{}
|
||||||
|
result := getFilterFields(filter)
|
||||||
|
assert.Equal(t, 0, len(result))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Skip fields without filterfield tag", func(t *testing.T) {
|
||||||
|
var (
|
||||||
|
alive bool = true
|
||||||
|
id int64 = 123456
|
||||||
|
)
|
||||||
|
type TestFilter struct {
|
||||||
|
Alive *bool
|
||||||
|
Id *int64 `funnytag:"created_at,LT"`
|
||||||
|
}
|
||||||
|
filter := TestFilter{
|
||||||
|
Alive: &alive,
|
||||||
|
Id: &id,
|
||||||
|
}
|
||||||
|
result := getFilterFields(filter)
|
||||||
|
assert.Equal(t, 0, len(result))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user