-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbme280_test.go
56 lines (44 loc) · 885 Bytes
/
bme280_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
package bme280
import (
"strings"
"testing"
)
type nullBus struct{}
func (*nullBus) ReadReg(byte, []byte) error {
return nil
}
func (*nullBus) WriteReg(byte, []byte) error {
return nil
}
func TestRead(t *testing.T) {
t.Run("fails if uninitialized", func(t *testing.T) {
driver := New(&nullBus{})
_, err := driver.Read()
if err == nil || !strings.HasPrefix(err.Error(), "driver uninitialized") {
t.Errorf("no or unexpected error: %s", err.Error())
}
})
}
type closerBus struct {
closed bool
}
func (b *closerBus) ReadReg(byte, []byte) error {
return nil
}
func (b *closerBus) WriteReg(byte, []byte) error {
return nil
}
func (b *closerBus) Close() error {
b.closed = true
return nil
}
func TestClose(t *testing.T) {
b := closerBus{}
err := b.Close()
if err != nil {
t.Fatalf("close: %v", err)
}
if !b.closed {
t.Errorf("expected closed")
}
}