Skip to content

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

@danicat

Description

@danicat

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

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.OS-WindowsTestingAn issue that has been verified to require only test changes, not just a test failure.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions