2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2019-06-01 21:18:09 -04:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package config // import "miniflux.app/v2/internal/config"
|
2019-06-01 21:18:09 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-06-02 21:20:59 -04:00
|
|
|
func TestParseBoolValue(t *testing.T) {
|
2019-06-01 21:18:09 -04:00
|
|
|
scenarios := map[string]bool{
|
2019-06-02 21:20:59 -04:00
|
|
|
"": true,
|
2019-06-01 21:18:09 -04:00
|
|
|
"1": true,
|
|
|
|
"Yes": true,
|
|
|
|
"yes": true,
|
|
|
|
"True": true,
|
|
|
|
"true": true,
|
|
|
|
"on": true,
|
|
|
|
"false": false,
|
|
|
|
"off": false,
|
|
|
|
"invalid": false,
|
|
|
|
}
|
|
|
|
|
|
|
|
for input, expected := range scenarios {
|
2019-06-02 21:20:59 -04:00
|
|
|
result := parseBool(input, true)
|
2019-06-01 21:18:09 -04:00
|
|
|
if result != expected {
|
|
|
|
t.Errorf(`Unexpected result for %q, got %v instead of %v`, input, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 21:20:59 -04:00
|
|
|
func TestParseStringValueWithUnsetVariable(t *testing.T) {
|
|
|
|
if parseString("", "defaultValue") != "defaultValue" {
|
2019-06-01 21:18:09 -04:00
|
|
|
t.Errorf(`Unset variables should returns the default value`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 21:20:59 -04:00
|
|
|
func TestParseStringValue(t *testing.T) {
|
|
|
|
if parseString("test", "defaultValue") != "test" {
|
2019-06-01 21:18:09 -04:00
|
|
|
t.Errorf(`Defined variables should returns the specified value`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 21:20:59 -04:00
|
|
|
func TestParseIntValueWithUnsetVariable(t *testing.T) {
|
|
|
|
if parseInt("", 42) != 42 {
|
2019-06-01 21:18:09 -04:00
|
|
|
t.Errorf(`Unset variables should returns the default value`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 21:20:59 -04:00
|
|
|
func TestParseIntValueWithInvalidInput(t *testing.T) {
|
|
|
|
if parseInt("invalid integer", 42) != 42 {
|
2019-06-01 21:18:09 -04:00
|
|
|
t.Errorf(`Invalid integer should returns the default value`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 21:20:59 -04:00
|
|
|
func TestParseIntValue(t *testing.T) {
|
|
|
|
if parseInt("2018", 42) != 2018 {
|
2019-06-01 21:18:09 -04:00
|
|
|
t.Errorf(`Defined variables should returns the specified value`)
|
|
|
|
}
|
|
|
|
}
|