Files
Reims-Go/internal/host/drives_windows_test.go
T

51 lines
1.3 KiB
Go

//go:build windows
package host
import (
"encoding/binary"
"testing"
)
func TestListDrivesFindsTheSystemDrive(t *testing.T) {
var sys bool
for _, d := range ListDrives() {
t.Logf("%s free=%.0fGB system=%v external=%v", d.Root, d.FreeGB, d.System, d.External)
if d.System {
sys = true
if d.External {
t.Error("system drive reported as external")
}
if d.VolumeGUID == "" {
t.Error("system drive has no volume GUID")
}
}
}
if !sys {
t.Fatal("no system drive listed")
}
}
func TestInternalStorageDevice(t *testing.T) {
if internal, known := internalStorageDevice(make([]byte, 31)); internal || known {
t.Fatal("accepted a truncated device descriptor")
}
for bus := uint32(0); bus <= 20; bus++ {
for removable := byte(0); removable <= 1; removable++ {
desc := make([]byte, 32)
desc[10] = removable
desc[11] = 1 - removable // CommandQueueing is independent of removability.
binary.LittleEndian.PutUint32(desc[28:], bus)
internal, known := internalStorageDevice(desc)
want := false
switch bus {
case 1, 2, 3, 8, 10, 11, 16, 17, 18, 19:
want = removable == 0
}
if !known || internal != want {
t.Errorf("bus %d, removable %d: internal=%v known=%v, want internal=%v", bus, removable, internal, known, want)
}
}
}
}