github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/mount/fs_linux_test.go (about) 1 // Copyright 2015-2017 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package mount 6 7 import ( 8 "fmt" 9 "reflect" 10 "testing" 11 ) 12 13 func TestGetFileSystems(t *testing.T) { 14 fstypes, err := internalGetFilesystems("testdata/filesystems") 15 expected := []string{"ext4", "ext3", "vfat"} 16 if err != nil { 17 t.Errorf("InternalGetFilesystems failed with error %v", err) 18 } 19 if !reflect.DeepEqual(fstypes, expected) { 20 t.Errorf("Expected '%q', but resulted with '%q'", expected, fstypes) 21 } 22 } 23 24 func TestEmptyFileSystems(t *testing.T) { 25 fstypes, err := internalGetFilesystems("testdata/emptyFile") 26 if err != nil { 27 t.Errorf("InternalGetFilesystems failed with error %v", err) 28 } 29 if len(fstypes) != 0 { 30 t.Error("Expected no results for empty filesystem file.") 31 } 32 } 33 34 func TestFindFileSystem(t *testing.T) { 35 procfilesystems := `nodev sysfs 36 nodev rootfs 37 nodev ramfs 38 vfat 39 btrfs 40 ext3 41 ext2 42 ext4 43 ` 44 45 for _, tt := range []struct { 46 name string 47 err string 48 }{ 49 {"rootfs", "<nil>"}, 50 {"ext3", "<nil>"}, 51 {"bogusfs", "file system type \"bogusfs\" not found"}, 52 } { 53 t.Run(tt.name, func(t *testing.T) { 54 err := internalFindFileSystem(procfilesystems, tt.name) 55 // There has to be a better way to do this. 56 if fmt.Sprintf("%v", err) != tt.err { 57 t.Errorf("%s: got %v, want %v", tt.name, err, tt.err) 58 } 59 }) 60 } 61 }