Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions disk/disk_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,50 @@ package disk

import (
"context"
"os"
"os/exec"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestGetLogicalDrives(t *testing.T) {
// Create a virtual drive using subst to ensure multiple drives exist
tempDir := t.TempDir()

// Find an unused drive letter (Y: to G:, reverse order)
var driveLetter string
for c := 'Y'; c >= 'G'; c-- {
testDrive := string(c) + ":"
_, err := os.Stat(testDrive + "\\")
if os.IsNotExist(err) {
driveLetter = testDrive
break
}
}
if driveLetter == "" {
t.Skip("No available drive letter for subst")
}
ctx := context.Background()
// Create virtual drive by using subst command
cmd := exec.CommandContext(ctx, "subst", driveLetter, tempDir)
if err := cmd.Run(); err != nil {
t.Skipf("subst command failed: %v", err)
}
t.Cleanup(func() {
exec.CommandContext(ctx, "subst", driveLetter, "/d").Run()
})

drives, err := getLogicalDrives(context.Background())
require.NoError(t, err)
assert.NotEmpty(t, drives)
for _, d := range drives {
assert.NotEmpty(t, d)
}
t.Log("Logical Drives:", drives)
assert.Contains(t, drives, `C:\`)
assert.Contains(t, drives, driveLetter+`\`)
}

func TestBuildPartitionStat(t *testing.T) {
Expand Down