Skip to content

Commit

Permalink
make test fail
Browse files Browse the repository at this point in the history
  • Loading branch information
hspitzley-czi committed Mar 6, 2024
1 parent df90821 commit b57589a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 1 addition & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit b57589a

Please sign in to comment.