-
Notifications
You must be signed in to change notification settings - Fork 323
Refactors environment variables handling to make it testable. #9586
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
Merged
AlexeyKuznetsov-DD
merged 13 commits into
master
from
alexeyk/refactored-env-vars-to-be-testable
Oct 10, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
401b3cb
Refactored EnvironmentVariables to be testable.
AlexeyKuznetsov-DD 4003775
Merge branch 'master' into alexeyk/refactored-env-vars-to-be-testable
AlexeyKuznetsov-DD 10d4bdf
Merge branch 'master' into alexeyk/refactored-env-vars-to-be-testable
AlexeyKuznetsov-DD 348f975
WIP.
AlexeyKuznetsov-DD a0be629
Merge branch 'master' into alexeyk/refactored-env-vars-to-be-testable
mhlidd 335f9f2
Merge branch 'master' into alexeyk/refactored-env-vars-to-be-testable
AlexeyKuznetsov-DD cc64b43
Merge branch 'master' into alexeyk/refactored-env-vars-to-be-testable
AlexeyKuznetsov-DD ca04c39
Applied review comments.
AlexeyKuznetsov-DD d230400
Merge branch 'master' into alexeyk/refactored-env-vars-to-be-testable
AlexeyKuznetsov-DD 3e00962
Merge branch 'master' into alexeyk/refactored-env-vars-to-be-testable
AlexeyKuznetsov-DD dd97aa0
Merge branch 'master' into alexeyk/refactored-env-vars-to-be-testable
AlexeyKuznetsov-DD d8b5aec
Merge branch 'master' into alexeyk/refactored-env-vars-to-be-testable
AlexeyKuznetsov-DD 06b8d5d
Merge branch 'master' into alexeyk/refactored-env-vars-to-be-testable
AlexeyKuznetsov-DD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ | |
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
| import static utils.TestHelper.setEnvVar; | ||
| import static utils.TestHelper.setFieldInConfig; | ||
|
|
||
| import com.datadog.debugger.util.RemoteConfigHelper; | ||
|
|
@@ -22,6 +21,7 @@ | |
| import datadog.trace.api.Config; | ||
| import datadog.trace.api.git.GitInfoProvider; | ||
| import datadog.trace.bootstrap.instrumentation.api.Tags; | ||
| import datadog.trace.test.util.ControllableEnvironmentVariables; | ||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
|
|
@@ -54,6 +54,8 @@ public class DebuggerAgentTest { | |
| final MockWebServer server = new MockWebServer(); | ||
| HttpUrl url; | ||
|
|
||
| private ControllableEnvironmentVariables env = ControllableEnvironmentVariables.setup(); | ||
|
|
||
| private static void setFieldInContainerInfo( | ||
| ContainerInfo containerInfo, String fieldName, Object value) { | ||
| try { | ||
|
|
@@ -67,6 +69,7 @@ private static void setFieldInContainerInfo( | |
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| env.clear(); | ||
| url = server.url(URL_PATH); | ||
| } | ||
|
|
||
|
|
@@ -175,14 +178,14 @@ public void tags() { | |
| when(config.getGlobalTags()).thenReturn(globalTags); | ||
| // set env vars now to be cached by GitInfoProvider | ||
| GitInfoProvider.INSTANCE.invalidateCache(); | ||
| setEnvVar("DD_GIT_COMMIT_SHA", "sha1"); | ||
| setEnvVar("DD_GIT_REPOSITORY_URL", "http://github.com"); | ||
| env.set("DD_GIT_COMMIT_SHA", "sha1"); | ||
| env.set("DD_GIT_REPOSITORY_URL", "http://github.com"); | ||
|
Comment on lines
+181
to
+182
Contributor
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. 🎯 suggestion: This is typically the kind of test that should be migrated to be tested using config mocked value, not environment variables. |
||
| String tags; | ||
| try { | ||
| tags = DebuggerAgent.getDefaultTagsMergedWithGlobalTags(config); | ||
| } finally { | ||
| setEnvVar("DD_GIT_COMMIT_SHA", null); | ||
| setEnvVar("DD_GIT_REPOSITORY_URL", null); | ||
| env.set("DD_GIT_COMMIT_SHA", null); | ||
| env.set("DD_GIT_REPOSITORY_URL", null); | ||
| GitInfoProvider.INSTANCE.invalidateCache(); | ||
| } | ||
| Map<String, String> resultTags = new HashMap<>(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.