Skip to main content

maintenance_test.go

maintenance_test.go - Overview

  1. Overview The maintenance_test.go file contains unit tests for the PlannedMaintenance struct, focusing on the shouldSkip method, which determines whether an alert should be skipped based on the maintenance schedule.

  2. Detailed Documentation

Helper Function: timePtr

  • Purpose: Creates a pointer to a time.Time value.
  • Parameters:
    • t: time.Time - The time value.
  • Returns: *time.Time - A pointer to the time value.

Function: TestShouldSkipMaintenance

  • Purpose: Tests the shouldSkip method of PlannedMaintenance with various schedule configurations and timestamps.
  • Parameters:
    • t: *testing.T - Testing object for running test cases.

Test Cases

Each test case defines:

  • name: string - Name of the test case.
  • maintenance: *PlannedMaintenance - The PlannedMaintenance instance with specific Schedule and Recurrence details.
  • ts: time.Time - The timestamp to check against the maintenance schedule.
  • skip: bool - Expected result: true if the alert should be skipped, false otherwise.

The test cases cover various scenarios, including:

  • Weekly recurrence: tests different days of the week and handling of midnight crossings.
  • Daily recurrence: tests different times of day and handling of midnight crossings.
  • Monthly recurrence: tests different days of the month.
  • Timezone handling: tests with different timezones.
  • Edge cases: tests with empty RepeatOn array, end dates in the past, and month-end crossings.
  • Fixed schedules: start <= ts <= end, start >= ts, and ts < start

Include in Getting Started: NO