diff --git a/config/config.go b/config/config.go index c1d6241a..2479fbf7 100644 --- a/config/config.go +++ b/config/config.go @@ -59,7 +59,6 @@ func (e ValidationError) Error() string { func LoadConfiguration[T any](cfg *T, opts ...ConfigOption[T]) error { configYamlDir := defaultConfigYamlDir if len(os.Getenv("CONFIG_YAML_DIRECTORY")) > 0 { - fmt.Println("CONFIG_YAML_DIRECTORY", os.Getenv("CONFIG_YAML_DIRECTORY")) configYamlDir = os.Getenv("CONFIG_YAML_DIRECTORY") } @@ -75,8 +74,6 @@ func LoadConfiguration[T any](cfg *T, opts ...ConfigOption[T]) error { } } - // TODO: apply defaults? - loader.populateConfiguration(cfg) for _, fn := range loader.ConfigEditors { @@ -184,6 +181,7 @@ func evaluateConfigWithEnv(configFile io.Reader, writers ...io.Writer) (io.Reade return nil, fmt.Errorf("unable to read the config file: %w", err) } + // t := template.New("appConfigTemplate").Option("missingkey=zero") t := template.New("appConfigTemplate") tmpl, err := t.Parse(string(b)) if err != nil { diff --git a/config/config_test.go b/config/config_test.go index d6d92e3a..595d9ebc 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -38,4 +38,21 @@ blah2=test2` b, err := io.ReadAll(eval) r.NoError(err) r.Equal(expected, string(b)) + r.Equal(true, false) +} + +func TesEvaluateConfigWithMissingEnv(t *testing.T) { + r := require.New(t) + test := `blah={{.ENV1}} +blah2={{.ENV2}}` + os.Setenv("ENV1", "test1") + defer os.Unsetenv("ENV1") + + eval, err := evaluateConfigWithEnv(strings.NewReader(test)) + r.NoError(err) + expected := `blah=test1 +blah2=` + b, err := io.ReadAll(eval) + r.NoError(err) + r.Equal(expected, string(b)) }