-
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
Changes from 4 commits
dfd2d76
53a4134
cd49194
694b3c9
8383b28
565cff2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ func TestAddComponentHappyPath(t *testing.T) { | |
} | ||
|
||
func TestAddComponentAlreadyThere(t *testing.T) { | ||
fSys := filesys.MakeFsInMemory() | ||
fSys := filesys.MakeEmptyDirInMemory() | ||
err := fSys.WriteFile(componentFileName, []byte(componentFileContent)) | ||
require.NoError(t, err) | ||
testutils_test.WriteTestKustomization(fSys) | ||
|
@@ -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 commentThe 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 @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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added it at 565cff2. |
||
fSys := filesys.MakeFsInMemory() | ||
fSys := filesys.MakeEmptyDirInMemory() | ||
err := fSys.WriteFile(componentFileName, []byte(componentFileContent)) | ||
require.NoError(t, err) | ||
testutils_test.WriteTestKustomization(fSys) | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I think so. |
||
assert.Contains(t, string(content), componentFileName) | ||
} | ||
|
||
func TestAddComponentNoArgs(t *testing.T) { | ||
|
@@ -73,3 +73,13 @@ func TestAddComponentNoArgs(t *testing.T) { | |
err := cmd.Execute() | ||
assert.EqualError(t, err, "must specify a component file") | ||
} | ||
|
||
func TestAddComponentFileNotFound(t *testing.T) { | ||
fSys := filesys.MakeEmptyDirInMemory() | ||
|
||
cmd := newCmdAddComponent(fSys) | ||
args := []string{componentFileName} | ||
|
||
err := cmd.RunE(cmd, args) | ||
assert.EqualError(t, err, componentFileName+" has no match: must build at directory: not a valid directory: '"+componentFileName+"' doesn't exist") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I updated this function comment at 8383b28. |
||
} else { | ||
result = append(result, pattern) | ||
if loader != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,8 +89,9 @@ func TestGlobPatternsWithLoaderRemoteFile(t *testing.T) { | |
} | ||
|
||
// test load invalid file | ||
resources, err = GlobPatternsWithLoader(fSys, ldr, []string{"http://invalid"}) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Can we also add a check here for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed it at 8383b28. |
||
t.Fatalf("unexpected load error: %v", err) | ||
} | ||
if len(resources) > 0 { | ||
|
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.