Skip to content

Commit

Permalink
Test history.FlappingEventTime#Value()
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Sep 5, 2024
1 parent 277a61d commit 4e851f5
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pkg/icingadb/v1/history/flapping_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package history

import (
"database/sql/driver"
"github.com/icinga/icinga-go-library/types"
"github.com/stretchr/testify/require"
"testing"
"time"
)

func TestFlappingEventTime_Value(t *testing.T) {
s := types.UnixMilli(time.Unix(12, 345000000))
e := types.UnixMilli(time.Unix(67, 890000000))

subtests := []struct {
name string
input *HistoryFlapping
output driver.Value
}{
{name: "nil-history"},
{
name: "bad-event-type",
input: &HistoryFlapping{HistoryMeta: HistoryMeta{EventType: "bad"}, StartTime: s, EndTime: e},
},
{
name: "start",
input: &HistoryFlapping{HistoryMeta: HistoryMeta{EventType: "flapping_start"}, StartTime: s, EndTime: e},
output: int64(12345),
},
{
name: "end",
input: &HistoryFlapping{HistoryMeta: HistoryMeta{EventType: "flapping_end"}, StartTime: s, EndTime: e},
output: int64(67890),
},
{
name: "start-nil",
input: &HistoryFlapping{HistoryMeta: HistoryMeta{EventType: "flapping_start"}, EndTime: e},
},
{
name: "end-nil",
input: &HistoryFlapping{HistoryMeta: HistoryMeta{EventType: "flapping_end"}, StartTime: s},
},
}

for _, st := range subtests {
t.Run(st.name, func(t *testing.T) {
v, err := (FlappingEventTime{History: st.input}).Value()

require.NoError(t, err)
require.Equal(t, st.output, v)
})
}
}

0 comments on commit 4e851f5

Please sign in to comment.