aboutsummaryrefslogtreecommitdiffhomepage
path: root/model
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2017-11-26 15:07:59 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2017-11-26 15:07:59 -0800
commit8781648af9f730d8bd1a7d9c395c1f28f9058716 (patch)
treea6c0c68a6864c56b5c35401c3e748310e5eafe80 /model
parent51f77754660ddcd29f61be293a8e405d8cd3ba18 (diff)
Add integration tests for entries
Diffstat (limited to 'model')
-rw-r--r--model/entry.go13
-rw-r--r--model/entry_test.go14
2 files changed, 27 insertions, 0 deletions
diff --git a/model/entry.go b/model/entry.go
index 1053130..79a3bcb 100644
--- a/model/entry.go
+++ b/model/entry.go
@@ -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" {
diff --git a/model/entry_test.go b/model/entry_test.go
index 3f2e196..2f8c25d 100644
--- a/model/entry_test.go
+++ b/model/entry_test.go
@@ -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"`)