kde-lockscreen-suspend-display/config/config_test.go

49 lines
673 B
Go

package config_test
import (
"testing"
"kdelsd/config"
)
type TestConfig struct {
INT int
BOOL bool
STR string
OTHER_STR string
}
var testConfigInstance = TestConfig{
INT: 42,
BOOL: true,
STR: "sajtok",
OTHER_STR: "default-value",
}
var testEnv = []string {
"TEST_INT=42",
"TEST_BOOL=true",
"TEST_STR=sajtok",
}
func setup() {
config.ConfigFetchMethod = func() []string {
return testEnv
}
}
func TestBuildConfig(t *testing.T) {
setup()
c := TestConfig{}
c.OTHER_STR = testConfigInstance.OTHER_STR
err := config.Build("TEST", &c)
if err != nil {
panic(err)
}
if c != testConfigInstance {
t.Errorf("%v != %v", c, testConfigInstance)
}
}