-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 unit tests for bundle resolver #5704
Conversation
The following is the coverage report on the affected files.
|
/approve |
d11e604
to
d2f35b9
Compare
The following is the coverage report on the affected files.
|
/retest |
d2f35b9
to
44ef0b5
Compare
The following is the coverage report on the affected files.
|
44ef0b5
to
1d27883
Compare
The following is the coverage report on the affected files.
|
1d27883
to
fd836e8
Compare
fd836e8
to
0aca5ff
Compare
The following is the coverage report on the affected files.
|
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! This lgtm. Feel free to resolve my comments
@@ -169,3 +171,26 @@ func ensureConfigurationConfigMapsExist(d *test.Data) { | |||
}) | |||
} | |||
} | |||
|
|||
// CreateResolutionRequestStatusWithData returns a ResolutionRequestStatus with the resolved content. | |||
func CreateResolutionRequestStatusWithData(content []byte) *v1beta1.ResolutionRequestStatus { |
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'm not sure if having those files in the fakecontroller.go
file is good or not. 😂 Or they could be in a new separate file? Those functions seem not controller related...?
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.
SGTM! Created a new file named resolutionrequest.go
, and they are now living in this new file :D PTAL.
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.
👍
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 hope I could have the lgtm permission 😂
0aca5ff
to
1c79659
Compare
The following is the coverage report on the affected files.
|
@chuangw6: GitHub didn't allow me to assign the following users: wl. Note that only tektoncd members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time. In response to this:
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. |
/assign @wlynch |
t.Fatalf("could not push image: %#v", err) | ||
} | ||
// set bundle param to be the image ref | ||
tc.args.bundle = ref |
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 doesn't look like this is ever set in args. Let's just set it here. (same with service account - it doesn't look like it's ever used).
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 doesn't look like this is ever set in args. Let's just set it here.
Sounds good. I pre-populated the oci registry with images, and the ref is used for the args.bundle in the test table. PTAL.
same with service account - it doesn't look like it's ever used
Yes, service account is not used in the test, but the param validation expects this to be set somewhere either from param or configmap, otherwise the param validation will fail. That's why we added a placeholder service account field in the configmap. PTAL and let me know wdyt. Thanks!
|
||
ctx, _ := ttesting.SetupFakeContext(t) | ||
|
||
resolver := &Resolver{ |
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.
Doesn't look like this is ever modified. Hoist out of the loop?
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.
Done. Thanks!
expectedErrMessage: fmt.Sprintf("contained more than the maximum %d allow objects", MaximumBundleObjects), | ||
}, { | ||
name: "single-task-no-version", | ||
objs: []runtime.Object{&pipelinev1beta1.Task{TypeMeta: metav1.TypeMeta{Kind: "task"}, ObjectMeta: metav1.ObjectMeta{Name: "foo"}}}, |
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.
Similar to the repo tests - you could probably simplify this by just prepopulating a single OCI test registry with a few different kinds of bundles and just fetch the different values.
By decoupling it from the CRDs this also lets you setup some other interesting tests like what if you try to fetch a valid OCI artifact that isn't a Tekton bundle? 🤔
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.
Similar to the repo tests - you could probably simplify this by just prepopulating a single OCI test registry with a few different kinds of bundles and just fetch the different values.
Good idea. Done. PTAL. Thanks
By decoupling it from the CRDs this also lets you setup some other interesting tests like what if you try to fetch a valid OCI artifact that isn't a Tekton bundle? 🤔
This is interesting. Just play around a bit. It seems like the implementation code will checkImageCompliance after retrieving the image by only checking required annotations and the number of layers. Therefore,
1). if we want to create a valid but non-tekton oci artifact without those annotations, the existing tests i.e. single-task-no-version
basically cover that.
2). if we want to create a valid but non-tekton oci artifact with those required annotations, the resolution will succeed.
- sounds a bit odd b/c a valid oci artifact that isn't a tekton bundle normally shouldn't have those required annotations in its layers. Please let me know what you think.
limitations under the License. | ||
*/ | ||
|
||
package testing |
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.
Make this an internal package.
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.
Done. Put it under pkg/resolution/resolver/internal
. Thank you for the suggestion!!
expectedStatus = tc.expectedStatus.DeepCopy() | ||
if tc.expectedErrMessage == "" { | ||
reqParams := make(map[string]string) | ||
for _, p := range request.Spec.Params { |
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.
Same as the repo tests, it looks like we're feeding in request data into the expected response. Can we simplify the comparisons here so it's easier to see what's being compared and what fields we're expecting to be returned for each request?
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.
Good point. Done. Please take a look.
One possible direction to make it even more clear to see what we expect is to explicitly declare what is expected annotation and source other than the data in the ResolutionRequestStatus in the test table instead of inside the for loop. But I guess the downside is that the test table will be too verbose. Not sure if we want to go down that path. If so, happy to do it in another pr (b/c this might need to change the util helper CreateResolutionRequestStatusWithData
's interface, and therefore change tests in gitresolver).
a261a1a
to
02e1ee0
Compare
The following is the coverage report on the affected files.
|
02e1ee0
to
9afacdd
Compare
The following is the coverage report on the affected files.
|
9afacdd
to
2052a03
Compare
The following is the coverage report on the affected files.
|
2052a03
to
695b407
Compare
Prior, remote bundle solver didn't have unit test for the resolve method. In this commit, we added the unit test by setup a local test registry. Note: Some commonly used testing helpers are extracted to pkg/resolution/resolver/framework/testing/fakecontroller.go file. Signed-off-by: Chuang Wang <chuangw@google.com>
695b407
to
dad54cd
Compare
The following is the coverage report on the affected files.
|
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 great!
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: abayer, vdemeester, wlynch, Yongxuanzhang 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 |
Changes
/kind misc
Prior, remote bundle solver didn't have unit test for the resolve method.
In this commit, we added the unit test by setup a local test registry.
Note: Some commonly used testing helpers are extracted to
pkg/resolution/resolver/framework/testing/fakecontroller.go file.
Signed-off-by: Chuang Wang chuangw@google.com
Submitter Checklist
As the author of this PR, please check off the items in this checklist:
functionality, content, code)
/kind <type>
. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes