2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2021-01-04 16:49:28 -05:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package validator // import "miniflux.app/v2/internal/validator"
|
2021-01-04 16:49:28 -05:00
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestIsValidURL(t *testing.T) {
|
|
|
|
scenarios := map[string]bool{
|
|
|
|
"https://www.example.org": true,
|
|
|
|
"http://www.example.org/": true,
|
|
|
|
"www.example.org": false,
|
|
|
|
}
|
|
|
|
|
|
|
|
for link, expected := range scenarios {
|
2021-02-07 21:38:45 -05:00
|
|
|
result := IsValidURL(link)
|
2021-01-04 16:49:28 -05:00
|
|
|
if result != expected {
|
|
|
|
t.Errorf(`Unexpected result, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-04 18:32:32 -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`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateDirection(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`)
|
|
|
|
}
|
|
|
|
}
|
2021-02-07 21:38:45 -05:00
|
|
|
|
|
|
|
func TestIsValidRegex(t *testing.T) {
|
|
|
|
scenarios := map[string]bool{
|
|
|
|
"(?i)miniflux": true,
|
|
|
|
"[": false,
|
|
|
|
}
|
|
|
|
|
|
|
|
for expr, expected := range scenarios {
|
|
|
|
result := IsValidRegex(expr)
|
|
|
|
if result != expected {
|
|
|
|
t.Errorf(`Unexpected result, got %v instead of %v`, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|