From cf85bd84f21ddd287ceb488eb71b7c9c5e2f1dbf Mon Sep 17 00:00:00 2001 From: Jose Donizetti Date: Sat, 11 Nov 2017 12:13:12 -0200 Subject: [PATCH] Add CalcSilenceState Test (#1085) --- types/types_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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) +}