fix(test): check os.WriteFile error in fileutil test #5363
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Need for Change:
This PR fixes a missing error check in a unit test.
In internal/fileutil/fileutil_test.go, the test case TestFileExists/file-with-content was calling os.WriteFile without checking its returned error. If the write failed (for example due to permission issues, disk errors, or a read-only filesystem), the test would continue assuming the file was written successfully. This could lead to misleading failures or false positives later in the test.
Other tests in the same file already validate os.WriteFile errors, so this change also improves consistency.
##Type of change:
##Changes Made:
File: internal/fileutil/fileutil_test.go
Line: 54
Wrapped os.WriteFile with require.NoError(t, ...) to ensure the test fails immediately if the write operation fails.
##Impact:
-Prevents silent failures in the test
-Produces clearer and more accurate test results
-Improves consistency with existing test patterns
-No functional or behavioral changes to production code
##Steps to Reproduce
-In internal/fileutil/fileutil_test.go (line 54), os.WriteFile is called without checking its error return.
-Run the test:
go test -v ./internal/fileutil -run TestFileExists/file-with-content-Create a small test case (or environment) where the target directory is read-only or unwritable. In this scenario, os.WriteFile fails, but the test continues because the error is ignored.
After the fix, the test fails immediately when os.WriteFile returns an error.
Impact: Ignoring the error can cause tests to pass or fail for misleading reasons
wh