-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use environment variables when error is strict #731
base: master
Are you sure you want to change the base?
Changes from 3 commits
ede34b6
53b7048
ba1475e
eab066c
99cfc08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I'm mildly worried about setting and unsetting environment variables in tests that could run parallel with other things (even though you don't use Cc @aditya-stripe for a second opinion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for reviewing this! Environment variables are in effect global variables, and these IMO should be accessed only from the most exterior layer of the app, and then passed as arguments to more interior layers. Having a package with "constants" might be helpful if we don't want to "pollute" the signatures of the functions. In Go I know this cannot be enforced at compile time since |
||
|
||
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 | ||
|
@@ -51,6 +63,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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oufff, that's a good catch!