io/fs: should fs.Sub(fsys, "no such directory") return a file system that fails fstest.TestFS? #45087
Labels
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
If you mean latest released Go, then yes.
If you mean
tip
, I'm not sure, but I expect so.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/eXsqSUYHWQs
What did you expect to see?
No error returned.
What did you see instead?
It fails due to lack of an empty root directory:
This may very well be a "works as intended" issue, and if so I apologise for the noise.
FYI: I ran into this while experimenting with implementing the opposite of
fs.Sub
, aPrefix(fs.FS, string) (fs.FS, error)
.I provided a
prefixFS.Sub
as an optimisation where it returns anotherprefixFS
with the prefix adjusted or callsfs.Sub
on it's underlying file system to avoid chaining multiple wrappers. I ended up also implementing anEmptyFS
that I return when the sub-dir isn't within my prefix in order to keepfstest.TestFS
happy.I imagine others implementing
fs.SubFS
and trying to test their code would appreciate not having to make their ownEmptyFS
just to satisfyfstest.TestFS
. Perhaps an empty file system implementation could be provided orfstest
could be tweaked with respect to what it accepts as a completely emtpy file system.The text was updated successfully, but these errors were encountered: