Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
working-directory: "${{ github.workspace }}/_build"

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

- name: Dump lcov
run: lcov --list coverage.info
Expand Down
5 changes: 5 additions & 0 deletions core/tests/histogram_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ TEST(HistogramTest, reject_unsorted_bucket_bounds) {
EXPECT_ANY_THROW(Histogram({2, 1}));
}

TEST(HistogramTest, reject_unsorted_bucket_bounds_lvalue) {
const Histogram::BucketBoundaries unsorted = {2, 1};
EXPECT_THROW(Histogram{unsorted}, std::invalid_argument);
}

TEST(HistogramTest, reject_non_incrementing_bucket_bounds) {
EXPECT_ANY_THROW(Histogram({1, 2, 2, 3}));
}
Expand Down
21 changes: 21 additions & 0 deletions core/tests/summary_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,26 @@ TEST(SummaryTest, construction_with_dynamic_quantile_vector) {
summary.Observe(8.0);
}

TEST(SummaryTest, quantile_with_out_of_order_batches) {
// Flush large values into the sample first, then insert smaller values so
// that insertBatch() hits the --idx path (value < sample_[item].value).
Summary summary{Summary::Quantiles{{0.5, 0.05}}, std::chrono::hours{1}};

for (int i = 0; i < 10; ++i) summary.Observe(100.0 + i);
summary.Collect(); // flushes buffer → sample_ now contains large values

for (int i = 0; i < 10; ++i) summary.Observe(1.0 + i);
auto metric = summary.Collect(); // flushes buffer with small values < existing sample → --idx
auto s = metric.summary;

// 20 observations total, sum = (1..10) + (100..109) = 55 + 1045 = 1100
EXPECT_EQ(s.sample_count, 20U);
EXPECT_DOUBLE_EQ(s.sample_sum, 1100.0);
// p50 with error 0.05 on 20 samples: rank error ≤ 1, true median is 10 or 100
ASSERT_EQ(s.quantile.size(), 1U);
EXPECT_GE(s.quantile.at(0).value, 1.0);
EXPECT_LE(s.quantile.at(0).value, 109.0);
}

} // namespace
} // namespace prometheus
13 changes: 13 additions & 0 deletions pull/tests/integration/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ TEST_F(BasicAuthIntegrationTest, shouldRejectWrongAuthorizationMethod) {
}
#endif

TEST_F(BasicAuthIntegrationTest, shouldRejectNonBasicAuthScheme) {
std::unique_ptr<curl_slist, decltype(&curl_slist_free_all)> header(
curl_slist_append(nullptr, "Authorization: Bearer sometoken"),
curl_slist_free_all);

fetchPrePerform_ = [&header](CURL* curl) {
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header.get());
};

const auto metrics = FetchMetrics(default_metrics_path_);
ASSERT_EQ(metrics.code, 401);
}

TEST_F(BasicAuthIntegrationTest, shouldRejectMalformedBase64) {
std::unique_ptr<curl_slist, decltype(&curl_slist_free_all)> header(
curl_slist_append(nullptr, "Authorization: Basic $"),
Expand Down
12 changes: 12 additions & 0 deletions push/tests/internal/label_encoder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ TEST_F(LabelEncoderTest, regular) {
EXPECT_EQ("/foo/bar", Encode(Label{"foo", "bar"}));
}

TEST_F(LabelEncoderTest, uppercase) {
EXPECT_EQ("/foo/Bar", Encode(Label{"foo", "Bar"}));
}

TEST_F(LabelEncoderTest, digits) {
EXPECT_EQ("/foo/bar123", Encode(Label{"foo", "bar123"}));
}

TEST_F(LabelEncoderTest, unreserved_chars) {
EXPECT_EQ("/foo/a-b.c_d~e", Encode(Label{"foo", "a-b.c_d~e"}));
}

TEST_F(LabelEncoderTest, empty) {
EXPECT_EQ("/first_label@base64/=", Encode(Label{"first_label", ""}));
}
Expand Down
3 changes: 3 additions & 0 deletions util/tests/unit/base64_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const TestVector testVector[] = {
{"easure.", "ZWFzdXJlLg=="},
{"asure.", "YXN1cmUu"},
{"sure.", "c3VyZS4="},

// '/' character in encoded output (covers temp |= 0x3F branch in decode)
{"\xff\xff\xff", "////"},
};

using namespace testing;
Expand Down
Loading