forked from u-root/u-root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs_linux_test.go
61 lines (55 loc) · 1.42 KB
/
fs_linux_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
// Copyright 2015-2017 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package mount
import (
"fmt"
"reflect"
"testing"
)
func TestGetFileSystems(t *testing.T) {
fstypes, err := internalGetFilesystems("testdata/filesystems")
expected := []string{"ext4", "ext3", "vfat"}
if err != nil {
t.Errorf("InternalGetFilesystems failed with error %v", err)
}
if !reflect.DeepEqual(fstypes, expected) {
t.Errorf("Expected '%q', but resulted with '%q'", expected, fstypes)
}
}
func TestEmptyFileSystems(t *testing.T) {
fstypes, err := internalGetFilesystems("testdata/emptyFile")
if err != nil {
t.Errorf("InternalGetFilesystems failed with error %v", err)
}
if len(fstypes) != 0 {
t.Error("Expected no results for empty filesystem file.")
}
}
func TestFindFileSystem(t *testing.T) {
procfilesystems := `nodev sysfs
nodev rootfs
nodev ramfs
vfat
btrfs
ext3
ext2
ext4
`
for _, tt := range []struct {
name string
err string
}{
{"rootfs", "<nil>"},
{"ext3", "<nil>"},
{"bogusfs", "file system type \"bogusfs\" not found"},
} {
t.Run(tt.name, func(t *testing.T) {
err := internalFindFileSystem(procfilesystems, tt.name)
// There has to be a better way to do this.
if fmt.Sprintf("%v", err) != tt.err {
t.Errorf("%s: got %v, want %v", tt.name, err, tt.err)
}
})
}
}