From 9a29d4eae666c528673953e16de81b55fd4046f1 Mon Sep 17 00:00:00 2001 From: forsaken628 Date: Wed, 19 Jun 2024 00:15:12 +0800 Subject: [PATCH] fix Signed-off-by: forsaken628 --- .../file-metricscollector/rules_test.go | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/pkg/metricscollector/v1beta1/file-metricscollector/rules_test.go b/pkg/metricscollector/v1beta1/file-metricscollector/rules_test.go index 23ec3a69b29..6a933e8c24d 100644 --- a/pkg/metricscollector/v1beta1/file-metricscollector/rules_test.go +++ b/pkg/metricscollector/v1beta1/file-metricscollector/rules_test.go @@ -41,17 +41,38 @@ func TestRuleSet(t *testing.T) { }, action: func(t *testing.T, s *RuleSet) { diff(t, []string{"a", "b", "c"}, s.LiveMetrics()) - s.UpdateMetric("c", 1) + err := s.UpdateMetric("c", 1) + if err != nil { + t.Error(err) + } diff(t, []string{"a", "b"}, s.LiveMetrics()) - s.UpdateMetric("a", 1) - s.UpdateMetric("b", 0) - s.UpdateMetric("b", 0) + err = s.UpdateMetric("a", 1) + if err != nil { + t.Error(err) + } + err = s.UpdateMetric("b", 0) + if err != nil { + t.Error(err) + } + err = s.UpdateMetric("b", 0) + if err != nil { + t.Error(err) + } diff(t, []string{"a", "b"}, s.LiveMetrics()) - s.UpdateMetric("a", 0.1) + err = s.UpdateMetric("a", 0.1) + if err != nil { + t.Error(err) + } diff(t, []string{"a", "b"}, s.LiveMetrics()) - s.UpdateMetric("a", 0.21) + err = s.UpdateMetric("a", 0.21) + if err != nil { + t.Error(err) + } diff(t, []string{"b"}, s.LiveMetrics()) - s.UpdateMetric("b", 0.2) + err = s.UpdateMetric("b", 0.2) + if err != nil { + t.Error(err) + } diff(t, []string{}, s.LiveMetrics()) }, }, @@ -75,11 +96,23 @@ func TestRuleSet(t *testing.T) { }, action: func(t *testing.T, s *RuleSet) { diff(t, []string{"obj", "a"}, s.LiveMetrics()) - s.UpdateMetric("obj", 1) - s.UpdateMetric("a", 0.6) + err := s.UpdateMetric("obj", 1) + if err != nil { + t.Error(err) + } + err = s.UpdateMetric("a", 0.6) + if err != nil { + t.Error(err) + } diff(t, []string{"obj", "a"}, s.LiveMetrics()) - s.UpdateMetric("obj", 0.7) - s.UpdateMetric("a", 0.6) + err = s.UpdateMetric("obj", 0.7) + if err != nil { + t.Error(err) + } + err = s.UpdateMetric("a", 0.6) + if err != nil { + t.Error(err) + } diff(t, []string{"a"}, s.LiveMetrics()) }, },