-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 accumulateResources error tests for local files #5225
Add accumulateResources error tests for local files #5225
Conversation
Skipping CI for Draft Pull Request. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: annasong20 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 |
710d909
to
d03abc4
Compare
Add tests demonstrating accumulateResources errors when the resource is a local file. Works to address kubernetes-sigs#4807.
d03abc4
to
f84afda
Compare
/assign |
errFile, errDir string | ||
} | ||
populateAbsolutePaths := func(tc testcase, dir string) testcase { | ||
filePaths := make(map[string]string, len(tc.files)+1) |
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 len
and range of tc.files
are the same numerics.
Are you need +1
for len(tc.files)
for any reason?
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 moved this line of code: https://github.com/kubernetes-sigs/kustomize/pull/5225/files#diff-15a9eb3d3d62fd27ecea240ff711d887220b80ac54f3f709a7ed8bc25632a837R195 Does this make it easier to understand?
In addition to all the files we need to create specified by the test case, we also need to create the build root or the direct kustomization that we run kustomize build
on.
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.
Sorry, This is my misunderstanding.
Thanks for explaining that!
api/loader/fileloader_test.go
Outdated
_, err := makeLoader().New("https://google.com/project") | ||
require.Error(t, err) | ||
func TestNewRemoteLoaderDoesNotExist(t *testing.T) { | ||
_, err := makeLoader().New("https://example.com/project") |
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 it will be easy to understand to use the same URL for getting the same reason.
https://github.com/kubernetes-sigs/kustomize/pull/5225/files#diff-15a9eb3d3d62fd27ecea240ff711d887220b80ac54f3f709a7ed8bc25632a837R224.
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 great catch! I've changed the root url.
I did a little digging, and it turns out I blindly copied this existing test that was running incorrectly. The history of this test is as follows:
- This test existed before my previous PR, which only moved it.
- This test existed at a time when any
http
url was considered a repo
Hence, this test originally wanted to check that New()
failed when the repo url didn't exist. I assume someone forgot to update this test when they updated api/internal/git/repospec
.
To defend against this, I check in the error that the loader tried to fetch
the url.
The url is not exactly the same as in the accumulation_test
because there I want to clarify where a url is treated as a remote file vs. repo, whereas I don't think we need that here since we explicitly call New()
. I'm also happy to change this on further feedback, though.
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 investigating!
@@ -635,6 +661,8 @@ func TestLoaderHTTP(t *testing.T) { | |||
|
|||
// setupOnDisk sets up a file system on disk and directory that is cleaned after | |||
// test completion. | |||
// TODO(annasong): Move all loader tests that require real file system into |
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.
Looks like, according to your comment, you have a plan to remove the setupOnDisk() function and replace it with the Setup() function?
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.
Essentially, yeah. I plan to move all tests calling setupOnDisk
into krusty/remoteloader_test.go
(will rename to loader_test.go
), then replace calls to setupOnDisk
with Setup
.
I can't replace setupOnDisk
with Setup
in fileloader_test.go
because it would create a cyclic dependency.
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 great plan!
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. |
/label tide/merge-method-squash |
/lgtm |
This is part of the effort to address #4807.
This PR tests
accumulateResources
error messages forresources
that are faulty local files.