mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-10-08 20:03:05 -04:00
refactor(config): keep the re-export a function, pin env expansion in the test
This commit is contained in:
1 parent
87fb14eb5d
commit
44dba933b7
3 files changed
+14
-8
No files matched your search
@@ -16,7 +16,7 @@ import (
|
||||
// decoderConfigTagName sets the tag name to be used from the config structs
|
||||
// currently we only support "yaml" because we only support config loading
|
||||
// from yaml files and the yaml parser has no simple way to set a custom tag name to use
|
||||
var decoderConfigTagName = "yaml"
|
||||
const decoderConfigTagName = "yaml"
|
||||
|
||||
// BindSourcesToStructs assigns any config value from a config file / env variable to struct `dst`.
|
||||
func BindSourcesToStructs(service string, dst any) error {
|
||||
@@ -42,6 +42,8 @@ func BindSourcesToStructsFS(fileSystem fs.FS, filePath, service string, dst any)
|
||||
|
||||
return err
|
||||
}
|
||||
// the error is ignored on purpose, matching the pre-extraction behavior:
|
||||
// an unparseable yaml file binds nothing instead of failing the startup
|
||||
_ = cnf.LoadSources("yaml", yamlContent)
|
||||
|
||||
err = cnf.BindStruct("", &dst)
|
||||
|
||||
@@ -14,11 +14,13 @@ type TestConfig struct {
|
||||
}
|
||||
|
||||
func TestBindSourcesToStructs(t *testing.T) {
|
||||
// setup test env
|
||||
// setup test env: one var set to pin env expansion, two deliberately
|
||||
// unset to pin the defaults
|
||||
t.Setenv("BINDER_TEST_SET_VAR", "from-env")
|
||||
yaml := `
|
||||
a: "${FOO_VAR|no-foo}"
|
||||
b: "${BAR_VAR|no-bar}"
|
||||
c: "${CODE_VAR|code}"
|
||||
a: "${BINDER_TEST_SET_VAR|no-foo}"
|
||||
b: "${BINDER_TEST_UNSET_VAR|no-bar}"
|
||||
c: "${BINDER_TEST_OTHER_UNSET_VAR|code}"
|
||||
`
|
||||
filePath := "etc/opencloud/foo.yaml"
|
||||
fs := fstest.MapFS{
|
||||
@@ -31,7 +33,7 @@ c: "${CODE_VAR|code}"
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, c.A, "no-foo")
|
||||
assert.Equal(t, c.A, "from-env")
|
||||
assert.Equal(t, c.B, "no-bar")
|
||||
assert.Equal(t, c.C, "code")
|
||||
}
|
||||
|
||||
@@ -7,8 +7,10 @@ import (
|
||||
)
|
||||
|
||||
// BindSourcesToStructs assigns any config value from a config file / env variable to struct `dst`.
|
||||
// Backward-compatible re-export; the implementation lives in pkg/config/binder.
|
||||
var BindSourcesToStructs = binder.BindSourcesToStructs
|
||||
// The implementation lives in pkg/config/binder.
|
||||
func BindSourcesToStructs(service string, dst any) error {
|
||||
return binder.BindSourcesToStructs(service, dst)
|
||||
}
|
||||
|
||||
// LocalEndpoint returns the local endpoint for a given protocol and address.
|
||||
// Use it when configuring the reva runtime to get a service endpoint in the same
|
||||
|
||||
Reference in new issue
Block a user