diff --git a/types/types_test.go b/types/types_test.go index bffda4fd..ae143743 100644 --- a/types/types_test.go +++ b/types/types_test.go @@ -19,6 +19,7 @@ import ( "time" "github.com/prometheus/common/model" + "github.com/stretchr/testify/require" ) func TestAlertMerge(t *testing.T) { @@ -61,3 +62,23 @@ func TestAlertMerge(t *testing.T) { } } } + +func TestCalcSilenceState(t *testing.T) { + + var ( + pastStartTime = time.Now() + pastEndTime = time.Now() + + futureStartTime = time.Now().Add(time.Hour) + futureEndTime = time.Now().Add(time.Hour) + ) + + expected := CalcSilenceState(futureStartTime, futureEndTime) + require.Equal(t, SilenceStatePending, expected) + + expected = CalcSilenceState(pastStartTime, futureEndTime) + require.Equal(t, SilenceStateActive, expected) + + expected = CalcSilenceState(pastStartTime, pastEndTime) + require.Equal(t, SilenceStateExpired, expected) +}