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 mockery generate mock in clusterresource pkg #6243

Conversation

popojk
Copy link
Contributor

@popojk popojk commented Feb 14, 2025

Tracking issue

Related to #149

Why are the changes needed?

FlyteAdmin currently relies on manually crafted mocks, which are cumbersome to maintain and extend for new interfaces. Switching to Mockery v2 generated mocks is a more efficient approach, eliminating repetitive boilerplate code and streamlining the development process.

What changes were proposed in this pull request?

This PR updates the mocks in flyteadmin/pkg/clusterresource to use Mockery v2 generated mocks and includes modifications to the related test cases to ensure compatibility.

Check all the applicable boxes

  • All new and existing tests passed.
  • All commits are signed-off.

Summary by Bito

This PR updates the clusterresource package by migrating from manual mocks to mockery v2 generated mocks. The implementation includes regenerating mocks with mockery v2.40.3 and updating test cases to use the new EXPECT() syntax, enhancing the maintainability of the testing infrastructure.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 2

@flyte-bot
Copy link
Collaborator

flyte-bot commented Feb 14, 2025

Code Review Agent Run #5e81f2

Actionable Suggestions - 4
  • flyteadmin/pkg/clusterresource/mocks/flyte_admin_data_provider.go - 2
    • Consider preserving mock expectation method · Line 31-33
    • Consider error return over panic · Line 90-93
  • flyteadmin/pkg/clusterresource/controller_test.go - 2
    • Consider using specific mock expectations · Line 124-124
    • Consider using OnGetClusterResourceAttributes for mocking · Line 335-335
Additional Suggestions - 2
  • flyteadmin/pkg/clusterresource/mocks/flyte_admin_data_provider.go - 2
    • Consider removing duplicate variable declaration · Line 90-90
    • Consider consistent mock return implementation pattern · Line 76-78
Review Details
  • Files reviewed - 3 · Commit Range: 4c5daef..4c5daef
    • flyteadmin/pkg/clusterresource/controller_test.go
    • flyteadmin/pkg/clusterresource/interfaces/admin.go
    • flyteadmin/pkg/clusterresource/mocks/flyte_admin_data_provider.go
  • Files skipped - 0
  • Tools
    • Golangci-lint (Linter) - ✖︎ Failed
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Copy link

codecov bot commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 17.39130% with 38 lines in your changes missing coverage. Please review.

Project coverage is 36.87%. Comparing base (b04df59) to head (4c5daef).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...clusterresource/mocks/flyte_admin_data_provider.go 17.39% 36 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #6243       +/-   ##
===========================================
- Coverage   50.51%   36.87%   -13.65%     
===========================================
  Files        1162     1318      +156     
  Lines       91811   134731    +42920     
===========================================
+ Hits        46375    49676     +3301     
- Misses      41340    80726    +39386     
- Partials     4096     4329      +233     
Flag Coverage Δ
unittests-datacatalog 51.58% <ø> (ø)
unittests-flyteadmin 51.91% <17.39%> (-0.03%) ⬇️
unittests-flytecopilot 30.99% <ø> (?)
unittests-flytectl 62.29% <ø> (ø)
unittests-flyteidl 7.22% <ø> (?)
unittests-flyteplugins 54.03% <ø> (ø)
unittests-flytepropeller 42.78% <ø> (ø)
unittests-flytestdlib 55.35% <ø> (+0.01%) ⬆️

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.

@flyte-bot
Copy link
Collaborator

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Testing - Update Mock Generation Framework

controller_test.go - Updated test cases to use new mockery v2 syntax with EXPECT()

admin.go - Updated mock generation directive to use mockery-v2

flyte_admin_data_provider.go - Regenerated mock implementation using mockery v2.40.3

Comment on lines +31 to +33
panic("no return value specified for GetClusterResourceAttributes")
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider preserving mock expectation method

Consider keeping the OnGetClusterResourceAttributesMatch method alongside the new EXPECT() method as they serve different purposes in mock expectations. The removal might break existing tests that rely on this method.

Code suggestion
Check the AI-generated fix before applying
 @@ -31,3 +22,5 @@
 +func (_m *FlyteAdminDataProvider) EXPECT() *FlyteAdminDataProvider_Expecter {
 +	return &FlyteAdminDataProvider_Expecter{mock: &_m.Mock}
 +}
 +
 +func (_m *FlyteAdminDataProvider) OnGetClusterResourceAttributesMatch(matchers ...interface{}) *FlyteAdminDataProvider_GetClusterResourceAttributes {
 +	c_call := _m.On("GetClusterResourceAttributes", matchers...)
 +	return &FlyteAdminDataProvider_GetClusterResourceAttributes{Call: c_call}
 +}

Code Review Run #5e81f2


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +90 to +93
if len(ret) == 0 {
panic("no return value specified for GetProjects")
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider error return over panic

Consider handling the empty return value case more gracefully instead of using panic(). A panic in mock code could disrupt test execution unnecessarily. Consider returning a meaningful error instead.

Code suggestion
Check the AI-generated fix before applying
Suggested change
if len(ret) == 0 {
panic("no return value specified for GetProjects")
}
if len(ret) == 0 {
return nil, fmt.Errorf("no return value specified for GetProjects")
}

Code Review Run #5e81f2


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@eapolinario eapolinario merged commit c1e5830 into flyteorg:master Feb 14, 2025
51 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants