-
Notifications
You must be signed in to change notification settings - Fork 979
test(opentelemetry-configuration): simplify management of environment variables #6004
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6004 +/- ##
=======================================
Coverage 95.22% 95.22%
=======================================
Files 311 311
Lines 8603 8603
Branches 1801 1801
=======================================
Hits 8192 8192
Misses 411 411 🚀 New features to boost your workflow:
|
maryliag
left a comment
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.
Thanks for the improvement, it's a great idea so we don't forget any variables 😄
I added a suggestion, because we might evolve those tests and need some pre determined variables. This way you save the original values (doesn't need to be inside a before), and restore after every test
| before(function () { | ||
| process.env = {}; | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| process.env = {}; | ||
| }); |
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.
| before(function () { | |
| process.env = {}; | |
| }); | |
| afterEach(function () { | |
| process.env = {}; | |
| }); | |
| const _origEnvVariables = process.env | |
| afterEach(function () { | |
| process.env = _origEnvVariables; | |
| }); |
… variables The ConfigProvider tests were deleting a number of environment variables after every test, and this logic was duplicated in a few places. This is a bit error prone. The tests seem to pass with a clean process.env provided to each test, and Mocha's afterEach() hook is inherited, so the logic can be simplified a good bit while maintaining semantics.
|
I've made the suggested changes, with a few notes:
|
PR open-telemetry#6004 simplified the environment restoration logic after each test. However, process.env is a special object that converts all of its values to strings automatically. That behavior was lost in open-telemetry#6004, which could potentially lead to surprising behavior. This commit changes the process.env restoration logic to maintain the original special object.
Which problem is this PR solving?
The
ConfigProvidertests were deleting a number of environment variables after every test, and this logic was duplicated in a few places. This is a bit error prone.Fixes # N/A
Short description of the changes
The tests seem to pass with a clean
process.envprovided to each test, and Mocha'safterEach()hook is inherited, so the logic can be simplified a good bit while maintaining semantics.Type of change
How Has This Been Tested?
Checklist: