maintenance_test.go
maintenance_test.go - Overview
-
Overview The
maintenance_test.go
file contains unit tests for thePlannedMaintenance
struct, focusing on theshouldSkip
method, which determines whether an alert should be skipped based on the maintenance schedule. -
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 ofPlannedMaintenance
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
- ThePlannedMaintenance
instance with specificSchedule
andRecurrence
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