2019-06-02 03:18:09 +02:00
|
|
|
// Copyright 2019 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.
|
|
|
|
|
|
|
|
package config // import "miniflux.app/config"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
func TestParseBoolValue(t *testing.T) {
|
2019-06-02 03:18:09 +02:00
|
|
|
scenarios := map[string]bool{
|
2019-06-03 03:20:59 +02:00
|
|
|
"": true,
|
2019-06-02 03:18:09 +02: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-03 03:20:59 +02:00
|
|
|
result := parseBool(input, true)
|
2019-06-02 03:18:09 +02:00
|
|
|
if result != expected {
|
|
|
|
t.Errorf(`Unexpected result for %q, got %v instead of %v`, input, result, expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
func TestParseStringValueWithUnsetVariable(t *testing.T) {
|
|
|
|
if parseString("", "defaultValue") != "defaultValue" {
|
2019-06-02 03:18:09 +02:00
|
|
|
t.Errorf(`Unset variables should returns the default value`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
func TestParseStringValue(t *testing.T) {
|
|
|
|
if parseString("test", "defaultValue") != "test" {
|
2019-06-02 03:18:09 +02:00
|
|
|
t.Errorf(`Defined variables should returns the specified value`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
func TestParseIntValueWithUnsetVariable(t *testing.T) {
|
|
|
|
if parseInt("", 42) != 42 {
|
2019-06-02 03:18:09 +02:00
|
|
|
t.Errorf(`Unset variables should returns the default value`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
func TestParseIntValueWithInvalidInput(t *testing.T) {
|
|
|
|
if parseInt("invalid integer", 42) != 42 {
|
2019-06-02 03:18:09 +02:00
|
|
|
t.Errorf(`Invalid integer should returns the default value`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-03 03:20:59 +02:00
|
|
|
func TestParseIntValue(t *testing.T) {
|
|
|
|
if parseInt("2018", 42) != 2018 {
|
2019-06-02 03:18:09 +02:00
|
|
|
t.Errorf(`Defined variables should returns the specified value`)
|
|
|
|
}
|
|
|
|
}
|