Skip to content

Commit 458deac

Browse files
authored
Merge pull request #756 from jupp0r/improve-coverage
tests: improve coverage
2 parents 72fd485 + b586971 commit 458deac

6 files changed

Lines changed: 55 additions & 1 deletion

File tree

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
working-directory: "${{ github.workspace }}/_build"
5858

5959
- name: Run lcov
60-
run: lcov --capture --directory "${{ github.workspace }}" --output-file coverage.info --no-external --exclude '*/tests/*'
60+
run: lcov --capture --directory "${{ github.workspace }}" --output-file coverage.info --filter brace --no-external --exclude '*/tests/*'
6161

6262
- name: Dump lcov
6363
run: lcov --list coverage.info

core/tests/histogram_test.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ TEST(HistogramTest, reject_unsorted_bucket_bounds) {
5757
EXPECT_ANY_THROW(Histogram({2, 1}));
5858
}
5959

60+
TEST(HistogramTest, reject_unsorted_bucket_bounds_lvalue) {
61+
const Histogram::BucketBoundaries unsorted = {2, 1};
62+
EXPECT_THROW(Histogram{unsorted}, std::invalid_argument);
63+
}
64+
6065
TEST(HistogramTest, reject_non_incrementing_bucket_bounds) {
6166
EXPECT_ANY_THROW(Histogram({1, 2, 2, 3}));
6267
}

core/tests/summary_test.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,26 @@ TEST(SummaryTest, construction_with_dynamic_quantile_vector) {
102102
summary.Observe(8.0);
103103
}
104104

105+
TEST(SummaryTest, quantile_with_out_of_order_batches) {
106+
// Flush large values into the sample first, then insert smaller values so
107+
// that insertBatch() hits the --idx path (value < sample_[item].value).
108+
Summary summary{Summary::Quantiles{{0.5, 0.05}}, std::chrono::hours{1}};
109+
110+
for (int i = 0; i < 10; ++i) summary.Observe(100.0 + i);
111+
summary.Collect(); // flushes buffer → sample_ now contains large values
112+
113+
for (int i = 0; i < 10; ++i) summary.Observe(1.0 + i);
114+
auto metric = summary.Collect(); // flushes buffer with small values < existing sample → --idx
115+
auto s = metric.summary;
116+
117+
// 20 observations total, sum = (1..10) + (100..109) = 55 + 1045 = 1100
118+
EXPECT_EQ(s.sample_count, 20U);
119+
EXPECT_DOUBLE_EQ(s.sample_sum, 1100.0);
120+
// p50 with error 0.05 on 20 samples: rank error ≤ 1, true median is 10 or 100
121+
ASSERT_EQ(s.quantile.size(), 1U);
122+
EXPECT_GE(s.quantile.at(0).value, 1.0);
123+
EXPECT_LE(s.quantile.at(0).value, 109.0);
124+
}
125+
105126
} // namespace
106127
} // namespace prometheus

pull/tests/integration/integration_test.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,19 @@ TEST_F(BasicAuthIntegrationTest, shouldRejectWrongAuthorizationMethod) {
274274
}
275275
#endif
276276

277+
TEST_F(BasicAuthIntegrationTest, shouldRejectNonBasicAuthScheme) {
278+
std::unique_ptr<curl_slist, decltype(&curl_slist_free_all)> header(
279+
curl_slist_append(nullptr, "Authorization: Bearer sometoken"),
280+
curl_slist_free_all);
281+
282+
fetchPrePerform_ = [&header](CURL* curl) {
283+
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header.get());
284+
};
285+
286+
const auto metrics = FetchMetrics(default_metrics_path_);
287+
ASSERT_EQ(metrics.code, 401);
288+
}
289+
277290
TEST_F(BasicAuthIntegrationTest, shouldRejectMalformedBase64) {
278291
std::unique_ptr<curl_slist, decltype(&curl_slist_free_all)> header(
279292
curl_slist_append(nullptr, "Authorization: Basic $"),

push/tests/internal/label_encoder_test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ TEST_F(LabelEncoderTest, regular) {
2323
EXPECT_EQ("/foo/bar", Encode(Label{"foo", "bar"}));
2424
}
2525

26+
TEST_F(LabelEncoderTest, uppercase) {
27+
EXPECT_EQ("/foo/Bar", Encode(Label{"foo", "Bar"}));
28+
}
29+
30+
TEST_F(LabelEncoderTest, digits) {
31+
EXPECT_EQ("/foo/bar123", Encode(Label{"foo", "bar123"}));
32+
}
33+
34+
TEST_F(LabelEncoderTest, unreserved_chars) {
35+
EXPECT_EQ("/foo/a-b.c_d~e", Encode(Label{"foo", "a-b.c_d~e"}));
36+
}
37+
2638
TEST_F(LabelEncoderTest, empty) {
2739
EXPECT_EQ("/first_label@base64/=", Encode(Label{"first_label", ""}));
2840
}

util/tests/unit/base64_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ const TestVector testVector[] = {
3636
{"easure.", "ZWFzdXJlLg=="},
3737
{"asure.", "YXN1cmUu"},
3838
{"sure.", "c3VyZS4="},
39+
40+
// '/' character in encoded output (covers temp |= 0x3F branch in decode)
41+
{"\xff\xff\xff", "////"},
3942
};
4043

4144
using namespace testing;

0 commit comments

Comments
 (0)