-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlabel_test.go
114 lines (101 loc) · 2.25 KB
/
label_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package lifxlan_test
import (
"context"
"testing"
"time"
"go.yhsif.com/lifxlan"
"go.yhsif.com/lifxlan/mock"
)
func TestLabel(t *testing.T) {
t.Run(
"Short",
func(t *testing.T) {
label := "1234"
var rl lifxlan.Label
err := rl.Set(label)
if err != nil {
t.Fatalf("Label.Set returned err: %v", err)
}
got := rl.String()
if got != label {
t.Errorf("Expected %q, got %q", label, got)
}
},
)
t.Run(
"UTF-8",
func(t *testing.T) {
label := "中文"
var rl lifxlan.Label
err := rl.Set(label)
if err != nil {
t.Fatalf("Label.Set returned err: %v", err)
}
got := rl.String()
if got != label {
t.Errorf("Expected %q, got %q", label, got)
}
},
)
t.Run(
"Long",
func(t *testing.T) {
label := "0123456789012345678901234567890123456789"
// First 32 bytes in utf8
expected := "01234567890123456789012345678901"
var rl lifxlan.Label
err := rl.Set(label)
if err != nil {
t.Fatalf("Label.Set returned err: %v", err)
}
got := rl.String()
if got != expected {
t.Errorf("Expected %q, got %q", label, got)
}
},
)
t.Run(
"LongUnicode",
func(t *testing.T) {
label := "中文6789012345678901234567890123456789"
// First 32 bytes in utf8
expected := "中文67890123456789012345678901"
var rl lifxlan.Label
err := rl.Set(label)
if err != nil {
t.Fatalf("Label.Set returned err: %v", err)
}
got := rl.String()
if got != expected {
t.Errorf("Expected %q, got %q", label, got)
}
},
)
}
func TestEmptyLabel(t *testing.T) {
var label lifxlan.Label
s := label.String()
if s != lifxlan.EmptyLabel {
t.Errorf("Expected %q, got %q", lifxlan.EmptyLabel, s)
}
}
func TestGetLabel(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
const timeout = time.Millisecond * 200
var expected lifxlan.Label
expected.Set("foo")
service, device := mock.StartService(t)
service.RawStateLabelPayload = &lifxlan.RawStateLabelPayload{
Label: expected,
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
if err := device.GetLabel(ctx, nil); err != nil {
t.Fatal(err)
}
if device.Label().String() != expected.String() {
t.Errorf("Label expected %v, got %v", expected, device.Label())
}
}