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

Switch workflowengine compiler mock to mockery generated #6261

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

luckyarthur
Copy link
Contributor

@luckyarthur luckyarthur commented Feb 20, 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, also add the go generate comment which automates update of mocks

What changes were proposed in this pull request?

this PR includes changes of mock for flyteadmin/pkg/workflowengine/interfaces/compiler.go, and update unit test usage of the new mockery generated mock

Check all the applicable boxes

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

Summary by Bito

Modernization of testing infrastructure by replacing manual mocks with Mockery v2 generated mocks for the workflow engine compiler interface. The update includes adding go:generate directives and implementing new Mockery v2-based mocks. The changes streamline the codebase by removing old manual mock implementations while enhancing maintainability and consistency of test files.

Unit tests added: True

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

…r_test

the AddCompileTaskCallback is only used in old hand roll mock, nowhere else is using it, fine to remove it

Signed-off-by: Arthur <[email protected]>
@flyte-bot
Copy link
Collaborator

flyte-bot commented Feb 20, 2025

Code Review Agent Run #285e27

Actionable Suggestions - 2
  • flyteadmin/pkg/manager/impl/workflow_manager_test.go - 1
    • Consider simplifying mock setup implementation · Line 235-237
  • flyteadmin/pkg/manager/impl/task_manager_test.go - 1
Review Details
  • Files reviewed - 5 · Commit Range: f12185a..6fbb5a6
    • flyteadmin/pkg/manager/impl/task_manager_test.go
    • flyteadmin/pkg/manager/impl/workflow_manager_test.go
    • flyteadmin/pkg/workflowengine/interfaces/compiler.go
    • flyteadmin/pkg/workflowengine/mocks/Compiler.go
    • flyteadmin/pkg/workflowengine/mocks/mock_compiler.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 20, 2025

Codecov Report

Attention: Patch coverage is 45.07042% with 39 lines in your changes missing coverage. Please review.

Project coverage is 36.85%. Comparing base (e9e227b) to head (23fe577).

Files with missing lines Patch % Lines
flyteadmin/pkg/workflowengine/mocks/Compiler.go 45.07% 27 Missing and 12 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6261      +/-   ##
==========================================
- Coverage   36.86%   36.85%   -0.01%     
==========================================
  Files        1318     1318              
  Lines      134773   134821      +48     
==========================================
+ Hits        49683    49695      +12     
- Misses      80758    80782      +24     
- Partials     4332     4344      +12     
Flag Coverage Δ
unittests-datacatalog 51.58% <ø> (ø)
unittests-flyteadmin 51.82% <45.07%> (-0.06%) ⬇️
unittests-flytecopilot 30.99% <ø> (ø)
unittests-flytectl 62.29% <ø> (ø)
unittests-flyteidl 7.22% <ø> (ø)
unittests-flyteplugins 54.00% <ø> (ø)
unittests-flytepropeller 42.78% <ø> (ø)
unittests-flytestdlib 55.35% <ø> (ø)

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

flyte-bot commented Feb 20, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Testing - Mock Framework Migration to Mockery v2

task_manager_test.go - Updated test code to use new Mockery v2 generated compiler mock

workflow_manager_test.go - Migrated workflow manager tests to use new Mockery v2 compiler mock

builder.go - Added mockery-v2 generate directive for FlyteWorkflowBuilder interface

compiler.go - Added mockery-v2 generate directive for Compiler interface

executor.go - Added mockery-v2 generate directive for WorkflowExecutor interface

Compiler.go - Added new Mockery v2 generated mock implementation

mock_compiler.go - Removed old manual mock implementation

Comment on lines 235 to 237
mockCompiler.On("GetRequirements", mock.AnythingOfType("*core.WorkflowTemplate"), mock.AnythingOfType("[]*core.WorkflowTemplate")).Return(func(fg *core.WorkflowTemplate, subWfs []*core.WorkflowTemplate) (compiler.WorkflowExecutionRequirements, error) {
return compiler.WorkflowExecutionRequirements{}, nil
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider simplifying mock setup implementation

Consider using mockCompiler.On() with explicit return values instead of using callback functions for better readability and maintainability. The current implementation using callback functions makes the test setup more complex than necessary.

Code suggestion
Check the AI-generated fix before applying
Suggested change
mockCompiler.On("GetRequirements", mock.AnythingOfType("*core.WorkflowTemplate"), mock.AnythingOfType("[]*core.WorkflowTemplate")).Return(func(fg *core.WorkflowTemplate, subWfs []*core.WorkflowTemplate) (compiler.WorkflowExecutionRequirements, error) {
return compiler.WorkflowExecutionRequirements{}, nil
})
mockCompiler.On("GetRequirements", mock.AnythingOfType("*core.WorkflowTemplate"), mock.AnythingOfType("[]*core.WorkflowTemplate")).Return(compiler.WorkflowExecutionRequirements{}, nil)

Code Review Run #285e27


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Comment on lines 174 to 178
mockCompiler := &workflowMocks.Compiler{}
expectedErr := errors.New("expected error")
mockCompiler.(*workflowMocks.MockCompiler).AddCompileTaskCallback(
func(task *core.TaskTemplate) (*core.CompiledTask, error) {
return nil, expectedErr
})
mockCompiler.On("CompileTask", mock.AnythingOfType("*core.TaskTemplate")).Return(func(taskTemplate *core.TaskTemplate) (*core.CompiledTask, error) {
return nil, expectedErr
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider simpler mock setup approach

Consider using testify/mock functionality more idiomatically. Instead of using a callback function with Return, you could use mock.MatchedBy with direct return values for better readability and maintainability.

Code suggestion
Check the AI-generated fix before applying
 -	mockCompiler := &workflowMocks.Compiler{}
 -	mockCompiler.On("CompileTask", mock.AnythingOfType("*core.TaskTemplate")).Return(func(taskTemplate *core.TaskTemplate) (*core.CompiledTask, error) {
 -		return nil, expectedErr
 -	})
 +	mockCompiler := &workflowMocks.Compiler{}
 +	mockCompiler.On("CompileTask", mock.MatchedBy(func(*core.TaskTemplate) bool { return true })).Return(nil, expectedErr)

Code Review Run #285e27


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@luckyarthur luckyarthur force-pushed the switch-workflowengine-compiler-mock-to-mockery-generated branch from 41ca1a2 to 5db164d Compare February 20, 2025 09:40
@flyte-bot
Copy link
Collaborator

flyte-bot commented Feb 20, 2025

Code Review Agent Run #74cc11

Actionable Suggestions - 1
  • flyteadmin/pkg/manager/impl/task_manager_test.go - 1
    • Consider more specific mock matcher condition · Line 176-176
Review Details
  • Files reviewed - 5 · Commit Range: 6fbb5a6..23fe577
    • flyteadmin/pkg/manager/impl/task_manager_test.go
    • flyteadmin/pkg/manager/impl/workflow_manager_test.go
    • flyteadmin/pkg/workflowengine/interfaces/builder.go
    • flyteadmin/pkg/workflowengine/interfaces/compiler.go
    • flyteadmin/pkg/workflowengine/interfaces/executor.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

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.

2 participants