forked from bendahl/uinput
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uinput_test.go
46 lines (42 loc) · 1.13 KB
/
uinput_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
package uinput
import "testing"
func TestValidateDevicePathEmptyPathPanics(t *testing.T) {
expected := "device path must not be empty"
defer func() {
if r := recover(); r != nil {
actual := r.(string)
if actual != expected {
t.Fatalf("Expected: %s\nActual: %s", expected, actual)
}
}
}()
validateDevicePath("")
t.Fatalf("Empty path did not yield a panic")
}
func TestValidateDevicePathInvalidPathPanics(t *testing.T) {
path := "/some/bogus/path"
expected := "device path '" + path + "' does not exist"
defer func() {
if r := recover(); r != nil {
actual := r.(string)
if actual != expected {
t.Fatalf("Expected: %s\nActual: %s", expected, actual)
}
}
}()
validateDevicePath(path)
t.Fatalf("Invalid path did not yield a panic")
}
func TestValidateUinputNameEmptyNamePanics(t *testing.T) {
expected := "device name may not be empty"
defer func() {
if r := recover(); r != nil {
actual := r.(string)
if actual != expected {
t.Fatalf("Expected: %s\nActual: %s", expected, actual)
}
}
}()
validateUinputName(nil)
t.Fatalf("expected panic due to validation error, but nothing happened...")
}