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

jira: general client improvements #26564

Merged
merged 3 commits into from
Jun 23, 2022

Conversation

AlexNPavel
Copy link
Contributor

This PR fixes the fakejira CloneIssue and CreateIssue functions
along with adding unit tests for them, adds more extensive issue
function errors for the fakeclient, and modifies the
DeleteRemoteLinkViaURL function to return a bool indicating whether
a link with the provided URL was found and removed (no remote link with
the provided URL is not an error).

These improvements will be used in a new openshift external prow plugin
called the jira-lifecycle plugin, which will replicate the bugzilla
plugins functionality, but with the Jira service instead of bugzilla.

/cc @stevekuznetsov @alvaroaleman

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/prow Issues or PRs related to prow area/prow/plugins Issues or PRs related to prow's plugins for the hook component sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Jun 13, 2022
This PR fixes the fakejira `CloneIssue` and `CreateIssue` functions
along with adding unit tests for them, adds more extensive issue
function errors for the fakeclient, and modifies the
`DeleteRemoteLinkViaURL` function to return a `bool` indicating whether
a link with the provided URL was found and removed (no remote link with
the provided URL is not an error).

These improvements will be used in a new openshift external prow plugin
called the `jira-lifecycle` plugin, which will replicate the `bugzilla`
plugins functionality, but with the Jira service instead of bugzilla.
@AlexNPavel AlexNPavel force-pushed the jira-client-improvements branch from 6e96f94 to 4534311 Compare June 13, 2022 23:40
@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 13, 2022
f.updateIssueIDAndKey(issueCopy)
// run generic cloning function
return jiraclient.CloneIssue(f, issueCopy)
return jiraclient.CloneIssue(f, issue)
}

func (f *FakeClient) CreateIssue(issue *jira.Issue) (*jira.Issue, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What, exactly, is this helping? Having to build a fake Jira sounds like testing is happening at the wrong level. See also: how this repo has not built a fake GitHub, Bugzilla, S3, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by this repo not building a fake github or bugzilla? There is a fakegithub and a fake bugzilla client that are used heavily by unit testing in plugins. This fake jira client isn't much different.

Copy link
Contributor

Choose a reason for hiding this comment

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

Those are simple in-memory maps that we add to / delete from using the methods. They do not encode provider-specific implementation details like ("issue.fields.project must be set to create new issue").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

ptrIssues = append(ptrIssues, &tc.existingIssues[index])
}
fakeClient := &FakeClient{Issues: ptrIssues}
newIssue, err := fakeClient.CreateIssue(&tc.issue)
Copy link
Contributor

Choose a reason for hiding this comment

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

These are unit tests for a fake ... ? This doesn't seem right - in the fake you might inject data, or validate that calls happen to the right endpoints. There's nothing making sure that the fake implementation of the clone here is the same as what Jira actually does, so ensuring it is "correct" here is not helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CreateIssue function was very poorly implemented before to the point that it was basically useless (that was my fault as I wrote it). I just wanted to make sure it was generally close enough when fixing the implementation. For the CloneIssue function, we just call a generic function that is shared by the fake and real clients so this tests that, but makes it does make calls to CreateIssueLink and CreateIssue of the client provided (in this case fake client), so you could say it's not a truly accurate test.

If you would rather not have unit tests for the fake client, I could remove these tests.

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 have removed the unit tests.

@AlexNPavel AlexNPavel force-pushed the jira-client-improvements branch 2 times, most recently from 7878953 to 7d42023 Compare June 21, 2022 23:23
This commit removes the unit tests for the fake client and simplifies
the `CreateIssue` function by removing checks for unsettable fields.
@AlexNPavel AlexNPavel force-pushed the jira-client-improvements branch from 7d42023 to 0587179 Compare June 21, 2022 23:41
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 21, 2022
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 23, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlexNPavel, stevekuznetsov

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

@k8s-ci-robot k8s-ci-robot merged commit 3ef0bc3 into kubernetes:master Jun 23, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.25 milestone Jun 23, 2022
@AlexNPavel AlexNPavel deleted the jira-client-improvements branch June 23, 2022 15:27
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. area/prow/plugins Issues or PRs related to prow's plugins for the hook component area/prow Issues or PRs related to prow cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants