Skip to content

Commit 69fdfff

Browse files
authored
fix: Fixed golden file test framework (#1540)
Signed-off-by: dhoard <doug.hoard@gmail.com>
1 parent 3b062c3 commit 69fdfff

10,982 files changed

Lines changed: 27504 additions & 10898 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/environment/PrefixConsumer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ public static Consumer<OutputFrame> of(String prefix, String image) {
5151
if (!ENABLED) {
5252
return NOOP;
5353
}
54-
return frame -> System.out.println("[" + prefix + "] " + image + " | " + frame.utf8StringWithoutLineEnding());
54+
String label = "[" + prefix + "] " + image + " | ";
55+
return frame -> {
56+
String[] lines = frame.utf8String().split("\r\n|\n", -1);
57+
for (String line : lines) {
58+
String trimmed = line.stripTrailing();
59+
if (!trimmed.isEmpty()) {
60+
System.out.println(label + trimmed);
61+
}
62+
}
63+
};
5564
}
5665

5766
private static boolean resolveEnabled() {

integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricsAssertions.java

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,87 @@ private static boolean isNumeric(String s) {
787787
}
788788
}
789789

790+
/**
791+
* Tests whether an actual value matches a glob pattern containing zero or more
792+
* {@code *} wildcards. Each {@code *} matches zero or more characters. All other
793+
* characters are matched literally.
794+
*
795+
* <p>Examples:
796+
* <ul>
797+
* <li>{@code "*"} matches any value
798+
* <li>{@code "prefix*"} matches values starting with {@code "prefix"}
799+
* <li>{@code "*suffix"} matches values ending with {@code "suffix"}
800+
* <li>{@code "*middle*"} matches values containing {@code "middle"}
801+
* <li>{@code "*a*b*c*"} matches values containing {@code "a"}, then {@code "b"}, then {@code "c"} in order
802+
* </ul>
803+
*
804+
* @param pattern the glob pattern
805+
* @param value the actual label value to test
806+
* @return {@code true} if the value matches the pattern
807+
*/
808+
/**
809+
* Cache of compiled glob patterns to avoid recompilation.
810+
*/
811+
private static final Map<String, java.util.regex.Pattern> GLOB_CACHE =
812+
new java.util.concurrent.ConcurrentHashMap<>();
813+
814+
/**
815+
* Tests whether an actual value matches a glob pattern containing zero or more
816+
* {@code *} wildcards. Each {@code *} matches zero or more characters. All other
817+
* characters are matched literally.
818+
*
819+
* <p>The glob pattern is converted to a regex internally. Patterns are cached
820+
* for reuse.
821+
*
822+
* <p>Examples:
823+
* <ul>
824+
* <li>{@code "*"} matches any value
825+
* <li>{@code "prefix*"} matches values starting with {@code "prefix"}
826+
* <li>{@code "*suffix"} matches values ending with {@code "suffix"}
827+
* <li>{@code "*middle*"} matches values containing {@code "middle"}
828+
* <li>{@code "*a*b*c*"} matches values containing {@code "a"}, then {@code "b"}, then {@code "c"} in order
829+
* </ul>
830+
*
831+
* @param pattern the glob pattern
832+
* @param value the actual label value to test
833+
* @return {@code true} if the value matches the pattern
834+
*/
835+
static boolean matchesGlob(String pattern, String value) {
836+
return GLOB_CACHE
837+
.computeIfAbsent(pattern, MetricsAssertions::toRegex)
838+
.matcher(value)
839+
.matches();
840+
}
841+
842+
/**
843+
* Converts a glob pattern to a compiled regex. The glob syntax supports:
844+
* <ul>
845+
* <li>{@code *} — matches zero or more characters
846+
* <li>All other characters are matched literally
847+
* </ul>
848+
*
849+
* @param glob the glob pattern
850+
* @return the compiled regex
851+
*/
852+
private static java.util.regex.Pattern toRegex(String glob) {
853+
StringBuilder regex = new StringBuilder(glob.length() + 16);
854+
regex.append('^');
855+
for (int i = 0; i < glob.length(); i++) {
856+
char c = glob.charAt(i);
857+
if (c == '*') {
858+
regex.append(".*");
859+
} else {
860+
// Escape regex metacharacters
861+
if ("\\[{()+?.$^|".indexOf(c) >= 0) {
862+
regex.append('\\');
863+
}
864+
regex.append(c);
865+
}
866+
}
867+
regex.append('$');
868+
return java.util.regex.Pattern.compile(regex.toString());
869+
}
870+
790871
private static boolean updateMetricsFile() {
791872
if (Boolean.getBoolean(METRIC_ASSERTIONS_UPDATE)) {
792873
return true;
@@ -911,19 +992,8 @@ private static boolean labelsMatchExpected(
911992
if (actualValue == null) {
912993
return false;
913994
}
914-
if (expectedValue.equals("*")) {
915-
// "*" alone means any non-null value — skip check.
916-
continue;
917-
}
918-
if (expectedValue.startsWith("*")) {
919-
String suffix = expectedValue.substring(1);
920-
if (!actualValue.endsWith(suffix)) {
921-
return false;
922-
}
923-
} else {
924-
if (!actualValue.equals(expectedValue)) {
925-
return false;
926-
}
995+
if (!matchesGlob(expectedValue, actualValue)) {
996+
return false;
927997
}
928998
}
929999
return true;
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Copyright (C) The Prometheus jmx_exporter Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.prometheus.jmx.test.support.metrics;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
import java.util.stream.Stream;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.params.ParameterizedTest;
24+
import org.junit.jupiter.params.provider.Arguments;
25+
import org.junit.jupiter.params.provider.MethodSource;
26+
27+
class GlobMatcherTest {
28+
29+
@Test
30+
void singleWildcardMatchesEverything() {
31+
assertThat(MetricsAssertions.matchesGlob("*", "")).isTrue();
32+
assertThat(MetricsAssertions.matchesGlob("*", "anything")).isTrue();
33+
assertThat(MetricsAssertions.matchesGlob("*", "with spaces")).isTrue();
34+
}
35+
36+
@Test
37+
void exactMatch() {
38+
assertThat(MetricsAssertions.matchesGlob("hello", "hello")).isTrue();
39+
assertThat(MetricsAssertions.matchesGlob("hello", "hell")).isFalse();
40+
assertThat(MetricsAssertions.matchesGlob("hello", "helloo")).isFalse();
41+
assertThat(MetricsAssertions.matchesGlob("hello", "Hello")).isFalse();
42+
}
43+
44+
@Test
45+
void prefixWildcard() {
46+
assertThat(MetricsAssertions.matchesGlob("pre*", "prefix")).isTrue();
47+
assertThat(MetricsAssertions.matchesGlob("pre*", "pre")).isTrue();
48+
assertThat(MetricsAssertions.matchesGlob("pre*", "pr")).isFalse();
49+
assertThat(MetricsAssertions.matchesGlob("pre*", "other")).isFalse();
50+
}
51+
52+
@Test
53+
void suffixWildcard() {
54+
assertThat(MetricsAssertions.matchesGlob("*suf", "endsuf")).isTrue();
55+
assertThat(MetricsAssertions.matchesGlob("*suf", "suf")).isTrue();
56+
assertThat(MetricsAssertions.matchesGlob("*suf", "suffix")).isFalse();
57+
assertThat(MetricsAssertions.matchesGlob("*suf", "other")).isFalse();
58+
}
59+
60+
@Test
61+
void containsWildcard() {
62+
assertThat(MetricsAssertions.matchesGlob("*mid*", "has middle here")).isTrue();
63+
assertThat(MetricsAssertions.matchesGlob("*mid*", "middle")).isTrue();
64+
assertThat(MetricsAssertions.matchesGlob("*mid*", "mid")).isTrue();
65+
assertThat(MetricsAssertions.matchesGlob("*mid*", "no match")).isFalse();
66+
}
67+
68+
@Test
69+
void prefixAndSuffix() {
70+
assertThat(MetricsAssertions.matchesGlob("a*z", "az")).isTrue();
71+
assertThat(MetricsAssertions.matchesGlob("a*z", "abz")).isTrue();
72+
assertThat(MetricsAssertions.matchesGlob("a*z", "axyz")).isTrue();
73+
assertThat(MetricsAssertions.matchesGlob("a*z", "a")).isFalse();
74+
assertThat(MetricsAssertions.matchesGlob("a*z", "z")).isFalse();
75+
assertThat(MetricsAssertions.matchesGlob("a*z", "azb")).isFalse();
76+
}
77+
78+
@Test
79+
void multipleWildcards() {
80+
assertThat(MetricsAssertions.matchesGlob("*foo*bar", "xfooybar")).isTrue();
81+
assertThat(MetricsAssertions.matchesGlob("*foo*bar", "foobar")).isTrue();
82+
assertThat(MetricsAssertions.matchesGlob("*foo*bar", "fooxxx")).isFalse();
83+
assertThat(MetricsAssertions.matchesGlob("*foo*bar", "barfoo")).isFalse();
84+
85+
assertThat(MetricsAssertions.matchesGlob("foo*bar*", "foobarx")).isTrue();
86+
assertThat(MetricsAssertions.matchesGlob("foo*bar*", "foobar")).isTrue();
87+
assertThat(MetricsAssertions.matchesGlob("foo*bar*", "fooxbar")).isTrue();
88+
assertThat(MetricsAssertions.matchesGlob("foo*bar*", "barfoo")).isFalse();
89+
90+
assertThat(MetricsAssertions.matchesGlob("*foo*bar*", "xfooybarz")).isTrue();
91+
assertThat(MetricsAssertions.matchesGlob("*foo*bar*", "foobar")).isTrue();
92+
assertThat(MetricsAssertions.matchesGlob("*foo*bar*", "fooxbar")).isTrue();
93+
assertThat(MetricsAssertions.matchesGlob("*foo*bar*", "barfoobaz")).isFalse();
94+
}
95+
96+
@Test
97+
void threeWildcards() {
98+
assertThat(MetricsAssertions.matchesGlob("a*b*c*d", "aXbYcZd")).isTrue();
99+
assertThat(MetricsAssertions.matchesGlob("a*b*c*d", "abcd")).isTrue();
100+
assertThat(MetricsAssertions.matchesGlob("a*b*c*d", "aXbYc")).isFalse();
101+
assertThat(MetricsAssertions.matchesGlob("a*b*c*d", "bYcZd")).isFalse();
102+
}
103+
104+
@Test
105+
void allWildcards() {
106+
assertThat(MetricsAssertions.matchesGlob("*a*b*c*", "XaYbZcW")).isTrue();
107+
assertThat(MetricsAssertions.matchesGlob("*a*b*c*", "abc")).isTrue();
108+
assertThat(MetricsAssertions.matchesGlob("*a*b*c*", "aXbYc")).isTrue();
109+
assertThat(MetricsAssertions.matchesGlob("*a*b*c*", "abcW")).isTrue();
110+
assertThat(MetricsAssertions.matchesGlob("*a*b*c*", "XaYcZbW")).isFalse();
111+
assertThat(MetricsAssertions.matchesGlob("*a*b*c*", "xxx")).isFalse();
112+
assertThat(MetricsAssertions.matchesGlob("*a*b*c*", "cba")).isFalse();
113+
}
114+
115+
@Test
116+
void emptySegments() {
117+
assertThat(MetricsAssertions.matchesGlob("**", "anything")).isTrue();
118+
assertThat(MetricsAssertions.matchesGlob("a**b", "axb")).isTrue();
119+
assertThat(MetricsAssertions.matchesGlob("a**b", "ab")).isTrue();
120+
}
121+
122+
@ParameterizedTest
123+
@MethodSource("jvmVersionExamples")
124+
void jvmVersionGlobPatterns(String pattern, String value, boolean expected) {
125+
assertThat(MetricsAssertions.matchesGlob(pattern, value)).isEqualTo(expected);
126+
}
127+
128+
static Stream<Arguments> jvmVersionGlobPatterns() {
129+
return Stream.of(
130+
// Exact version (no wildcards)
131+
Arguments.of("1.8.0_492-b09", "1.8.0_492-b09", true),
132+
Arguments.of("1.8.0_492-b09", "1.8.0_502-b09", false),
133+
134+
// Any version
135+
Arguments.of("*", "25.0.3+9-LTS", true),
136+
137+
// Major version prefix
138+
Arguments.of("1.8*", "1.8.0_492-b09", true),
139+
Arguments.of("1.8*", "11.0.31+11-LTS", false),
140+
141+
// LTS suffix
142+
Arguments.of("*-LTS", "25.0.3+9-LTS", true),
143+
Arguments.of("*-LTS", "25.0.3+9", false),
144+
145+
// Contains jvmci
146+
Arguments.of("*jvmci*", "17.0.4+8-jvmci-22.3-b22", true),
147+
Arguments.of("*jvmci*", "17.0.4+8", false),
148+
149+
// Starts with major, ends with build
150+
Arguments.of("17*b09", "17.0.19+10-b09", true),
151+
Arguments.of("17*b09", "17.0.19+10-b10", false),
152+
153+
// Multiple wildcards
154+
Arguments.of("*0*LTS", "21.0.11+10-LTS", true),
155+
Arguments.of("*0*LTS", "21.0.11+10", false));
156+
}
157+
}

integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/DeveloperTest/mode/Standalone/assertions/local.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ match GAUGE jvm_memory_pool_used_bytes{pool="*Survivor Space"}
138138
match GAUGE jvm_memory_pool_used_bytes{pool="Metaspace"}
139139
match GAUGE jvm_memory_used_bytes{area="heap"}
140140
match GAUGE jvm_memory_used_bytes{area="nonheap"}
141-
match GAUGE jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Amazon.com Inc.",version="25.0.3+9-LTS"}
141+
match GAUGE jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Amazon.com Inc.",version="*"}
142142
match GAUGE jvm_threads_current
143143
match GAUGE jvm_threads_daemon
144144
match GAUGE jvm_threads_deadlocked

integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/core/AllLowerCaseWithHttpAuthSSLTest/mode/JavaAgent/assertions/adoptopenjdk_openjdk11-openj9.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ match GAUGE jvm_memory_pool_used_bytes{pool="tenured-LOA"} *
162162
match GAUGE jvm_memory_pool_used_bytes{pool="tenured-SOA"} *
163163
match GAUGE jvm_memory_used_bytes{area="heap"} *
164164
match GAUGE jvm_memory_used_bytes{area="nonheap"} *
165-
match GAUGE jvm_runtime_info{runtime="IBM Semeru Runtime Open Edition",vendor="Eclipse OpenJ9",version="11.0.26+4"} *
165+
match GAUGE jvm_runtime_info{runtime="IBM Semeru Runtime Open Edition",vendor="Eclipse OpenJ9",version="*"} *
166166
match GAUGE jvm_threads_current *
167167
match GAUGE jvm_threads_daemon *
168168
match GAUGE jvm_threads_deadlocked *

integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/core/AllLowerCaseWithHttpAuthSSLTest/mode/JavaAgent/assertions/adoptopenjdk_openjdk8-openj9.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ match GAUGE jvm_memory_pool_used_bytes{pool="tenured-LOA"} *
159159
match GAUGE jvm_memory_pool_used_bytes{pool="tenured-SOA"} *
160160
match GAUGE jvm_memory_used_bytes{area="heap"} *
161161
match GAUGE jvm_memory_used_bytes{area="nonheap"} *
162-
match GAUGE jvm_runtime_info{runtime="IBM Semeru Runtime Open Edition",vendor="Eclipse OpenJ9",version="1.8.0_442-b06"} *
162+
match GAUGE jvm_runtime_info{runtime="IBM Semeru Runtime Open Edition",vendor="Eclipse OpenJ9",version="*"} *
163163
match GAUGE jvm_threads_current *
164164
match GAUGE jvm_threads_daemon *
165165
match GAUGE jvm_threads_deadlocked *

integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/core/AllLowerCaseWithHttpAuthSSLTest/mode/JavaAgent/assertions/alibabadragonwell_dragonwell_11.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ match GAUGE jvm_memory_pool_used_bytes{pool="*Survivor Space"} *
131131
match GAUGE jvm_memory_pool_used_bytes{pool="*Gen"} *
132132
match GAUGE jvm_memory_used_bytes{area="heap"} *
133133
match GAUGE jvm_memory_used_bytes{area="nonheap"} *
134-
match GAUGE jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Alibaba",version="11.0.31.28+11"} *
134+
match GAUGE jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Alibaba",version="*"} *
135135
match GAUGE jvm_threads_current *
136136
match GAUGE jvm_threads_daemon *
137137
match GAUGE jvm_threads_deadlocked *

integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/core/AllLowerCaseWithHttpAuthSSLTest/mode/JavaAgent/assertions/alibabadragonwell_dragonwell_17.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ match GAUGE jvm_memory_pool_used_bytes{pool="*Survivor Space"} *
135135
match GAUGE jvm_memory_pool_used_bytes{pool="*Gen"} *
136136
match GAUGE jvm_memory_used_bytes{area="heap"} *
137137
match GAUGE jvm_memory_used_bytes{area="nonheap"} *
138-
match GAUGE jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Alibaba",version="17.0.17+9"} *
138+
match GAUGE jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Alibaba",version="*"} *
139139
match GAUGE jvm_threads_current *
140140
match GAUGE jvm_threads_daemon *
141141
match GAUGE jvm_threads_deadlocked *

integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/core/AllLowerCaseWithHttpAuthSSLTest/mode/JavaAgent/assertions/alibabadragonwell_dragonwell_21.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ match GAUGE jvm_memory_pool_used_bytes{pool="*Survivor Space"} *
135135
match GAUGE jvm_memory_pool_used_bytes{pool="*Gen"} *
136136
match GAUGE jvm_memory_used_bytes{area="heap"} *
137137
match GAUGE jvm_memory_used_bytes{area="nonheap"} *
138-
match GAUGE jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Alibaba",version="21.0.10.0.10"} *
138+
match GAUGE jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Alibaba",version="*"} *
139139
match GAUGE jvm_threads_current *
140140
match GAUGE jvm_threads_daemon *
141141
match GAUGE jvm_threads_deadlocked *

integration_test_suite/integration_tests/src/test/resources/io/prometheus/jmx/test/core/AllLowerCaseWithHttpAuthSSLTest/mode/JavaAgent/assertions/alibabadragonwell_dragonwell_25.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ match GAUGE jvm_memory_pool_used_bytes{pool="*Survivor Space"} *
135135
match GAUGE jvm_memory_pool_used_bytes{pool="*Gen"} *
136136
match GAUGE jvm_memory_used_bytes{area="heap"} *
137137
match GAUGE jvm_memory_used_bytes{area="nonheap"} *
138-
match GAUGE jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Alibaba",version="25.0.3.0.3"} *
138+
match GAUGE jvm_runtime_info{runtime="OpenJDK Runtime Environment",vendor="Alibaba",version="*"} *
139139
match GAUGE jvm_threads_current *
140140
match GAUGE jvm_threads_daemon *
141141
match GAUGE jvm_threads_deadlocked *

0 commit comments

Comments
 (0)