Skip to content

assert: refactor Test*FileExists and Test*DirExists tests to enable parallel testing #1766

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dolmen
Copy link
Collaborator

@dolmen dolmen commented Jun 16, 2025

Summary

Refactor TestFileExists, TestNoFileExists, TestDirExists and TestNoDirExists to be able to run in parallel: we now use a temporary directory handled by go test to create temporary files.

Much infrastructure logic is moved to the helper getTempSymlinkPath for improved readability of each test suite.

Changes

  • use testing.T.TempDir (available since go1.15) as the storage location for files created temporarly for testing. This directory is handled by go test, so this allows us to remove cleanup code.
  • as there is no more race condition, we enable parallel testing on Test*Exists.

Motivation

  • cleanup: improved readability of the Test*Exists code
  • enable parallel testing on all assert tests for faster dev loop

Related issues

@dolmen dolmen self-assigned this Jun 16, 2025
@dolmen dolmen added pkg-assert Change related to package testify/assert concurrency internal/refactor Refactor internals with no external visible changes internal/testing Changes purely related to the testify testsuites internal/cleanup Internal change to ease maintenance without external impact labels Jun 16, 2025
dolmen added 3 commits June 16, 2025 16:37
In package assert, fix TestFileExists, TestNoFileExists, TestDirExists, TestNoDirExists
to be able to run in parallel:
- use t.TempDir() as the storage location for temporary created
  symlinks. This also allows the cleanup of that storage to be
  automatically handled by "go test". testing.T.TempDir is available
  since go1.15.
- enable parallel testing on each test
In tests of the assert package, move more logic from each test into
the helper getTempSymlinkPath.
Improve error reporting in getTempSymlinkPath by displaying the
file paths.
@dolmen dolmen force-pushed the dolmen/assert-testing-parallel-TestFileDirExists branch from 99df383 to e44f5a0 Compare June 16, 2025 14:37
err := os.Symlink(file, link)
return link, err
}
func getTempSymlinkPath(t *testing.T, file string) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can improve naming:

Suggested change
func getTempSymlinkPath(t *testing.T, file string) string {
func tempSymlinkPath(t *testing.T, file string) string {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency internal/cleanup Internal change to ease maintenance without external impact internal/refactor Refactor internals with no external visible changes internal/testing Changes purely related to the testify testsuites pkg-assert Change related to package testify/assert
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants