Skip to main content

base_rule_test.go

base_rule_test.go - Overview

  1. Overview The base_rule_test.go file contains unit tests for the BaseRule struct, specifically focusing on the ShouldAlert method and its behavior when RequireMinPoints is enabled.

  2. Detailed Documentation

Function: TestBaseRule_RequireMinPoints

  • Purpose: Tests the ShouldAlert method of BaseRule when RequireMinPoints is enabled in the rule condition.
  • Parameters:
    • t: *testing.T - Testing object for running test cases.

Test Cases

  • test should skip if less than min points: Checks if the rule skips evaluation when the number of data points in the series is less than RequiredNumPoints.
  • test should alert if more than min points: Checks if the rule triggers an alert when the number of data points in the series is greater than or equal to RequiredNumPoints and the value satisfies the condition.

Test Structure

Each test case defines:

  • name: Name of the test case.
  • rule: *BaseRule - The BaseRule instance with specific RuleCondition.
  • shouldAlert: bool - Expected value of shouldAlert returned by ShouldAlert method.
  • series: *v3.Series - The v3.Series instance representing the time series data.

Include in Getting Started: NO