forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock_linux_test.go
More file actions
91 lines (85 loc) · 1.92 KB
/
Copy pathblock_linux_test.go
File metadata and controls
91 lines (85 loc) · 1.92 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
//
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
//
// +build linux
package ghw
import (
"os"
"reflect"
"testing"
)
func TestParseMtabEntry(t *testing.T) {
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok {
t.Skip("Skipping block tests.")
}
tests := []struct {
line string
expected *mtabEntry
}{
{
line: "/dev/sda6 / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0",
expected: &mtabEntry{
Partition: "/dev/sda6",
Mountpoint: "/",
FilesystemType: "ext4",
Options: []string{
"rw",
"relatime",
"errors=remount-ro",
"data=ordered",
},
},
},
{
line: "/dev/sda8 /home/Name\\040with\\040spaces ext4 ro 0 0",
expected: &mtabEntry{
Partition: "/dev/sda8",
Mountpoint: "/home/Name with spaces",
FilesystemType: "ext4",
Options: []string{
"ro",
},
},
},
{
// Whoever might do this in real life should be quarantined and
// placed in administrative segregation
line: "/dev/sda8 /home/Name\\011with\\012tab&newline ext4 ro 0 0",
expected: &mtabEntry{
Partition: "/dev/sda8",
Mountpoint: "/home/Name\twith\ntab&newline",
FilesystemType: "ext4",
Options: []string{
"ro",
},
},
},
{
line: "/dev/sda1 /home/Name\\\\withslash ext4 ro 0 0",
expected: &mtabEntry{
Partition: "/dev/sda1",
Mountpoint: "/home/Name\\withslash",
FilesystemType: "ext4",
Options: []string{
"ro",
},
},
},
{
line: "Indy, bad dates",
expected: nil,
},
}
for x, test := range tests {
actual := parseMtabEntry(test.line)
if test.expected == nil {
if actual != nil {
t.Fatalf("Expected nil, but got %v", actual)
}
} else if !reflect.DeepEqual(test.expected, actual) {
t.Fatalf("In test %d, expected %v == %v", x, test.expected, actual)
}
}
}