-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcc_test.go
63 lines (49 loc) · 1.24 KB
/
cc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package openminder
import (
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
"periph.io/x/periph/conn/gpio"
"periph.io/x/periph/conn/gpio/gpiotest"
)
func TestContactClosure(t *testing.T) {
Convey("given a cc with a high pin", t, func() {
p := new(gpiotest.Pin)
p.L = gpio.High
cc := &ContactClosure{}
cc.Pin = p
Convey("when the cc is started with an interrupt callback", func() {
closed := false
cc.onClosureCB = func() {
closed = true
}
cc.Start()
Convey("and the pin reads low for < 400ms", func() {
p.L = gpio.Low
time.Sleep(300 * time.Millisecond)
p.L = gpio.High
Convey("it should not have closed", func() {
So(closed, ShouldBeFalse)
})
})
Convey("and the pin reads low for > 400ms", func() {
p.L = gpio.Low
time.Sleep(500 * time.Millisecond)
Convey("and the pin goes high again", func() {
p.L = gpio.High
time.Sleep(100 * time.Millisecond)
Convey("it should have closed", func() {
So(closed, ShouldBeTrue)
})
})
Convey("and the pin stays low", func() {
time.Sleep(100 * time.Millisecond)
Convey("it should not have closed", func() {
So(closed, ShouldBeFalse)
})
})
})
})
cc.Stop()
})
}