Skip to content

Commit 39a83b9

Browse files
authored
increase coverage (#1276)
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 60dc69d commit 39a83b9

File tree

6 files changed

+102
-9
lines changed

6 files changed

+102
-9
lines changed

prometheus-metrics-exposition-formats/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
<artifactId>protobuf-java</artifactId>
3434
<version>${protobuf-java.version}</version>
3535
</dependency>
36+
37+
<dependency>
38+
<groupId>io.prometheus</groupId>
39+
<artifactId>prometheus-metrics-exposition-textformats</artifactId>
40+
<version>${project.version}</version>
41+
<scope>test</scope>
42+
<type>test-jar</type>
43+
</dependency>
3644
</dependencies>
3745

3846
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.prometheus.metrics.expositionformats;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_29_3.Metrics;
6+
import io.prometheus.metrics.expositionformats.internal.PrometheusProtobufWriterImpl;
7+
import io.prometheus.metrics.expositionformats.internal.ProtobufUtil;
8+
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
9+
10+
class ProtobufExpositionFormatsTest extends ExpositionFormatsTest {
11+
12+
@Override
13+
protected void assertPrometheusProtobuf(String expected, MetricSnapshot snapshot) {
14+
PrometheusProtobufWriterImpl writer = new PrometheusProtobufWriterImpl();
15+
Metrics.MetricFamily protobufData = writer.convert(snapshot);
16+
String actual = ProtobufUtil.shortDebugString(protobufData);
17+
assertThat(actual).isEqualTo(expected);
18+
}
19+
}

prometheus-metrics-exposition-textformats/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<properties>
2121
<automatic.module.name>io.prometheus.writer.text</automatic.module.name>
22+
<jacoco.line-coverage>0.50</jacoco.line-coverage>
2223
</properties>
2324

2425
<dependencies>
@@ -33,4 +34,20 @@
3334
<version>${project.version}</version>
3435
</dependency>
3536
</dependencies>
37+
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-jar-plugin</artifactId>
43+
<executions>
44+
<execution>
45+
<goals>
46+
<goal>test-jar</goal>
47+
</goals>
48+
</execution>
49+
</executions>
50+
</plugin>
51+
</plugins>
52+
</build>
3653
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.prometheus.metrics.expositionformats;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
6+
import org.junit.jupiter.api.Test;
7+
8+
class ExpositionFormatWriterTest {
9+
10+
private final ExpositionFormatWriter writer = new OpenMetricsTextFormatWriter(false, false);
11+
12+
@Test
13+
void toDebugString() {
14+
assertThat(writer.toDebugString(new MetricSnapshots())).isEqualTo("# EOF\n");
15+
}
16+
17+
@Test
18+
void isAvailable() {
19+
assertThat(writer.isAvailable()).isTrue();
20+
}
21+
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5-
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_29_3.Metrics;
6-
import io.prometheus.metrics.expositionformats.internal.PrometheusProtobufWriterImpl;
7-
import io.prometheus.metrics.expositionformats.internal.ProtobufUtil;
85
import io.prometheus.metrics.model.snapshots.ClassicHistogramBuckets;
96
import io.prometheus.metrics.model.snapshots.CounterSnapshot;
107
import io.prometheus.metrics.model.snapshots.CounterSnapshot.CounterDataPointSnapshot;
@@ -2659,10 +2656,5 @@ private void assertPrometheusTextWithoutCreated(String expected, MetricSnapshot
26592656
assertThat(out).hasToString(expected);
26602657
}
26612658

2662-
private void assertPrometheusProtobuf(String expected, MetricSnapshot snapshot) {
2663-
PrometheusProtobufWriterImpl writer = new PrometheusProtobufWriterImpl();
2664-
Metrics.MetricFamily protobufData = writer.convert(snapshot);
2665-
String actual = ProtobufUtil.shortDebugString(protobufData);
2666-
assertThat(actual).isEqualTo(expected);
2667-
}
2659+
protected void assertPrometheusProtobuf(String expected, MetricSnapshot snapshot) {}
26682660
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.prometheus.metrics.expositionformats;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatCode;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class PrometheusProtobufWriterTest {
9+
10+
private final PrometheusProtobufWriter writer = new PrometheusProtobufWriter();
11+
12+
@Test
13+
void accepts() {
14+
assertThat(writer.accepts(null)).isFalse();
15+
}
16+
17+
@Test
18+
void getContentType() {
19+
assertThat(writer.getContentType())
20+
.isEqualTo(
21+
"application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; "
22+
+ "encoding=delimited");
23+
}
24+
25+
@Test
26+
void write() {
27+
assertThatCode(() -> writer.write(null, null))
28+
.isInstanceOf(UnsupportedOperationException.class);
29+
}
30+
31+
@Test
32+
void toDebugString() {
33+
assertThatCode(() -> writer.toDebugString(null))
34+
.isInstanceOf(UnsupportedOperationException.class);
35+
}
36+
}

0 commit comments

Comments
 (0)