fix(envfile_test): Fix unit test error in Windows #43
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.
该问题仅存在于 Windows 系统中。
问题现象
在 Windows 系统下运行
go test
进行单元测试时无法通过,但在 Linux 系统下则正常。调试后发现
os.Remove(envPath)
等方法在 Windows 中并没有删除文件,而是报错:从而导致某些依赖于不存在
.env
文件的单元测试无法通过。问题原因
Windows 系统不允许直接删除已打开的文件。
解决方法
在
envfile_test
中删除.env
文件前关闭文件。测试在进行该处理之后在,于 Windows 和 Liunx 下的单元测试均可正常通过了。