mirror of
https://github.com/miniflux/v2.git
synced 2025-09-15 18:57:04 +00:00
Add integration tests for entries
This commit is contained in:
parent
51f7775466
commit
8781648af9
9 changed files with 356 additions and 43 deletions
|
@ -68,6 +68,19 @@ func ValidateDirection(direction string) error {
|
|||
return fmt.Errorf(`Invalid direction, valid direction values are: "asc" or "desc"`)
|
||||
}
|
||||
|
||||
// ValidateRange makes sure the offset/limit values are valid.
|
||||
func ValidateRange(offset, limit int) error {
|
||||
if offset < 0 {
|
||||
return fmt.Errorf(`Offset value should be >= 0`)
|
||||
}
|
||||
|
||||
if limit < 0 {
|
||||
return fmt.Errorf(`Limit value should be >= 0`)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOppositeDirection returns the opposite sorting direction.
|
||||
func GetOppositeDirection(direction string) string {
|
||||
if direction == "asc" {
|
||||
|
|
|
@ -42,6 +42,20 @@ func TestValidateEntryDirection(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestValidateRange(t *testing.T) {
|
||||
if err := ValidateRange(-1, 0); err == nil {
|
||||
t.Error(`An invalid offset should generate a error`)
|
||||
}
|
||||
|
||||
if err := ValidateRange(0, -1); err == nil {
|
||||
t.Error(`An invalid limit should generate a error`)
|
||||
}
|
||||
|
||||
if err := ValidateRange(42, 42); err != nil {
|
||||
t.Error(`A valid offset and limit should not generate any error`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOppositeDirection(t *testing.T) {
|
||||
if GetOppositeDirection("asc") != "desc" {
|
||||
t.Errorf(`The opposite direction of "asc" should be "desc"`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue