This repository was archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathuinput_test.go
More file actions
50 lines (44 loc) · 1.28 KB
/
uinput_test.go
File metadata and controls
50 lines (44 loc) · 1.28 KB
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
package uinput
import (
"os"
"strings"
"testing"
)
func TestValidateDevicePathEmptyPathPanics(t *testing.T) {
expected := "device path must not be empty"
err := validateDevicePath("")
if err.Error() != expected {
t.Fatalf("Expected: %s\nActual: %s", expected, err)
}
}
func TestValidateDevicePathInvalidPathPanics(t *testing.T) {
path := "/some/bogus/path"
err := validateDevicePath(path)
if !os.IsNotExist(err) {
t.Fatalf("Expected: os.IsNotExist error\nActual: %s", err)
}
}
func TestValidateUinputNameEmptyNamePanics(t *testing.T) {
expected := "device name may not be empty"
err := validateUinputName(nil)
if err.Error() != expected {
t.Fatalf("Expected: %s\nActual: %s", expected, err)
}
}
func TestFailedDeviceFileCreationGeneratesError(t *testing.T) {
expected := "could not open device file"
_, err := createDeviceFile("/root/testfile")
if err == nil || err.Error() != expected {
t.Fatalf("expected error, but got none")
}
}
func TestNonExistentDeviceFileCausesError(t *testing.T) {
expected := "failed to write uidev struct to device file:"
_, err := createUsbDevice(nil, uinputUserDev{})
if err == nil {
t.Fatalf("expected error, but got none")
}
if !strings.Contains(err.Error(), expected) {
t.Fatalf("got '%v', but expected '%v'", err.Error(), expected)
}
}