1
0
Fork 0
miniflux/model/entry_test.go

72 lines
2 KiB
Go
Raw Normal View History

2017-11-25 22:06:02 -05:00
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
2018-08-25 00:51:50 -04:00
package model // import "miniflux.app/model"
2017-11-25 22:06:02 -05:00
import "testing"
func TestValidateEntryStatus(t *testing.T) {
for _, status := range []string{EntryStatusRead, EntryStatusUnread, EntryStatusRemoved} {
if err := ValidateEntryStatus(status); err != nil {
t.Error(`A valid status should not generate any error`)
}
}
if err := ValidateEntryStatus("invalid"); err == nil {
t.Error(`An invalid status should generate a error`)
}
}
func TestValidateEntryOrder(t *testing.T) {
for _, status := range []string{"id", "status", "changed_at", "published_at", "category_title", "category_id"} {
2017-11-25 22:06:02 -05:00
if err := ValidateEntryOrder(status); err != nil {
t.Error(`A valid order should not generate any error`)
}
}
if err := ValidateEntryOrder("invalid"); err == nil {
t.Error(`An invalid order should generate a error`)
}
}
func TestValidateEntryDirection(t *testing.T) {
for _, status := range []string{"asc", "desc"} {
if err := ValidateDirection(status); err != nil {
t.Error(`A valid direction should not generate any error`)
}
}
if err := ValidateDirection("invalid"); err == nil {
t.Error(`An invalid direction should generate a error`)
}
}
2017-11-26 18:07:59 -05:00
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`)
}
}
2017-11-25 22:06:02 -05:00
func TestGetOppositeDirection(t *testing.T) {
2017-12-02 20:04:01 -05:00
if OppositeDirection("asc") != "desc" {
2017-11-25 22:06:02 -05:00
t.Errorf(`The opposite direction of "asc" should be "desc"`)
}
2017-12-02 20:04:01 -05:00
if OppositeDirection("desc") != "asc" {
2017-11-25 22:06:02 -05:00
t.Errorf(`The opposite direction of "desc" should be "asc"`)
}
2017-12-02 20:04:01 -05:00
if OppositeDirection("invalid") != "asc" {
2017-11-25 22:06:02 -05:00
t.Errorf(`An invalid direction should return "asc"`)
}
}