diff --git a/config_parse.go b/config_parse.go index d6ba8ea28..dc56a6153 100644 --- a/config_parse.go +++ b/config_parse.go @@ -136,7 +136,7 @@ func readConfig(r io.Reader) (Config, error) { } unmarshalErr := unmarshalSemiStrictly(bts, &c) if unmarshalErr != nil { - if _, ok := err.(*UnknownConfigKeys); !ok { + if _, ok := unmarshalErr.(*UnknownConfigKeys); !ok { return c, unmarshalErr } } diff --git a/config_test.go b/config_test.go index 08990f2a4..c24a0942d 100644 --- a/config_test.go +++ b/config_test.go @@ -35,6 +35,18 @@ func TestReadBadConfig(t *testing.T) { assert.Equal(t, c, Config{}, "Parsing invalid config file should return zero struct") } +func TestReadBadConfig_EnvVarsAreNotRead(t *testing.T) { + os.Setenv("VENEUR_HOSTNAME", "cux") + defer os.Unsetenv("VENEUR_HOSTNAME") + + const exampleConfig = `--- api_hostname: :bad` + r := strings.NewReader(exampleConfig) + c, err := readConfig(r) + + assert.NotNil(t, err, "Should have encountered parsing error when reading invalid config file") + assert.Equal(t, c, Config{}, "Parsing invalid config file should return zero struct") +} + func TestReadUnknownKeysConfig(t *testing.T) { const config = `--- no_such_key: 1 @@ -49,6 +61,23 @@ hostname: foobar assert.Equal(t, "foobar", c.Hostname) } +func TestReadUnknownKeysConfig_EnvVarsAreParsed(t *testing.T) { + os.Setenv("VENEUR_HOSTNAME", "cux") + defer os.Unsetenv("VENEUR_HOSTNAME") + + const config = `--- +no_such_key: 1 +hostname: foobar +` + r := strings.NewReader(config) + c, err := readConfig(r) + assert.Error(t, err) + _, ok := err.(*UnknownConfigKeys) + t.Log(err) + assert.True(t, ok, "Returned error should indicate a strictness error") + assert.Equal(t, "cux", c.Hostname) +} + func TestReadUnknownKeysProxyConfig(t *testing.T) { const config = `--- no_such_key: 1