Read From Environment Variable Even If Parse File Failed #94
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Issue
#79
Motivation and Context
Full Snippet of Read Configuration section of README
Current behavior of
ReadConfig
is that it will return an error if it failed to read configuration from file and the method will not attempt to read configuration from environment variables. Thus, this statement from Read Configuration section of README is not necessarily true:Because
parseFile
does not fill the config struct with default values andreadEnvVars
is the method that will fill the config struct with default values, onceparseFile
returns an errorReadConfig
will not executereadEnvVars
. Which causes the current behavior ofReadConfig
invalidating this statement:To address the discrepancy, we decided to open this PR to update
ReadConfig
so that the method:parseFile
orreadEnvVars
returns an errorHow Has This Been Tested?
All preexisting tests passed except
unknown
subtest andparsing error
subtest forTestReadConfig
due to the behavior change we implemented forReadConfig
. Thus we modifiedunknown
andparsing error
to becomeunknown filetype fallback to env
andparsing error fallback to env
respectively. So that instead of testing to ensureReadConfig
returns an error if it failed to parse file, the updated test cases testing to ensureReadConfig
will runreadEnvVars
if it failed to parse file.Two new subtests were added to
TestReadConfig
. The first one, calledfile and env parse error
, was added to cover the case where neither the file or environment variables could be successfully read. The second one, calledparsed file and failed to parse env
, was added to cover the case whereReadConfig
is able to read from file but not able to read from environment variables.Since
readDefaults
method was added to prepopulate the config struct with default values, new test calledTestReadDefaults
, with two subtests, was added to ensure the method is properly tested.Besides
ReadConfig
and the newly createdreadDefaults
, functionalities of other methods were not modified. Thus, changes implemented in this PR should not affect other areas of this library.Checklist: