1package gitlab
2
3import (
4 "testing"
5 "time"
6
7 "github.com/stretchr/testify/require"
8)
9
10var _ Event = mockEvent(0)
11
12type mockEvent int64
13
14func (m mockEvent) ID() string { panic("implement me") }
15func (m mockEvent) UserID() int { panic("implement me") }
16func (m mockEvent) Kind() EventKind { panic("implement me") }
17func (m mockEvent) CreatedAt() time.Time { return time.Unix(int64(m), 0) }
18
19func TestSortedEvents(t *testing.T) {
20 makeInput := func(times ...int64) chan Event {
21 out := make(chan Event)
22 go func() {
23 for _, t := range times {
24 out <- mockEvent(t)
25 }
26 close(out)
27 }()
28 return out
29 }
30
31 sorted := SortedEvents(
32 makeInput(),
33 makeInput(1, 7, 9, 19),
34 makeInput(2, 8, 23),
35 makeInput(35, 48, 59, 64, 721),
36 )
37
38 var previous Event
39 for event := range sorted {
40 if previous != nil {
41 require.True(t, previous.CreatedAt().Before(event.CreatedAt()))
42 }
43 previous = event
44 }
45}