From 74bd625bf2e051863f12c4f7203a1fb7657c9ac2 Mon Sep 17 00:00:00 2001 From: Daniel Albuquerque Date: Sat, 6 Apr 2024 19:01:57 +0100 Subject: [PATCH] Add unit tests --- internal/pkg/calendar/calendar_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/pkg/calendar/calendar_test.go b/internal/pkg/calendar/calendar_test.go index 9b193bcd..3e6bed51 100644 --- a/internal/pkg/calendar/calendar_test.go +++ b/internal/pkg/calendar/calendar_test.go @@ -20,4 +20,24 @@ func TestIsWeekDay(t *testing.T) { assert.False(t, isWeekday(monday.Add(time.Hour*24*6))) } +func TestShouldParseMtbf(t *testing.T) { + duration, _ := ParseMtbf("2d") + assert.Equal(t, time.Hour*24*2, duration) + + duration, _ = ParseMtbf("2h") + assert.Equal(t, time.Hour*2, duration) + + duration, _ = ParseMtbf("2m") + assert.Equal(t, time.Minute*2, duration) + + // Special case where we don't have a time unit and we assume days + duration, _ = ParseMtbf("2") + assert.Equal(t, duration, time.Hour*24*2) +} + +func TestParseMtbfShouldNotAllowDurationLessThanAMinute(t *testing.T) { + _, err := ParseMtbf("30s") + assert.NotNil(t, err) +} + // FIXME: add more tests