-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
be error when no path matching #5030
be error when no path matching #5030
Conversation
if err == nil { | ||
t.Fatalf("unexpected load error: %v", 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.
question: If err is nil isn't there 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.
I fix this line.
@@ -42,7 +42,7 @@ func GlobPatternsWithLoader(fSys filesys.FileSystem, ldr ifc.Loader, patterns [] | |||
if len(files) == 0 { | |||
loader, err := ldr.New(pattern) | |||
if err != nil { | |||
log.Printf("%s has no match", pattern) | |||
return nil, fmt.Errorf("%s has no match", pattern) |
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.
suggestion: Maybe worth including the original 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.
That is a good suggestion. Thanks!
I add it.
This PR has multiple commits, and the default merge method is: merge. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/lgtm |
@@ -63,7 +63,7 @@ func TestAddKustomizationFileAsComponent(t *testing.T) { | |||
|
|||
content, err := testutils_test.ReadTestKustomization(fSys) | |||
require.NoError(t, err) | |||
assert.NotContains(t, string(content), componentFileName) |
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.
Was this test previously broken?
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 think so.
@@ -38,7 +38,7 @@ func TestAddComponentHappyPath(t *testing.T) { | |||
} | |||
|
|||
func TestAddComponentAlreadyThere(t *testing.T) { | |||
fSys := filesys.MakeFsInMemory() | |||
fSys := filesys.MakeEmptyDirInMemory() |
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.
Why these changes?
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.
Because I think these test cases were broken.
It looks like MakeEmptyDirInMemory
is required for the parent directory position for the file path parameter.
But, these test cases were passed despite using the wrong parameter.
So, I fixed to use this function that is not required for the parent directory position.
If you want, I can rewrite for using filesys.MakeEmptyDirInMemory()
like the below case.
func TestAddComponentAlreadyThere(t *testing.T) {
fSys := filesys.MakeFsInMemory()
err := fSys.WriteFile(componentFileName, []byte(componentFileContent))
require.NoError(t, err)
testutils_test.WriteTestKustomization(fSys)
cmd := newCmdAddComponent(fSys)
args := []string{"/" + componentFileName} // add '/' dir for parameter.
assert.NoError(t, cmd.RunE(cmd, args))
// adding an existing component doesn't return an error
assert.NoError(t, cmd.RunE(cmd, args))
}
@@ -42,7 +42,7 @@ func GlobPatternsWithLoader(fSys filesys.FileSystem, ldr ifc.Loader, patterns [] | |||
if len(files) == 0 { | |||
loader, err := ldr.New(pattern) | |||
if err != nil { | |||
log.Printf("%s has no match", pattern) | |||
return nil, fmt.Errorf("%s has no match: %w", pattern, 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.
can we add a new "edit add" test covering this error case please?
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 add test cases at 694b3c9.
I think this function is called by only below 3 points.
https://github.com/search?q=repo%3Akubernetes-sigs%2Fkustomize+util.GlobPatternsWithLoader&type=code
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.
Can you update the comment description of this function to specify that it returns an error if there are no matching files and it can't load from remote?
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 updated this function comment at 8383b28.
I fixed and responded to your comments. |
85a4c4b
to
6508cf6
Compare
6508cf6
to
694b3c9
Compare
if err != nil { | ||
invalidURL := "http://invalid" | ||
resources, err = GlobPatternsWithLoader(fSys, ldr, []string{invalidURL}) | ||
if err != nil && err.Error() != invalidURL+" has no match: "+invalidURL+" not exist" { |
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.
Can we also add a check here for
if err == nil {
t.Fatalf("expected error but did not receive one")
}
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 fixed it at 8383b28.
@@ -42,7 +42,7 @@ func GlobPatternsWithLoader(fSys filesys.FileSystem, ldr ifc.Loader, patterns [] | |||
if len(files) == 0 { | |||
loader, err := ldr.New(pattern) | |||
if err != nil { | |||
log.Printf("%s has no match", pattern) | |||
return nil, fmt.Errorf("%s has no match: %w", pattern, 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.
Can you update the comment description of this function to specify that it returns an error if there are no matching files and it can't load from remote?
@@ -52,7 +52,7 @@ func TestAddComponentAlreadyThere(t *testing.T) { | |||
} | |||
|
|||
func TestAddKustomizationFileAsComponent(t *testing.T) { |
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 think this test was originally supposed to check that if you try to add the kustomization.yaml file itself to components
, it won't get added.
@annasong20 attempted to fix this in https://github.com/kubernetes-sigs/kustomize/pull/4702/files#diff-6f49ffbefe3aa6f9f90b63fa94b7019f1004257536c2264e6445f7b311d10b99, but it fell off our radar and it never merged. Do you mind picking up her fixes from TestAddKustomizationFileAsComponent
and TestAddKustomizationFileAsResource
from that PR?
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 added it at 565cff2.
Hi @natasha41575 |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: koba1t, natasha41575 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 happened?
kustomize edit
command does not return an error when adding no matching path.What doing?
It was caused by this line only show the warning message.
I think better return the error on this line.
Maybe this fix is not the best, please write your opinions if you have any.