mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
Add optional config file parser in addition to environment variables
This commit is contained in:
parent
bb720c87c1
commit
f7b7b63e3f
8 changed files with 599 additions and 251 deletions
|
@ -5,20 +5,12 @@
|
|||
package config // import "miniflux.app/config"
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetBooleanValueWithUnsetVariable(t *testing.T) {
|
||||
os.Clearenv()
|
||||
if getBooleanValue("MY_TEST_VARIABLE") {
|
||||
t.Errorf(`Unset variables should returns false`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBooleanValue(t *testing.T) {
|
||||
func TestParseBoolValue(t *testing.T) {
|
||||
scenarios := map[string]bool{
|
||||
"": false,
|
||||
"": true,
|
||||
"1": true,
|
||||
"Yes": true,
|
||||
"yes": true,
|
||||
|
@ -31,49 +23,39 @@ func TestGetBooleanValue(t *testing.T) {
|
|||
}
|
||||
|
||||
for input, expected := range scenarios {
|
||||
os.Clearenv()
|
||||
os.Setenv("MY_TEST_VARIABLE", input)
|
||||
result := getBooleanValue("MY_TEST_VARIABLE")
|
||||
result := parseBool(input, true)
|
||||
if result != expected {
|
||||
t.Errorf(`Unexpected result for %q, got %v instead of %v`, input, result, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetStringValueWithUnsetVariable(t *testing.T) {
|
||||
os.Clearenv()
|
||||
if getStringValue("MY_TEST_VARIABLE", "defaultValue") != "defaultValue" {
|
||||
func TestParseStringValueWithUnsetVariable(t *testing.T) {
|
||||
if parseString("", "defaultValue") != "defaultValue" {
|
||||
t.Errorf(`Unset variables should returns the default value`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetStringValue(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("MY_TEST_VARIABLE", "test")
|
||||
if getStringValue("MY_TEST_VARIABLE", "defaultValue") != "test" {
|
||||
func TestParseStringValue(t *testing.T) {
|
||||
if parseString("test", "defaultValue") != "test" {
|
||||
t.Errorf(`Defined variables should returns the specified value`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetIntValueWithUnsetVariable(t *testing.T) {
|
||||
os.Clearenv()
|
||||
if getIntValue("MY_TEST_VARIABLE", 42) != 42 {
|
||||
func TestParseIntValueWithUnsetVariable(t *testing.T) {
|
||||
if parseInt("", 42) != 42 {
|
||||
t.Errorf(`Unset variables should returns the default value`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetIntValueWithInvalidInput(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("MY_TEST_VARIABLE", "invalid integer")
|
||||
if getIntValue("MY_TEST_VARIABLE", 42) != 42 {
|
||||
func TestParseIntValueWithInvalidInput(t *testing.T) {
|
||||
if parseInt("invalid integer", 42) != 42 {
|
||||
t.Errorf(`Invalid integer should returns the default value`)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetIntValue(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("MY_TEST_VARIABLE", "2018")
|
||||
if getIntValue("MY_TEST_VARIABLE", 42) != 2018 {
|
||||
func TestParseIntValue(t *testing.T) {
|
||||
if parseInt("2018", 42) != 2018 {
|
||||
t.Errorf(`Defined variables should returns the specified value`)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue