hashicorp / hashicorp/terraform-plugin-testing

Go unit tests use Unix-specific path, error, and newline expectations on Windows

Open
#673 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
68
Forks
22
Avg merge
2d 12h
Merged PRs (30d)
1

Description

### terraform-plugin-testing version

Current `main` at commit `264df192526087d7f34a6ebf46cb8260bcd86573`.

### Environment

- Windows 11 Pro 10.0.26200
- Go 1.25.12 and Go 1.26.5
- Terraform 1.15.8
- Git 2.54.0.windows.1
- Git `core.autocrlf=true`

### Expected behavior

The Go unit test suite should use platform-independent expectations so that valid Windows paths, filesystem errors, and line endings do not cause test failures.

### Actual behavior

Running the test suite on a clean checkout of `upstream/main` produces failures in `config` and `internal/teststep` caused by Unix-specific test expectations.

The failures fall into three categories:

1. Tests in `config` hardcode expected paths using `/`, while the implementation uses `filepath.Join` and correctly returns native Windows paths containing `\`.

2. Tests in `internal/teststep` expect literal Unix filesystem error messages such as:

- `no such file or directory`
- `not a directory`

Windows returns different text for the equivalent filesystem errors.

3. At least one test compares LF-only text with content checked out using CRLF line endings on Windows.

These failures were reproduced on an unmodified worktree of `upstream/main` with both supported Go versions.

### Reproduction

From a clean checkout on Windows:

```powershell
go test ./config ./internal/teststep -count=1
```

The same failures are also visible when running:

```powershell
go test ./... -count=1
```

### Possible direction

Potential platform-independent approaches include:

- constructing expected filesystem paths with `filepath.Join`;
- using `errors.Is` with errors such as `fs.ErrNotExist` instead of matching operating-system-specific error strings;
- normalizing line endings before comparing textual file contents.

The appropriate solution may depend on whether each API is intended to return native filesystem paths or slash-normalized paths.

### Additional context

The issue was discovered while testing an unrelated change. The same failures occur on unmodified `main`.

The current Go CI workflow runs on Ubuntu, so these Windows-specific failures are not detected by the existing CI matrix

Contributor guide

Open the contributing guide

Research direction

Start by running `go test ./config ./internal/teststep -count=1` on Windows and inspect the failing tests in the `config` and `internal/teststep` packages. Replace Unix-specific path, filesystem-error, and line-ending expectations with platform-independent checks where appropriate. Done means these package tests, and the full `go test ./... -count=1` suite, pass on Windows without breaking native path behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.