Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: TestOneDrive fails on Windows if OneDrive PATH needs expansion #57576

Closed
danicat opened this issue Jan 4, 2023 · 2 comments
Closed

os: TestOneDrive fails on Windows if OneDrive PATH needs expansion #57576

danicat opened this issue Jan 4, 2023 · 2 comments
Assignees
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Windows Testing An issue that has been verified to require only test changes, not just a test failure.
Milestone

Comments

@danicat
Copy link
Contributor

danicat commented Jan 4, 2023

I'm setting up a new development environment on a Windows machine. After initial setup I ran all.bat and the compilation succeeded, but the tests failed with:

--- FAIL: TestOneDrive (0.00s)
    stat_test.go:21: CreateFile %UserProfile%\OneDrive: The system cannot find the path specified.
FAIL
FAIL    os      28.760s

For the sake of time saving, the same test can be run with go tool dist test:

> go tool dist test -run=^go_test:os$

##### Test execution environment.
# GOARCH: amd64
# CPU: Intel(R) Xeon(R) CPU E3-1565L v5 @ 2.50GHz
# GOOS: windows
# OS Version: 10.0.14393

##### Testing packages.
--- FAIL: TestOneDrive (0.00s)
    stat_test.go:21: CreateFile %UserProfile%\OneDrive: The system cannot find the path specified.
FAIL
FAIL    os      9.265s
FAIL
go tool dist: Failed: exit status 1

I traced the problem to the findOneDriveDir helper function:

path, _, err := k.GetStringValue("UserFolder")
if err != nil {
return "", fmt.Errorf("reading UserFolder failed: %v", err)
}
return path, nil

In line 877 we get the value of the registry key and return it in 881, but if the registry value is of type EXPAND_SZ it needs further expansion as documented in https://pkg.go.dev/golang.org/x/sys/windows/registry#ExpandString. In my case, %UserProfile% needs expansion.

The fix is simply calling registry.ExpandString on the resulting path. I'm preparing a PR for submission later today.

What version of Go are you using (go version)?

> go version
go version go1.19.2 windows/amd64

Does this issue reproduce with the latest release?

Yes, considering this is a test bug and I'm running the latest version of the tests.

What operating system and processor architecture are you using (go env)?

GOOS=windows
GOARCH=amd64

What did you do?

$ git clone https://go.googlesource.com/go
$ cd go\src
$ all.bat

What did you expect to see?

ALL TESTS PASSED

What did you see instead?

(other text omitted for brevity)

--- FAIL: TestOneDrive (0.00s)
    stat_test.go:21: CreateFile %UserProfile%\OneDrive: The system cannot find the path specified.
FAIL
FAIL    os      28.760s
@gopherbot
Copy link

Change https://go.dev/cl/460535 mentions this issue: os: fix findOneDriveDir to expand strings that contain environment variables

@heschi heschi added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 4, 2023
@heschi heschi added this to the Go1.21 milestone Jan 4, 2023
@heschi
Copy link
Contributor

heschi commented Jan 4, 2023

cc @ianlancetaylor, @golang/windows

@bcmills bcmills added OS-Windows Testing An issue that has been verified to require only test changes, not just a test failure. labels Jan 5, 2023
@golang golang locked and limited conversation to collaborators Jan 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Windows Testing An issue that has been verified to require only test changes, not just a test failure.
Projects
None yet
Development

No branches or pull requests

4 participants