1
0
Fork 0
hswro-alarm-bot/filters_test.go

38 lines
1.2 KiB
Go
Raw Normal View History

2024-02-13 22:20:15 +00:00
package main
import (
"sync"
"testing"
"github.com/probakowski/go-satel"
"github.com/stretchr/testify/assert"
)
func TestSatelEventTypeFiltering(t *testing.T) {
testEvents := make(chan satel.Event)
receivedEvents := make([]satel.Event, 0)
wg := sync.WaitGroup{}
go func() {
wg.Add(1)
for e := range FilterByType(testEvents, []satel.ChangeType{satel.ArmedPartition, satel.PartitionFireAlarm}) {
receivedEvents = append(receivedEvents, e)
}
wg.Done()
}()
testEvents <- satel.Event{Type: satel.ArmedPartition, Index: 1, Value: true}
testEvents <- satel.Event{Type: satel.DoorOpened, Index: 2, Value: true}
testEvents <- satel.Event{Type: satel.PartitionAlarm, Index: 3, Value: true}
testEvents <- satel.Event{Type: satel.PartitionFireAlarm, Index: 4, Value: true}
testEvents <- satel.Event{Type: satel.TroublePart1, Index: 5, Value: true}
testEvents <- satel.Event{Type: satel.ZoneTamper, Index: 6, Value: true}
close(testEvents)
wg.Wait()
assert.Len(t, receivedEvents, 2)
assert.Contains(t, receivedEvents, satel.Event{Type: satel.ArmedPartition, Index: 1, Value: true})
assert.Contains(t, receivedEvents, satel.Event{Type: satel.PartitionFireAlarm, Index: 4, Value: true})
}