Skip to content

Commit f9ce942

Browse files
committed
Fix tests
Signed-off-by: Federico Torres <[email protected]>
1 parent 5f9726f commit f9ce942

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void writeOpenMetricsTimestamp(Writer writer, long timestampMs) throws IO
4949
writer.write(Long.toString(ms));
5050
}
5151

52-
static void writeEscapedLabelValue(Writer writer, String s) throws IOException {
52+
static void writeEscapedString(Writer writer, String s) throws IOException {
5353
// optimize for the common case where no escaping is needed
5454
int start = 0;
5555
// #indexOf is a vectorized intrinsic

prometheus-metrics-exposition-textformats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,12 @@ public void testGaugeWithDots() throws IOException {
464464
@Test
465465
public void testGaugeUTF8() throws IOException {
466466
String prometheusText =
467-
"# HELP \"gauge.name\" gauge\\ndoc\\nstr\"ing\n" +
468-
"# TYPE \"gauge.name\" gauge\n" +
469-
"{\"gauge.name\",\"name*2\"=\"val with \\\\backslash and \\\"quotes\\\"\",\"name.1\"=\"val with\\nnew line\"} +Inf\n" +
470-
"{\"gauge.name\",\"name*2\"=\"佖佥\",\"name.1\"=\"Björn\"} 3.14E42\n";
467+
"""
468+
# HELP \"gauge.name\" gauge\\ndoc\\nstr\"ing
469+
# TYPE \"gauge.name\" gauge
470+
{\"gauge.name\",\"name*2\"=\"val with \\\\backslash and \\\"quotes\\\"\",\"name.1\"=\"val with\\nnew line\"} +Inf
471+
{\"gauge.name\",\"name*2\"=\"佖佥\",\"name.1\"=\"Björn\"} 3.14E42
472+
""";
471473
PrometheusNaming.nameValidationScheme = ValidationScheme.UTF_8_VALIDATION;
472474

473475
GaugeSnapshot gauge = GaugeSnapshot.builder()
@@ -2872,26 +2874,19 @@ public void testWrite() throws IOException {
28722874
.build())
28732875
.build();
28742876

2875-
String acceptHeaderValue = "application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited";
2876-
nameEscapingScheme = EscapingScheme.fromAcceptHeader(acceptHeaderValue);
2877-
ExpositionFormatWriter protoWriter = expositionFormats.findWriter(acceptHeaderValue);
2878-
2879-
protoWriter.write(buff, MetricSnapshots.of(unknown));
2880-
byte[] out = buff.toByteArray();
2881-
assertThat(out.length).isNotEqualTo(0);
2882-
2883-
buff.reset();
2884-
2885-
acceptHeaderValue = "text/plain; version=0.0.4; charset=utf-8";
2877+
String acceptHeaderValue = "text/plain; version=0.0.4; charset=utf-8";
28862878
nameEscapingScheme = EscapingScheme.fromAcceptHeader(acceptHeaderValue);
28872879
ExpositionFormatWriter textWriter = expositionFormats.findWriter(acceptHeaderValue);
28882880

28892881
textWriter.write(buff, MetricSnapshots.of(unknown));
2890-
out = buff.toByteArray();
2882+
byte[] out = buff.toByteArray();
28912883
assertThat(out.length).isNotEqualTo(0);
28922884

2893-
String expected = "# TYPE foo_metric untyped\n" +
2894-
"foo_metric 1.234\n";
2885+
String expected =
2886+
"""
2887+
# TYPE foo_metric untyped
2888+
foo_metric 1.234
2889+
""";
28952890

28962891
assertThat(new String(out, UTF_8)).hasToString(expected);
28972892
}

prometheus-metrics-exposition-textformats/src/test/java/io/prometheus/metrics/expositionformats/TextFormatUtilTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void writeEscapedLabelValue() throws IOException {
1919

2020
private static String escape(String s) throws IOException {
2121
StringWriter writer = new StringWriter();
22-
TextFormatUtil.writeEscapedLabelValue(writer, s);
22+
TextFormatUtil.writeEscapedString(writer, s);
2323
return writer.toString();
2424
}
2525

0 commit comments

Comments
 (0)