-
Notifications
You must be signed in to change notification settings - Fork 31
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
chore: add windows tests #120
Conversation
bc7b2b1
to
ebbdab2
Compare
ebbdab2
to
b819092
Compare
9a8b1c6
to
727413b
Compare
727413b
to
2628801
Compare
/label tide/merge-method-squash |
c27bbe7
to
9a44bb1
Compare
pkg/openapiclient/local_schemas.go
Outdated
versions, err := utils.ReadDir(k.fs, groupPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed reading local files dir %s: %w", groupPath, err) | ||
if apiGroups, err := fs.ReadDir(k.fs, "apis"); err == nil { |
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.
note that the behaviour changes slightly. this is because it seems impossible to have a consistent behaviour between windows and linux :(
see golang/go#46734
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.
IIUC the go issue you linked refers to files opened with ReadDir
returning true for errors.Is(err, fs.ErrNotExist)
That would mean for files with the name apis
we throw no error and apiGroups
is empty. I think that is preferrable to the current diff which throws out all errors.
Was the original code causing problems? If i understood correctly as above I feel like it wouldnt throw any more errors, just throw one less error for the file-named-apis case.
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.
IIRC the inconsistency case was when calling ReadDir
on a file.
That would mean for files with the name apis we throw no error and apiGroups is empty. I think that is preferrable to the current diff which throws out all errors.
In this case ReadDir
will fail, err == nil
will not be true and apiGroups
is not considered at all.
My feeling was that we were becoming more permissive with this kind of errors so it made sense to check err == nil
and just do nothing in case there was an error.
Let me know if you want me to change the behaviour but yeah the real problem is errors.Is(err, fs.ErrNotExist)
not being consistent across all systems (at least with an error we got from ReadDir
).
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.
Let me know if you want me to change the behaviour but yeah the real problem is errors.Is(err, fs.ErrNotExist) not being consistent across all systems (at least with an error we got from ReadDir).
Is it possible to check if the file exists without checking the ReadDir err
result? Like stat?
apiGroups, err := fs.ReadDir(k.fs, "apis")
if err != nil && CrossPlatformCheckDirExists(k.fs, "apis") {
return nil, fmt.Errorf("...: %w", err)
}
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.
We can probably do something like that.
Ultimately do you prefer returning an error in this case ? Or just skip the error to let the chain continue collecting paths ?
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.
If the dir does not exist it should skip it, but if it does exist and we couldn't read it then it should be an error
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.
Really appreciate you doing this! I had a few questions
pkg/openapiclient/local_schemas.go
Outdated
versions, err := utils.ReadDir(k.fs, groupPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed reading local files dir %s: %w", groupPath, err) | ||
if apiGroups, err := fs.ReadDir(k.fs, "apis"); err == nil { |
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.
IIUC the go issue you linked refers to files opened with ReadDir
returning true for errors.Is(err, fs.ErrNotExist)
That would mean for files with the name apis
we throw no error and apiGroups
is empty. I think that is preferrable to the current diff which throws out all errors.
Was the original code causing problems? If i understood correctly as above I feel like it wouldnt throw any more errors, just throw one less error for the file-named-apis case.
I think i introduced the bug... I break it, i fix it! =) |
9a44bb1
to
1375db5
Compare
1375db5
to
1e3c55d
Compare
fs: os.DirFS("../../invalid"), | ||
dir: ".", | ||
name: "not a dir", | ||
fs: os.DirFS("../../testcases/schemas/error_not_a_dir"), | ||
want: sets.New[string](), |
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 fails on windows returning a nil
set rather than an empty set, but not on *nix.
It is also curious to me that we can return nil
Paths()
but no error
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 is also curious to me that we can return nil Paths() but no error
If there's no api
nor apis
folders, what shall we return ?
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.
The problem was reading /api
/ /apis
without trying to read /
first 🙈
f64ac7d
to
3bed0bb
Compare
@alexzielenski tests are green finally :) |
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.
one more nit 😬
pkg/openapiclient/local_schemas.go
Outdated
func crossPlatformCheckDirExists(f fs.FS, path string) bool { | ||
_, err := fs.Stat(f, path) | ||
if err != nil { | ||
return !os.IsNotExist(err) |
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 looked at the implementation for os.IsNotExist...it seems very similar to errors.Is except it only looks at specific syscall error types and godoc advises agsinst new usage:
// IsNotExist returns a boolean indicating whether the error is known to
// report that a file or directory does not exist. It is satisfied by
// ErrNotExist as well as some syscall errors.
//
// This function predates errors.Is. It only supports errors returned by
// the os package. New code should use errors.Is(err, fs.ErrNotExist).
func IsNotExist(err error) bool {
return underlyingErrorIs(err, ErrNotExist)
}
Did the errors.Is check not work here?
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.
trying with errors.Is
...
// check if '.' can be listed | ||
if _, err := fs.ReadDir(k.fs, "."); err != nil { | ||
if crossPlatformCheckDirExists(k.fs, ".") { | ||
return nil, fmt.Errorf("error listing %s: %w", ".", err) | ||
} | ||
} |
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 assume this is right but I dont understand why this is necessary. My expectation was that if .
cant be listed then ReadDir
would yield an error? I'd expect the crossPlatfomrCheckDirExists
check after that to not skip the error since it wouldnt be an IsNotExist error, but some permission or something?
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.
My feeling is that if .
is a file and we try to list /api
it returns a not exist on windows. It's hard to check as i don't have a windows box but i can send a unit test and log the results...
3bed0bb
to
b711c2f
Compare
/lgtm |
@alexzielenski Shouldn't |
b711c2f
to
1ad4da4
Compare
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
1ad4da4
to
0bd7a50
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alexzielenski, eddycharly The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: