From a28ff7a7894ddb6d50fe5b2e8f754def82a92764 Mon Sep 17 00:00:00 2001 From: Michail Safronov Date: Fri, 10 Nov 2023 19:16:33 +0500 Subject: [PATCH] test: add movingAverage carbonapi func test --- metric_source/local/local_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/metric_source/local/local_test.go b/metric_source/local/local_test.go index 0e8af0e8e..b9d4629ab 100644 --- a/metric_source/local/local_test.go +++ b/metric_source/local/local_test.go @@ -363,6 +363,29 @@ func TestLocalSourceFetch(t *testing.T) { }) }) + // for update carbonapi to v0.16.2, check for nil pointers usage in carbonapi config + Convey("Test success evaluate target with movingAverage(1)", t, func() { + database.EXPECT().GetPatternMetrics(pattern1).Return([]string{metric}, nil) + database.EXPECT().GetMetricRetention(metric).Return(retention, nil) + database.EXPECT().GetMetricsValues([]string{metric}, retentionFrom, retentionUntil-1).Return(dataList, nil) + database.EXPECT().GetMetricsTTLSeconds().Return(metricsTTL) + + result, err := localSource.Fetch("super.puper.pattern | movingAverage(1) | aliasByNode(5, 7)", from, until, true) + + So(err, ShouldBeNil) + So(result, ShouldResemble, &FetchResult{ + MetricsData: []metricSource.MetricData{{ + Name: "super.puper.metric", + StartTime: retentionFrom, + StopTime: retentionUntil, + StepTime: retention, + Values: []float64{0, 1, 2, 3, 4}, + }}, + Metrics: []string{metric}, + Patterns: []string{pattern1}, + }) + }) + Convey("Test success evaluate target with aliasByTags('name')", t, func() { database.EXPECT().GetPatternMetrics(pattern1).Return([]string{metric}, nil) database.EXPECT().GetMetricRetention(metric).Return(retention, nil)