-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add wrapper for io/fs #81
Conversation
Signed-off-by: Evan Anderson <[email protected]>
So, it looks like the FS test fails on 1.22 and earlier (as I mentioned in the original PR) because the |
I added some line filtering that I hope will work for go <= 1.22. I haven't specifically set up a test environment, but I may try doing so if the workflows don't run in the next day or so. |
I got the chance to test on go 1.20.3 this evening, and discovered that the pre-1.23 error includes the line |
(I think this should pass CI now) |
@evankanderson thanks for putting this PR together.
|
helper/iofs/iofs_test.go
Outdated
files := map[string]string{ | ||
"foo.txt": "hello, world", | ||
"bar.txt": "goodbye, world", | ||
"dir/baz.txt": "こんにちわ, world", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be good that tests take into account OS specific things, such as path separators:
"dir/baz.txt": "こんにちわ, world", | |
filepath.Join("dir","baz.txt"): "こんにちわ, world", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out that fstest.testFS
isn't written in a Windows-aware way (e.g. https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/testing/fstest/testfs.go;l=147), so I skipped this test on Windows for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me sad, but not sad enough to re-implement fstest.testFS in this file, given that we have Linux coverage and billy coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, I think I addressed all of it (and it should pass the Windows CI leg now).
helper/iofs/iofs_test.go
Outdated
files := map[string]string{ | ||
"foo.txt": "hello, world", | ||
"bar.txt": "goodbye, world", | ||
"dir/baz.txt": "こんにちわ, world", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out that fstest.testFS
isn't written in a Windows-aware way (e.g. https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/testing/fstest/testfs.go;l=147), so I skipped this test on Windows for now.
helper/iofs/iofs_test.go
Outdated
files := map[string]string{ | ||
"foo.txt": "hello, world", | ||
"bar.txt": "goodbye, world", | ||
"dir/baz.txt": "こんにちわ, world", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me sad, but not sad enough to re-implement fstest.testFS in this file, given that we have Linux coverage and billy coverage.
I'm willing to bump go.mod and the tests, but I'd prefer to do it in a separate PR. (And this should pass on 1.20 if someone is using something that old). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evankanderson small change on the API to align with the rest of helpers, apart from that LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @evankanderson thanks for working on this. 🙇
Fixes #11
I did not implement
SubFS
orGlobFS
, because those seemed a bit trickier, and I didn't need them for my use case. 😁 Another option would be to extend thebilly.File
interface to add aStat()
method, but that seemed like a breaking ("v6") change, at which point you might simply want to rewrite towardsio/fs
, which has a testing memory filesystem already.It turns out that the Go
fstest.TestFS
is a bit more stringent than the billy tests,and it checks to see whether two
Stat()
calls return the same results on the same file. I disabled those tests in the unit test, but we could also adjust the Memfs implementation to store the ModTimes on each file when they are created. I thought the extra in-memory storage probably wasn't worth it, but I have a patch if you'd prefer that approach.Note that you'll probably need Go 1.23.x to pick up this change to the errors returned by
fstest.TestFS()
.