Skip to content
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

test: add unit tests for pkg/resolution/resource #6433

Merged
merged 1 commit into from
Apr 21, 2023

Conversation

l-qing
Copy link
Contributor

@l-qing l-qing commented Mar 26, 2023

fix #6429

I found two minor bugs while writing unit tests 😁:

  • ownerRefsAreEqual checking owner reference equality to always return false.
    • Currently, the owner is originally empty.
    • So, there is no impact at the moment.
  • GenerateDeterministicName not consider params when generating unique names.
    • Currently, including the taskrun name in the base name can to some extent avoid conflicts.
    • So, there is no impact at the moment.

These two bugs currently do not have any substantial impact.

Changes

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including
    functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings)
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

@tekton-robot tekton-robot added the release-note-none Denotes a PR that doesnt merit a release note. label Mar 26, 2023
@tekton-robot tekton-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 26, 2023
@tekton-robot
Copy link
Collaborator

Hi @l-qing. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@l-qing
Copy link
Contributor Author

l-qing commented Mar 26, 2023

/kind bug
/kind flake

@tekton-robot tekton-robot added kind/bug Categorizes issue or PR as related to a bug. kind/flake Categorizes issue or PR as related to a flakey test labels Mar 26, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 92.9%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%
test/loadfile.go Do not exist 88.9%

@l-qing
Copy link
Contributor Author

l-qing commented Mar 26, 2023

/assign lbernick

@tekton-robot tekton-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 26, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 92.9%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%
test/loadfile.go Do not exist 100.0%

// ResolverName is the type used for a resolver's name and is mostly
// used to ensure the function signatures that accept it are clear on the
// purpose for the given string.
type ResolverName string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move from:

// ResolverName is the type used for a resolver's name and is mostly
// used to ensure the function signatures that accept it are clear on the
// purpose for the given string.
type ResolverName string
// Requester is the interface implemented by a type that knows how to
// submit requests for remote resources.
type Requester interface {
// Submit accepts the name of a resolver to submit a request to
// along with the request itself.
Submit(context.Context, ResolverName, Request) (ResolvedResource, error)
}
// Request is implemented by any type that represents a single request
// for a remote resource. Implementing this interface gives the underlying
// type an opportunity to control properties such as whether the name of
// a request has particular properties, whether the request should be made
// to a specific namespace, and precisely which parameters should be included.
type Request interface {
Name() string
Namespace() string
Params() []pipelinev1beta1.Param
}
// OwnedRequest is implemented by any type implementing Request that also needs
// to express a Kubernetes OwnerRef relationship as part of the request being
// made.
type OwnedRequest interface {
OwnerRef() metav1.OwnerReference
}
// ResolvedResource is implemented by any type that offers a read-only
// view of the data and metadata of a resolved remote resource.
type ResolvedResource interface {
Data() ([]byte, error)
Annotations() map[string]string
Source() *pipelinev1beta1.ConfigSource
}

avoid cycle import. 😁

The test package references these interfaces.

resolution "github.com/tektoncd/pipeline/pkg/resolution/resource"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although moving the interface to write unit tests is not reasonable, since the methods in the test package are referenced in multiple places, I can only choose the way to make the minimum changes.

And I also need to use existing methods in the test package, I don't want to duplicate them here.

pkg/resolution/resource/crd_resource.go Outdated Show resolved Hide resolved
pkg/resolution/resource/name.go Outdated Show resolved Hide resolved
test/loadfile.go Outdated Show resolved Hide resolved
test/resolution.go Show resolved Hide resolved
test/resolution.go Show resolved Hide resolved
@l-qing
Copy link
Contributor Author

l-qing commented Mar 26, 2023

/remove-kind bug

@tekton-robot tekton-robot removed the kind/bug Categorizes issue or PR as related to a bug. label Mar 26, 2023
Copy link
Member

@lbernick lbernick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much @l-qing! I love that you were able to find two bugs by adding these tests-- that's great!

pkg/resolution/resource/crd_resource_test.go Outdated Show resolved Hide resolved
pkg/resolution/resource/crd_resource_test.go Outdated Show resolved Hide resolved
pkg/resolution/resource/crd_resource_test.go Outdated Show resolved Hide resolved
pkg/resolution/resource/crd_resource_test.go Outdated Show resolved Hide resolved
pkg/resolution/resource/crd_resource_test.go Outdated Show resolved Hide resolved
pkg/resolution/resource/name.go Outdated Show resolved Hide resolved
pkg/resolution/resource/crd_resource_test.go Outdated Show resolved Hide resolved
pkg/resolution/resource/crd_resource_test.go Outdated Show resolved Hide resolved
test/loadfile.go Outdated Show resolved Hide resolved
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 92.9%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%
test/loadfile.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 97.6%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%
test/loadfile.go Do not exist 100.0%

@l-qing l-qing requested review from lbernick and removed request for imjasonh and wlynch March 27, 2023 15:29
@l-qing
Copy link
Contributor Author

l-qing commented Mar 27, 2023

Hi, @lbernick.
I've adjusted the code based on your comments. Could you please take some time to review it again when you're available? Thanks!

@l-qing
Copy link
Contributor Author

l-qing commented Mar 27, 2023

/cc @imjasonh @wlynch

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@l-qing
Copy link
Contributor Author

l-qing commented Apr 12, 2023

/retest

@QuanZhang-William
Copy link
Member

/assign

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@QuanZhang-William QuanZhang-William removed their assignment Apr 18, 2023
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage-df to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/resolution/resource/crd_resource.go Do not exist 83.3%
pkg/resolution/resource/name.go Do not exist 76.2%
pkg/resolution/resource/request.go Do not exist 100.0%

@l-qing
Copy link
Contributor Author

l-qing commented Apr 21, 2023

/retest

@lbernick
Copy link
Member

/lgtm
I don't think there's much benefit to having you continue to rebase; just going to go ahead and merge this

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 21, 2023
@l-qing
Copy link
Contributor Author

l-qing commented Apr 21, 2023

/lgtm I don't think there's much benefit to having you continue to rebase; just going to go ahead and merge this

Thanks!

@tekton-robot tekton-robot merged commit a7424c4 into tektoncd:main Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/flake Categorizes issue or PR as related to a flakey test lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesnt merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tests for pkg/resolution/resource
6 participants