-
Notifications
You must be signed in to change notification settings - Fork 6
/
main_test.go
63 lines (51 loc) · 1.5 KB
/
main_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 main
import (
"bytes"
"github.com/stretchr/testify/assert"
"log"
"os"
"testing"
)
func TestPrintAllMatchingProtocols(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer func() {
log.SetOutput(os.Stderr)
}()
s := &Signal{
Lengths: []int{516, 2116, 4152, 9112},
Seq: "0102020101020201020101020102010202020202020202010201010202010202020202020103",
}
printAllMatchingProtocols([]string{"weather12", "weather15"}, s)
assert.Contains(t, buf.String(), "weather12")
assert.Contains(t, buf.String(), "weather15")
}
func TestProcessedWithMatchingConfigNoMatch(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer func() {
log.SetOutput(os.Stderr)
}()
s := &Signal{
Lengths: []int{516, 2116, 4152, 9112},
Seq: "0102020101020201020101020102010202020202020202010201010202010202020202020103",
}
processed := processedWithMatchingConfig([]string{"weather12", "weather15"}, s)
assert.False(t, processed)
}
func TestProcessedWithMatchingConfigMatch(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
defer func() {
log.SetOutput(os.Stderr)
}()
loadSampleConfig()
s := &Signal{
Lengths: []int{616, 1996, 4048, 9044},
Seq: "0102010202010202010101010101010102010202020102020102020102010202020102020103",
}
setupMetrics()
processed := processedWithMatchingConfig([]string{"weather12", "weather15"}, s)
assert.True(t, processed)
assert.Contains(t, buf.String(), "fridge: {ID:91 Name:91 Channel:1 Temperature:18.7 Humidity:53 LowBattery:false}")
}