-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathibeacon_test.go
57 lines (51 loc) · 1.16 KB
/
ibeacon_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
package tilt_test
import (
"errors"
"testing"
"github.com/alexhowarth/go-tilt"
)
func TestNewIBeacon(t *testing.T) {
tt := []struct {
name string
data []byte
err error
uuid string
major uint16
minor uint16
}{
{
name: "Valid iBeacon",
data: []uint8{0x4c, 0x0, 0x2, 0x15, 0xa4, 0x95, 0xbb, 0x30, 0xc5, 0xb1, 0x4b, 0x44, 0xb5, 0x12, 0x13, 0x70, 0xf0, 0x2d, 0x74, 0xde, 0x0, 0x46, 0x3, 0xfc, 0xc5},
err: nil,
uuid: "a495bb30c5b14b44b5121370f02d74de",
major: 70,
minor: 1020,
},
{
name: "Invalid iBeacon",
data: []uint8{0x4c, 0x0, 0x2, 0x15},
err: tilt.ErrNotBeacon,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
got, err := tilt.NewIBeacon(tc.data)
if tc.err != nil {
// expecting an error
if !errors.Is(err, tc.err) {
t.Fatalf("Expected '%v' error, got '%v' error", tc.err, err)
}
return
}
if got.UUID != tc.uuid {
t.Errorf("Expected %v, got %v", tc.uuid, got.UUID)
}
if got.Major != tc.major {
t.Errorf("Expected %v, got %v", tc.major, got.Major)
}
if got.Minor != tc.minor {
t.Errorf("Expected %v, got %v", tc.minor, got.Minor)
}
})
}
}