-
Notifications
You must be signed in to change notification settings - Fork 0
/
radio_test.go
64 lines (49 loc) · 1.46 KB
/
radio_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
64
package rn2483_test
import (
"testing"
"github.com/poy/onpar"
. "github.com/poy/onpar/expect"
. "github.com/poy/onpar/matchers"
"github.com/omaskery/rn2483"
"github.com/omaskery/rn2483/fake"
)
func TestRadio(t *testing.T) {
o := onpar.New()
defer o.Run(t)
o.BeforeEach(func(t *testing.T) (*testing.T, *testContext) {
ctx := prepareTestContext(t)
_, err := ctx.device.PauseMAC()
Expect(t, err).To(Not(HaveOccurred()))
return t, ctx
})
o.Spec("can set radio power", func(t *testing.T, ctx *testContext) {
Expect(t, ctx.device.SetRadioPower(5)).To(Not(HaveOccurred()))
power, err := ctx.device.GetRadioPower()
Expect(t, err).To(Not(HaveOccurred()))
Expect(t, power).To(Equal(5))
})
o.Spec("can transmit", func(t *testing.T, ctx *testContext) {
testData := []byte("Hello, World!")
var transmitted []byte
ctx.fake.Radio.Tx = func(d *fake.Device, packet []byte) error {
transmitted = packet
return nil
}
err := ctx.device.RadioTx(testData)
Expect(t, err).To(Not(HaveOccurred()))
Expect(t, transmitted).To(Equal(testData))
})
o.Spec("can receive", func(t *testing.T, ctx *testContext) {
testData := []byte("Wow, such test data!")
rxChan := make(chan []byte)
ctx.fake.Radio.Rx = func(d *fake.Device) <-chan []byte {
return rxChan
}
go func() {
rxChan <- testData
}()
data, err := ctx.device.RadioRx(rn2483.ContinuousReceiveMode)
Expect(t, err).To(Not(HaveOccurred()))
Expect(t, data).To(Equal(testData))
})
}