Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add tests for equal operator on arguments
  • Loading branch information
paullegranddc committed Jul 18, 2025
commit 75f6daeaab4acdc731e18c25fb03cf7cdca990d3
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static boolean doesRuleMatch(Rule rule) {
}

private static boolean matchOperator(String value, String operator, List<String> matches) {
// not sure if these are nullable, but the semantics make sense
// not sure if these are nullable, but the semantics makes sense
// and that will save us from a NPE
if (value == null || operator == null) {
return false;
Expand Down Expand Up @@ -140,6 +140,9 @@ private static boolean matchOperator(String value, String operator, List<String>
// We do all of the case insensitivity modifications in this function, because each selector will
// be viewed just once
static boolean selectorMatch(String origin, List<String> matches, String operator, String key) {
if (operator == null) {
return false;
}
operator = operator.toLowerCase();
switch (origin.toLowerCase()) {
case "language":
Expand All @@ -152,9 +155,6 @@ static boolean selectorMatch(String origin, List<String> matches, String operato
return false;
}
String envValue = System.getenv(key.toUpperCase());
if (envValue == null) {
return false;
}
return matchOperator(envValue, operator, matches);
case "process_arguments":
if (key == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ apm_configuration_rules:
injectEnvConfig("DD_PROFILING_ENABLED", "true")
injectEnvConfig("DD_SERVICE", "mysvc")
injectEnvConfig("DD_TAGS", "team:apm,component:web")
System.setProperty("arg1", "value1")

def match = StableConfigParser.selectorMatch(origin, matches, operator, key)

then:
Expand All @@ -83,6 +85,7 @@ apm_configuration_rules:
"language" | ["java"] | "exists" | "" | false
"language" | ["java"] | "something unexpected" | "" | false
"environment_variables" | [] | "exists" | "DD_TAGS" | true
"environment_variables" | null | "exists" | "DD_TAGS" | true
"environment_variables" | ["team:apm"] | "contains" | "DD_TAGS" | true
"ENVIRONMENT_VARIABLES" | ["TeAm:ApM"] | "CoNtAiNs" | "Dd_TaGs" | true // check case insensitivity
"environment_variables" | ["team:apm"] | "equals" | "DD_TAGS" | false
Expand All @@ -96,6 +99,13 @@ apm_configuration_rules:
"environment_variables" | ["svc"] | "contains" | "DD_SERVICE" | true
"environment_variables" | ["other"] | "contains" | "DD_SERVICE" | false
"environment_variables" | [null] | "contains" | "DD_SERVICE" | false
"environment_variables" | [] | "equals" | null | false
"environment_variables" | null | "equals" | "DD_SERVICE" | false
"language" | ["java"] | null | "" | false
"process_arguments" | null | "exists" | "-Darg1" | true
"process_arguments" | null | "exists" | "-Darg2" | false
"process_arguments" | ["value1"] | "equals" | "-Darg1" | true
"process_arguments" | ["value2"] | "equals" | "-Darg1" | false
}

def "test duplicate entries not allowed"() {
Expand Down
Loading