Skip to content

move EncodeUserIdentifier & drop userID from tests #500

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

Merged

Conversation

MatousJobanek
Copy link
Contributor

depends on: codeready-toolchain/toolchain-common#452

  • moves the EncodeUserIdentifier to toolchain-common (so it can be used in the helper function)
  • drops usage of userID from unit tests
  • Improves the unit-tests so they use an encoded value as the name of the UserSignup CRs
  • applies new helper functions introduced in the toolchain-common PR

KUBESAW-254

This is hopefully the last PR before final dropping of the usage of userIDs as the UserSignup names

Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.12%. Comparing base (88ab833) to head (7e48ae0).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #500      +/-   ##
==========================================
- Coverage   85.38%   85.12%   -0.26%     
==========================================
  Files          32       32              
  Lines        3174     3146      -28     
==========================================
- Hits         2710     2678      -32     
- Misses        376      380       +4     
  Partials       88       88              
Flag Coverage Δ
unittests 85.12% <100.00%> (-0.26%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it 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 a couple of minor questions.

)

svc.MockSignup = func(ctx *gin.Context) (*crtapi.UserSignup, error) {
assert.Equal(s.T(), expectedUserID, ctx.GetString(context.SubKey))
assert.Equal(s.T(), "bill", ctx.GetString(context.UsernameKey))
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of these asserts here? As far as I understand the flow, they're only checking that we set the appropriate values in the context a couple of lines above. Is that really needed?

What we're really should be testing there, IMHO, is that the signup service has been used. So what about instead of all those asserts on the context, having a "signupCalled" boolean that would be set to true in the svc.MockSignup and checked for being true after the call to handler?

Or maybe that's assumed by the correct status code of the response and we don't need any of that either?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH, (to keep my sanity intact) I didn't try to question the tests themself, I only modified the related changes (or dropped tests that didn't make sense anymore after my changes).
There are many things weird, wrong, missing, or redundant in the unit tests, I hope that we will get to fixing them later as soon as the whole code is simplified/refactored.
Anyway, I tried to improve the test here: ec1eefa

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and as for you question:

What we're really should be testing there

As I understand it, it verifies that the signup handler is called properly an returns corresponding response values

Copy link

@MatousJobanek
Copy link
Contributor Author

@metlos I've address/answered all your review comments, let me know if it looks good to you now.

Copy link

openshift-ci bot commented Jan 29, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, fbm3307, MatousJobanek, metlos, 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,fbm3307,metlos,mfrancisc]

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

@MatousJobanek MatousJobanek merged commit c7f9087 into codeready-toolchain:master Jan 29, 2025
12 of 13 checks passed
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.

5 participants