File: fs_windows_test.go

package info (click to toggle)
golang-github-microsoft-go-winio 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 764 kB
  • sloc: makefile: 3
file content (49 lines) | stat: -rw-r--r-- 1,128 bytes parent folder | download
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
package fs

import (
	"errors"
	"os"
	"testing"
)

func TestGetFSTypeOfKnownDrive(t *testing.T) {
	fsType, err := GetFileSystemType("C:\\")
	if err != nil {
		t.Fatal(err)
	}

	if fsType == "" {
		t.Fatal("No filesystem type name returned")
	}
}

func TestGetFSTypeOfInvalidPath(t *testing.T) {
	// [filepath.VolumeName] doesn't mandate that the drive letters matches [a-zA-Z].
	// Instead, use non-character drive.
	_, err := GetFileSystemType(`No:\`)
	if !errors.Is(err, ErrInvalidPath) {
		t.Fatalf("Expected `ErrInvalidPath`, got %v", err)
	}
}

func TestGetFSTypeOfValidButAbsentDrive(t *testing.T) {
	drive := ""
	for _, letter := range "abcdefghijklmnopqrstuvwxyz" {
		possibleDrive := string(letter) + ":\\"
		if _, err := os.Stat(possibleDrive); os.IsNotExist(err) {
			drive = possibleDrive
			break
		}
	}
	if drive == "" {
		t.Skip("Every possible drive exists")
	}

	_, err := GetFileSystemType(drive)
	if err == nil {
		t.Fatalf("GetFileSystemType %s unexpectedly succeeded", drive)
	}
	if !os.IsNotExist(err) {
		t.Fatalf("GetFileSystemType %s failed with %v, expected 'ErrNotExist' or similar", drive, err)
	}
}