Skip to content

Commit

Permalink
Add a test for #29
Browse files Browse the repository at this point in the history
Signed-off-by: sinkingpoint <[email protected]>
  • Loading branch information
sinkingpoint committed Nov 16, 2023
1 parent f0e58b7 commit e0c7104
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/aggregator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ async fn test_clear_mode_family_change_labels() {

#[tokio::test]
async fn test_17() {
// https://github.com/sinkingpoint/prometheus-gravel-gateway/issues/17

let mut agg = Aggregator::new();
let result = agg.parse_and_merge("# HELP metric_without_values_total This metric does not always have values
# TYPE metric_without_values_total counter
Expand All @@ -192,3 +194,37 @@ metric_with_values_created{a_label=\"label_value\",another_label=\"a_value\"} 1.

assert!(result.is_ok(), "failed to parse valid metric: {:?}", result.err());
}

#[tokio::test]
async fn test_29() {
// https://github.com/sinkingpoint/prometheus-gravel-gateway/issues/29

// Test push with metrics, followed by an empty push.
let mut agg = Aggregator::new();
let result = agg.parse_and_merge("# HELP number_of_transactions_total Number of transactions
# TYPE number_of_transactions_total counter
number_of_transactions_total{label=\"value\"} 1
", &HashMap::new()).await;

assert!(result.is_ok(), "failed to parse valid metric: {:?}", result.err());

let result = agg.parse_and_merge("# HELP number_of_transactions_total Number of transactions
# TYPE number_of_transactions_total counter
", &HashMap::new()).await;
assert!(result.is_ok(), "failed to parse valid metric: {:?}", result.err());

// Test an empty push, followed by a push with metrics.
let mut agg = Aggregator::new();

let result = agg.parse_and_merge("# HELP number_of_transactions_total Number of transactions
# TYPE number_of_transactions_total counter
", &HashMap::new()).await;
assert!(result.is_ok(), "failed to parse valid metric: {:?}", result.err());

let result = agg.parse_and_merge("# HELP number_of_transactions_total Number of transactions
# TYPE number_of_transactions_total counter
number_of_transactions_total{label=\"value\"} 1
", &HashMap::new()).await;

assert!(result.is_ok(), "failed to parse valid metric: {:?}", result.err());
}

0 comments on commit e0c7104

Please sign in to comment.