From 72283bc929abc8edc72e64249b56b4d7e52dbe56 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 5 Sep 2024 14:38:01 +0200 Subject: [PATCH] Test history.SlaDowntimeEndTime#Value() --- pkg/icingadb/v1/history/downtime_test.go | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/icingadb/v1/history/downtime_test.go b/pkg/icingadb/v1/history/downtime_test.go index e0f8c6f13..2f4c3f9bc 100644 --- a/pkg/icingadb/v1/history/downtime_test.go +++ b/pkg/icingadb/v1/history/downtime_test.go @@ -65,3 +65,39 @@ func TestDowntimeEventTime_Value(t *testing.T) { }) } } + +func TestSlaDowntimeEndTime_Value(t *testing.T) { + cancel := types.UnixMilli(time.Unix(42, 240000000)) + end := types.UnixMilli(time.Unix(1337, 733100000)) + + f := types.Bool{Bool: false, Valid: true} + T := types.Bool{Bool: true, Valid: true} + + subtests := []struct { + name string + cancelled types.Bool + cancelTime types.UnixMilli + endTime types.UnixMilli + output driver.Value + }{ + {name: "nil", cancelTime: cancel, endTime: end, output: int64(1337733)}, + {name: "invalid", cancelled: types.Bool{Bool: true}, cancelTime: cancel, endTime: end, output: int64(1337733)}, + {name: "false", cancelled: f, cancelTime: cancel, endTime: end, output: int64(1337733)}, + {name: "true", cancelled: T, cancelTime: cancel, endTime: end, output: int64(42240)}, + {name: "false-nil", cancelled: f, cancelTime: cancel}, + {name: "true-nil", cancelled: T, endTime: end}, + } + + for _, st := range subtests { + t.Run(st.name, func(t *testing.T) { + v, err := (SlaDowntimeEndTime{History: &SlaHistoryDowntime{ + HasBeenCancelled: st.cancelled, + CancelTime: st.cancelTime, + EndTime: st.endTime, + }}).Value() + + require.NoError(t, err) + require.Equal(t, st.output, v) + }) + } +}