Files
Dominik Schulz 2adc544dea [bugfix] Default to true for core.exportkeys even in substores (#2848)
* [bugfix] Default to true for core.exportkeys even in substores

This PR changes the default for core.exportkeys from false to true
in mounted substores to match the default of the global root store.

It also refactors and simplifies the config package a little bit
by removing special typed lookup methods and replacing them with
conversion helpers that can be applied to any string.

Fixes #2830

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>

* Fix config tests

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>

---------

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
2024-03-29 15:28:26 +01:00

88 lines
1.6 KiB
Go

package config
import (
"testing"
)
func TestAsBoolWithDefault(t *testing.T) {
tests := []struct {
name string
s string
def bool
expected bool
}{
{
name: "Empty string with default true",
s: "",
def: true,
expected: true,
},
{
name: "Empty string with default false",
s: "",
def: false,
expected: false,
},
{
name: "Valid string '1' with default true",
s: "1",
def: true,
expected: true,
},
{
name: "Valid string '0' with default true",
s: "0",
def: true,
expected: false,
},
// Add more test cases here
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := AsBoolWithDefault(test.s, test.def)
if result != test.expected {
t.Errorf("Expected %v, but got %v", test.expected, result)
}
})
}
}
func TestAsIntWithDefault(t *testing.T) {
tests := []struct {
name string
s string
def int
expected int
}{
{
name: "Empty string with default 0",
s: "",
def: 0,
expected: 0,
},
{
name: "Valid string '123' with default 0",
s: "123",
def: 0,
expected: 123,
},
{
name: "Invalid string 'abc' with default 0",
s: "abc",
def: 0,
expected: 0,
},
// Add more test cases here
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
result := AsIntWithDefault(test.s, test.def)
if result != test.expected {
t.Errorf("Expected %v, but got %v", test.expected, result)
}
})
}
}