[8.15](backport #5361) Fix TestEnvWithDefault and TestContainerCMDEventToStderr #5459
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.
What does this PR do?
This PR fixes two tests:
TestEnvWithDefault
Now TestEnvWithDefault unsets all environment variables it sets,
allowing it to be run multiple times using
-count
.TestContainerCMDEventToStderr
TestContainerCMDEventToStderr did not call agentFixture.Prepare early
enough leading to an empty STATE_PATH env var, so all state
information was in /usr/share/elastic-agent, which could make
subsequent tests to fail because they could read
/usr/share/elastic-agent/state/container-paths.yml and use a state
path different than the one set in the test.
Why is it important?
It fixes tests and prevents TestEventLogOutputConfiguredViaFleet from being flaky.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration filesI have added an entry in./changelog/fragments
using the changelog toolDisruptive User Impact
There is no disruptive user impact because this PR only updates tests.
How to test this PR locally
Testing the fix in TestContainerCMDEventToStderr
/usr/share/elastic-agent
does not existTestEnvWithDefault
Make sure the test succeeds
Related issues
Questions to ask yourself
This is an automatic backport of pull request #5361 done by [Mergify](https://mergify.com).