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

use helper function for UserSignup creation in verification tests #492

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MatousJobanek
Copy link
Contributor

This PR replaces manual creation of UserSignups with helper functions from toolchain common.

Why?
My ultimate goal is to clean up the leftovers that stayed there after the migration of the naming format of UserSignups that happened a few years ago.

func (s *ServiceImpl) DoGetUserSignupFromIdentifier(cl namespaced.Client, userID, username string) (*toolchainv1alpha1.UserSignup, error) {
// Retrieve UserSignup resource from the host cluster
userSignup := &toolchainv1alpha1.UserSignup{}
if err := cl.Get(gocontext.TODO(), cl.NamespacedName(EncodeUserIdentifier(username)), userSignup); err != nil {
if apierrors.IsNotFound(err) {
// Capture any error here in a separate var, as we need to preserve the original
if err2 := cl.Get(gocontext.TODO(), cl.NamespacedName(EncodeUserIdentifier(userID)), userSignup); err2 != nil {
if apierrors.IsNotFound(err2) {
return nil, err
}
return nil, err2
}
return userSignup, nil
}
return nil, err
}
return userSignup, nil
}

We don't use the sub claim (userID) for UserSignups for a few years, but most of the unit tests still do that. This change is to minimize the final PR(s) that will drop the usage & support of the UserSignups with names equal to the sub claim (userID).

Copy link

sonarqubecloud bot commented Jan 9, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
33.0% Duplication on New Code (required ≤ 30%)

See analysis details on SonarQube Cloud

Copy link

openshift-ci bot commented Jan 9, 2025

@MatousJobanek: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e 7f510c1 link true /test e2e

Full PR test history. Your PR dashboard.

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-sigs/prow repository. I understand the commands that are listed here.

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

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

Looks good!
Thanks for cleaning it up.

I have only one minor comment/question.

userSignup := testusersignup.NewUserSignup(
testusersignup.WithName("johny"),
testusersignup.WithLabel(toolchainv1alpha1.UserSignupUserPhoneHashLabelKey, "+1NUMBER"),
testusersignup.VerificationRequired(0))
Copy link
Contributor

Choose a reason for hiding this comment

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

does this have the same effect as :

states.SetVerificationRequired(userSignup, true)

?
It looks like the latter sets the UserSignupStateVerificationRequired in the UserSignup.Spec.States and it doesn't update the conditions .

Copy link
Contributor

Choose a reason for hiding this comment

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

minor and not related to this PR - also I found it a bit confusing at first to see the 0 value as parameter testusersignup.VerificationRequired(0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's weird - I've created a PR to align the names a bit codeready-toolchain/toolchain-common#445

It looks like the latter sets the UserSignupStateVerificationRequired in the UserSignup.Spec.States and it doesn't update the conditions

you are right, the testusersignup.VerificationRequired updates also the conditions which wasn't done before, technically speaking, the UserSignup should look like that, so it's closer to the real scenario now.

Copy link

openshift-ci bot commented Jan 9, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, MatousJobanek, mfrancisc

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:
  • OWNERS [MatousJobanek,alexeykazakov,mfrancisc]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants