github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+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  	for _, tt := range []struct {
    36  		name string
    37  		err  string
    38  	}{
    39  		{"rootfs", "<nil>"},
    40  		{"bogusfs", "bogusfs not found"},
    41  	} {
    42  		t.Run(tt.name, func(t *testing.T) {
    43  			err := FindFileSystem(tt.name)
    44  			// There has to be a better way to do this.
    45  			if fmt.Sprintf("%v", err) != tt.err {
    46  				t.Errorf("%s: got %v, want %v", tt.name, err, tt.err)
    47  			}
    48  		})
    49  	}
    50  }