-
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathlinux-list.test.ts
More file actions
118 lines (108 loc) · 3.17 KB
/
linux-list.test.ts
File metadata and controls
118 lines (108 loc) · 3.17 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
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
115
116
117
118
import { assert, shouldReject } from '../test/assert'
import { mockLinuxList as linuxList, mockLinuxListError } from './mocks/linux-list'
const mockUdevOutput = String.raw`
P: /devices/platform/serial8250/tty/ttyS0
N: ttyS0
E: DEVNAME=/dev/ttyS0
E: DEVPATH=/devices/platform/serial8250/tty/ttyS0
E: MAJOR=4
E: MINOR=64
E: SUBSYSTEM=tty
P: /devices/platform/serial8250/tty/ttyS1
N: ttyS1
E: DEVNAME=/dev/ttyS1
E: DEVPATH=/devices/platform/serial8250/tty/ttyS1
E: MAJOR=4
E: MINOR=65
E: SUBSYSTEM=tty
P: /devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.0/tty/ttyACM0
N: ttyACM0
S: serial/by-id/usb-Arduino__www.arduino.cc__0043_752303138333518011C1-if00
S: serial/by-path/pci-0000:00:06.0-usb-0:2:1.0
E: DEVLINKS=/dev/serial/by-path/pci-0000:00:06.0-usb-0:2:1.0 /dev/serial/by-id/usb-Arduino__www.arduino.cc__0043_752303138333518011C1-if00
E: DEVNAME=/dev/ttyACM0
E: DEVPATH=/devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.0/tty/ttyACM0
E: ID_BUS=usb
E: ID_MM_CANDIDATE=1
E: ID_MODEL=0043
E: ID_MODEL_ENC=0043
E: ID_MODEL_FROM_DATABASE=Uno R3 (CDC ACM)
E: ID_MODEL_ID=0043
E: ID_PATH=pci-0000:00:06.0-usb-0:2:1.0
E: ID_PATH_TAG=pci-0000_00_06_0-usb-0_2_1_0
E: ID_PCI_CLASS_FROM_DATABASE=Serial bus controller
E: ID_PCI_INTERFACE_FROM_DATABASE=OHCI
E: ID_PCI_SUBCLASS_FROM_DATABASE=USB controller
E: ID_REVISION=0001
E: ID_SERIAL=Arduino__www.arduino.cc__0043_752303138333518011C1
E: ID_SERIAL_SHORT=752303138333518011C1
E: ID_TYPE=generic
E: ID_USB_CLASS_FROM_DATABASE=Communications
E: ID_USB_DRIVER=cdc_acm
E: ID_USB_INTERFACES=:020201:0a0000:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=Arduino__www.arduino.cc_
E: ID_VENDOR_ENC=Arduino\x20\x28www.arduino.cc\x29
E: ID_VENDOR_FROM_DATABASE=Arduino SA
E: ID_VENDOR_ID=2341
E: MAJOR=166
E: MINOR=0
E: SUBSYSTEM=tty
E: TAGS=:systemd:
E: USEC_INITIALIZED=2219936602
P: /devices/unknown
N: ttyAMA_im_a_programmer
E: DEVNAME=/dev/ttyAMA_im_a_programmer
E: DEVLINKS=/dev/serial/by-id/pci-NATA_Siolynx2_C8T6VI1F-if00-port0 /dev/serial/by-path/pci-0000:00:14.0-usb-0:2:1.0-port0
P: /devices/unknown
N: ttyMFD0
E: DEVNAME=/dev/ttyMFD0
E: ID_VENDOR_ID=0x2343
E: ID_MODEL_ID=0043
E: ID_MODEL=some device made by someone
P: /devices/unknown
N: rfcomm4
E: DEVNAME=/dev/rfcomm4
P: /devices/unknown
N: ttyNOTASERIALPORT
`
const portOutput = [
{
path: '/dev/ttyS0',
},
{
path: '/dev/ttyS1',
},
{
path: '/dev/ttyACM0',
manufacturer: 'Arduino (www.arduino.cc)',
product: '0043',
serialNumber: '752303138333518011C1',
productId: '0043',
vendorId: '2341',
pnpId: 'usb-Arduino__www.arduino.cc__0043_752303138333518011C1-if00',
},
{
path: '/dev/ttyAMA_im_a_programmer',
pnpId: 'pci-NATA_Siolynx2_C8T6VI1F-if00-port0',
},
{
path: '/dev/ttyMFD0',
product: 'some device made by someone',
vendorId: '2343',
productId: '0043',
},
{
path: '/dev/rfcomm4',
},
]
describe('listLinux', () => {
it('lists available serialports', async () => {
const ports = await linuxList(mockUdevOutput)
assert.containSubset(ports, portOutput)
})
it('rejects on non-zero exit codes', async () => {
const list = mockLinuxListError('1')
await shouldReject(list, Error, 'Error listing ports udevadm exited with error code: 1')
})
})