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

Add the ability to mock more SCM data for git resolver tests #5531

Merged
merged 1 commit into from
Sep 22, 2022

Conversation

abayer
Copy link
Contributor

@abayer abayer commented Sep 21, 2022

Changes

Specifically, it adds the ability to cheat a "fake" list of repositories into the SCM client for use in adding the clone URL to the resolved resource annotations, as needed in #5397.

/kind misc

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

@abayer abayer added the kind/misc Categorizes issue or PR as a miscellaneuous one. label Sep 21, 2022
@tekton-robot tekton-robot added the release-note-none Denotes a PR that doesnt merit a release note. label Sep 21, 2022
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 21, 2022
@abayer
Copy link
Contributor Author

abayer commented Sep 21, 2022

/assign @chuangw6 @lbernick @vdemeester

@tekton-robot
Copy link
Collaborator

@abayer: GitHub didn't allow me to assign the following users: chuangw6.

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.
For more information please see the contributor guide

In response to this:

/assign @chuangw6 @lbernick @vdemeester

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.

@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/resolver/git/resolver.go 84.6% 84.8% 0.1

Copy link
Member

@chuangw6 chuangw6 left a comment

Choose a reason for hiding this comment

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

Thanks @abayer for adding this to take url testing into account!

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chuangw6, vdemeester

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 22, 2022
@@ -147,19 +152,32 @@ func (r *Resolver) resolveAPIGit(ctx context.Context, params map[string]string)
if err != nil {
return nil, fmt.Errorf("failed to create SCM client: %w", err)
}

// If we have fake data for the scm client, replace the scm client with a fake client with the fake data
if r.fakeData != nil && scmClient.Driver == scm.DriverFake {
Copy link
Member

Choose a reason for hiding this comment

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

would it make more sense to pass a client in as an argument to a helper function, or store the client on the resolver or something like that? (i.e. more like the dependency injection we use elsewhere in the codebase). It feels strange to mix test functionality and real functionality in the resolver code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the deliberate choice to create the client at resolution time every time. That way we don't have to specifically watch for changes to the token secret and then create a new client, and the work I'm doing for #5487 will mean we support multiple providers, which means different clients will be needed at runtime for each client, etc.

I guess we could have a field on the resolver that's a function for creating the client, with the default implementation being what we do now, and tests can override that?

Copy link
Member

Choose a reason for hiding this comment

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

maybe the resolution function can accept a client creation function as an argument? kind of like getpipelinefunc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would need to be on the resolver, not the function, since the actual path to calling Resolve(...) in the tests is off in frtesting.RunResolverReconcileTest. Lemme try something.

@abayer
Copy link
Contributor Author

abayer commented Sep 22, 2022

/hold

@lbernick How's 69171b7?

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 22, 2022
@lbernick
Copy link
Member

I like that approach!

@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/resolver/git/resolver.go 84.6% 83.9% -0.8

@abayer
Copy link
Contributor Author

abayer commented Sep 22, 2022

woo! Squashing it down now.

Specifically, it adds the ability to cheat a "fake" list of repositories into the SCM client for use in adding the clone URL to the resolved resource annotations, as needed in tektoncd#5397.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
@abayer
Copy link
Contributor Author

abayer commented Sep 22, 2022

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 22, 2022
@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/resolver/git/resolver.go 84.6% 83.9% -0.8

@lbernick
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 22, 2022
@tekton-robot tekton-robot merged commit 765ef04 into tektoncd:main Sep 22, 2022
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/misc Categorizes issue or PR as a miscellaneuous one. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants