Bug: Close hvsock handle on listen error; fix tests (#310)

* Bug: Close hvsock handle on listen error; fix tests

Close the socket created in
`github.com/Microsoft/go-winio/pkg/ListenHvsock` if either the `Bind` or
`Listen` calls fail.

Go changed `filepath.VolumeName` code, resulting in different behavior in
`github.com/Microsoft/go-winio/pkg/fs.GetFileSystemType`.
Update test accordingly.
Also add more debug logs to `pkg\fs\resolve_test.go`.

Also, move add skip for fuzzing on WS2019 or older to `FuzzHvSockRxTx`
code directly, instead of in ci.yml.

See: https://go-review.googlesource.com/c/go/+/540277

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

* PR: unskip TestResolvePath

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

---------

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
This commit is contained in:
Hamza El-Saawy
2023-12-18 11:11:12 -05:00
committed by GitHub
parent 553a715903
commit bc421d9108
5 changed files with 63 additions and 18 deletions
+3 -1
View File
@@ -18,7 +18,9 @@ func TestGetFSTypeOfKnownDrive(t *testing.T) {
}
func TestGetFSTypeOfInvalidPath(t *testing.T) {
_, err := GetFileSystemType("7:\\")
// [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)
}
+15 -1
View File
@@ -25,9 +25,19 @@ func getWindowsBuildNumber() uint32 {
func makeSymlink(t *testing.T, oldName string, newName string) {
t.Helper()
t.Logf("make symlink: %s -> %s", oldName, newName)
if _, err := os.Lstat(oldName); err != nil {
t.Fatalf("could not open file %q: %v", oldName, err)
}
if err := os.Symlink(oldName, newName); err != nil {
t.Fatalf("creating symlink: %s", err)
}
if _, err := os.Lstat(newName); err != nil {
t.Fatalf("could not open file %q: %v", newName, err)
}
}
func getVolumeGUIDPath(t *testing.T, path string) string {
@@ -209,14 +219,18 @@ func TestResolvePath(t *testing.T) {
{filepath.Join(dir, "lnk4"), filepath.Join(volumePathVHD2, "data.txt"), "symlink to volume with mount point"},
} {
t.Run(tc.description, func(t *testing.T) {
t.Logf("resolving: %s -> %s", tc.input, tc.expected)
actual, err := ResolvePath(tc.input)
if err != nil {
t.Fatalf("resolvePath should return no error, but %v", err)
t.Fatalf("ResolvePath should return no error, but: %v", err)
}
if actual != tc.expected {
t.Fatalf("expected %v but got %v", tc.expected, actual)
}
// Make sure EvalSymlinks works with the resolved path, as an extra safety measure.
t.Logf("filepath.EvalSymlinks(%s)", actual)
p, err := filepath.EvalSymlinks(actual)
if err != nil {
t.Fatalf("EvalSymlinks should return no error, but %v", err)