From 1a35e7936188fc62419fe124b4ab5bde369589a1 Mon Sep 17 00:00:00 2001 From: Alex Wu Date: Tue, 28 Jan 2025 00:55:03 +0800 Subject: [PATCH 1/4] build mock files with mockery v2 Signed-off-by: Alex Wu --- flyteadmin/dataproxy/service_test.go | 41 +- .../schedule/aws/workflow_executor_test.go | 25 +- .../impl/db_admin_data_provider_test.go | 17 +- .../manager/impl/execution_manager_test.go | 165 ++++- .../executions/quality_of_service_test.go | 19 +- .../pkg/manager/impl/metrics_manager_test.go | 19 +- .../pkg/manager/impl/util/resources_test.go | 13 +- .../pkg/manager/impl/util/shared_test.go | 25 +- .../impl/util/single_task_execution_test.go | 17 +- flyteadmin/pkg/manager/mocks/execution.go | 146 ----- .../pkg/manager/mocks/execution_interface.go | 575 ++++++++++++++++++ flyteadmin/pkg/manager/mocks/launch_plan.go | 114 ---- .../manager/mocks/launch_plan_interface.go | 451 ++++++++++++++ flyteadmin/pkg/manager/mocks/named_entity.go | 38 -- .../manager/mocks/named_entity_interface.go | 215 +++++++ .../pkg/manager/mocks/node_execution.go | 90 --- .../manager/mocks/node_execution_interface.go | 392 ++++++++++++ flyteadmin/pkg/manager/mocks/project.go | 69 --- .../pkg/manager/mocks/project_interface.go | 323 ++++++++++ flyteadmin/pkg/manager/mocks/resource.go | 133 ---- .../pkg/manager/mocks/resource_interface.go | 452 ++++++++++---- flyteadmin/pkg/manager/mocks/task.go | 50 -- .../pkg/manager/mocks/task_execution.go | 75 --- .../manager/mocks/task_execution_interface.go | 274 +++++++++ .../pkg/manager/mocks/task_interface.go | 274 +++++++++ flyteadmin/pkg/manager/mocks/workflow.go | 50 -- .../pkg/manager/mocks/workflow_interface.go | 274 +++++++++ .../rpc/adminservice/tests/execution_test.go | 69 +-- .../adminservice/tests/launch_plan_test.go | 25 +- .../adminservice/tests/node_execution_test.go | 37 +- .../adminservice/tests/project_domain_test.go | 44 +- .../rpc/adminservice/tests/project_test.go | 13 +- .../adminservice/tests/task_execution_test.go | 43 +- .../pkg/rpc/adminservice/tests/task_test.go | 13 +- flyteadmin/pkg/rpc/adminservice/tests/util.go | 16 +- .../rpc/adminservice/tests/workflow_test.go | 9 +- 36 files changed, 3479 insertions(+), 1126 deletions(-) delete mode 100644 flyteadmin/pkg/manager/mocks/execution.go create mode 100644 flyteadmin/pkg/manager/mocks/execution_interface.go delete mode 100644 flyteadmin/pkg/manager/mocks/launch_plan.go create mode 100644 flyteadmin/pkg/manager/mocks/launch_plan_interface.go delete mode 100644 flyteadmin/pkg/manager/mocks/named_entity.go create mode 100644 flyteadmin/pkg/manager/mocks/named_entity_interface.go delete mode 100644 flyteadmin/pkg/manager/mocks/node_execution.go create mode 100644 flyteadmin/pkg/manager/mocks/node_execution_interface.go delete mode 100644 flyteadmin/pkg/manager/mocks/project.go create mode 100644 flyteadmin/pkg/manager/mocks/project_interface.go delete mode 100644 flyteadmin/pkg/manager/mocks/resource.go delete mode 100644 flyteadmin/pkg/manager/mocks/task.go delete mode 100644 flyteadmin/pkg/manager/mocks/task_execution.go create mode 100644 flyteadmin/pkg/manager/mocks/task_execution_interface.go create mode 100644 flyteadmin/pkg/manager/mocks/task_interface.go delete mode 100644 flyteadmin/pkg/manager/mocks/workflow.go create mode 100644 flyteadmin/pkg/manager/mocks/workflow_interface.go diff --git a/flyteadmin/dataproxy/service_test.go b/flyteadmin/dataproxy/service_test.go index 4c3f3ea720..c66b9df9b7 100644 --- a/flyteadmin/dataproxy/service_test.go +++ b/flyteadmin/dataproxy/service_test.go @@ -11,6 +11,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/durationpb" @@ -33,8 +34,8 @@ func TestNewService(t *testing.T) { dataStore, err := storage.NewDataStore(&storage.Config{Type: storage.TypeMemory}, promutils.NewTestScope()) assert.NoError(t, err) - nodeExecutionManager := &mocks.MockNodeExecutionManager{} - taskExecutionManager := &mocks.MockTaskExecutionManager{} + nodeExecutionManager := &mocks.NodeExecutionInterface{} + taskExecutionManager := &mocks.TaskExecutionInterface{} s, err := NewService(config.DataProxyConfig{ Upload: config.DataProxyUploadConfig{}, }, nodeExecutionManager, dataStore, taskExecutionManager) @@ -59,8 +60,8 @@ func Test_createStorageLocation(t *testing.T) { func TestCreateUploadLocation(t *testing.T) { dataStore, err := storage.NewDataStore(&storage.Config{Type: storage.TypeMemory}, promutils.NewTestScope()) assert.NoError(t, err) - nodeExecutionManager := &mocks.MockNodeExecutionManager{} - taskExecutionManager := &mocks.MockTaskExecutionManager{} + nodeExecutionManager := &mocks.NodeExecutionInterface{} + taskExecutionManager := &mocks.TaskExecutionInterface{} s, err := NewService(config.DataProxyConfig{}, nodeExecutionManager, dataStore, taskExecutionManager) assert.NoError(t, err) t.Run("No project/domain", func(t *testing.T) { @@ -113,8 +114,8 @@ func TestCreateUploadLocationMore(t *testing.T) { } assert.NoError(t, err) - nodeExecutionManager := &mocks.MockNodeExecutionManager{} - taskExecutionManager := &mocks.MockTaskExecutionManager{} + nodeExecutionManager := &mocks.NodeExecutionInterface{} + taskExecutionManager := &mocks.TaskExecutionInterface{} s, err := NewService(config.DataProxyConfig{}, nodeExecutionManager, &ds, taskExecutionManager) assert.NoError(t, err) @@ -171,15 +172,15 @@ func (t testMetadata) Exists() bool { func TestCreateDownloadLink(t *testing.T) { dataStore := commonMocks.GetMockStorageClient() - nodeExecutionManager := &mocks.MockNodeExecutionManager{} - nodeExecutionManager.SetGetNodeExecutionFunc(func(ctx context.Context, request *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error) { + nodeExecutionManager := &mocks.NodeExecutionInterface{} + nodeExecutionManager.EXPECT().GetNodeExecution(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error) { return &admin.NodeExecution{ Closure: &admin.NodeExecutionClosure{ DeckUri: "s3://something/something", }, }, nil }) - taskExecutionManager := &mocks.MockTaskExecutionManager{} + taskExecutionManager := &mocks.TaskExecutionInterface{} s, err := NewService(config.DataProxyConfig{Download: config.DataProxyDownloadConfig{MaxExpiresIn: stdlibConfig.Duration{Duration: time.Hour}}}, nodeExecutionManager, dataStore, taskExecutionManager) assert.NoError(t, err) @@ -262,8 +263,8 @@ func TestCreateDownloadLink(t *testing.T) { func TestCreateDownloadLocation(t *testing.T) { dataStore := commonMocks.GetMockStorageClient() - nodeExecutionManager := &mocks.MockNodeExecutionManager{} - taskExecutionManager := &mocks.MockTaskExecutionManager{} + nodeExecutionManager := &mocks.NodeExecutionInterface{} + taskExecutionManager := &mocks.TaskExecutionInterface{} s, err := NewService(config.DataProxyConfig{Download: config.DataProxyDownloadConfig{MaxExpiresIn: stdlibConfig.Duration{Duration: time.Hour}}}, nodeExecutionManager, dataStore, taskExecutionManager) assert.NoError(t, err) @@ -300,8 +301,8 @@ func TestCreateDownloadLocation(t *testing.T) { func TestService_GetData(t *testing.T) { dataStore := commonMocks.GetMockStorageClient() - nodeExecutionManager := &mocks.MockNodeExecutionManager{} - taskExecutionManager := &mocks.MockTaskExecutionManager{} + nodeExecutionManager := &mocks.NodeExecutionInterface{} + taskExecutionManager := &mocks.TaskExecutionInterface{} s, err := NewService(config.DataProxyConfig{}, nodeExecutionManager, dataStore, taskExecutionManager) assert.NoError(t, err) @@ -340,7 +341,7 @@ func TestService_GetData(t *testing.T) { }, } - nodeExecutionManager.SetGetNodeExecutionDataFunc( + nodeExecutionManager.EXPECT().GetNodeExecutionData(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.NodeExecutionGetDataRequest) (*admin.NodeExecutionGetDataResponse, error) { return &admin.NodeExecutionGetDataResponse{ FullInputs: inputsLM, @@ -348,7 +349,7 @@ func TestService_GetData(t *testing.T) { }, nil }, ) - taskExecutionManager.SetListTaskExecutionsCallback(func(ctx context.Context, request *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error) { + taskExecutionManager.EXPECT().ListTaskExecutions(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error) { return &admin.TaskExecutionList{ TaskExecutions: []*admin.TaskExecution{ { @@ -374,7 +375,7 @@ func TestService_GetData(t *testing.T) { }, }, nil }) - taskExecutionManager.SetGetTaskExecutionDataCallback(func(ctx context.Context, request *admin.TaskExecutionGetDataRequest) (*admin.TaskExecutionGetDataResponse, error) { + taskExecutionManager.EXPECT().GetTaskExecutionData(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.TaskExecutionGetDataRequest) (*admin.TaskExecutionGetDataResponse, error) { return &admin.TaskExecutionGetDataResponse{ FullInputs: inputsLM, FullOutputs: outputsLM, @@ -441,13 +442,13 @@ func TestService_GetData(t *testing.T) { func TestService_Error(t *testing.T) { dataStore := commonMocks.GetMockStorageClient() - nodeExecutionManager := &mocks.MockNodeExecutionManager{} - taskExecutionManager := &mocks.MockTaskExecutionManager{} + nodeExecutionManager := &mocks.NodeExecutionInterface{} + taskExecutionManager := &mocks.TaskExecutionInterface{} s, err := NewService(config.DataProxyConfig{}, nodeExecutionManager, dataStore, taskExecutionManager) assert.NoError(t, err) t.Run("get a working set of urls without retry attempt", func(t *testing.T) { - taskExecutionManager.SetListTaskExecutionsCallback(func(ctx context.Context, request *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error) { + taskExecutionManager.EXPECT().ListTaskExecutions(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error) { return nil, errors.NewFlyteAdminErrorf(1, "not found") }) nodeExecID := &core.NodeExecutionIdentifier{ @@ -463,7 +464,7 @@ func TestService_Error(t *testing.T) { }) t.Run("get a working set of urls without retry attempt", func(t *testing.T) { - taskExecutionManager.SetListTaskExecutionsCallback(func(ctx context.Context, request *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error) { + taskExecutionManager.EXPECT().ListTaskExecutions(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error) { return &admin.TaskExecutionList{ TaskExecutions: nil, Token: "", diff --git a/flyteadmin/pkg/async/schedule/aws/workflow_executor_test.go b/flyteadmin/pkg/async/schedule/aws/workflow_executor_test.go index 38f8afddbd..aa615ea7ff 100644 --- a/flyteadmin/pkg/async/schedule/aws/workflow_executor_test.go +++ b/flyteadmin/pkg/async/schedule/aws/workflow_executor_test.go @@ -11,6 +11,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "google.golang.org/grpc/codes" flyteAdminErrors "github.com/flyteorg/flyte/flyteadmin/pkg/errors" @@ -138,8 +139,8 @@ func TestGetActiveLaunchPlanVersion(t *testing.T) { Version: "foo", } - launchPlanManager := mocks.NewMockLaunchPlanManager() - launchPlanManager.(*mocks.MockLaunchPlanManager).SetListLaunchPlansCallback( + launchPlanManager := mocks.LaunchPlanInterface{} + launchPlanManager.EXPECT().ListLaunchPlans(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ResourceListRequest) ( *admin.LaunchPlanList, error) { assert.True(t, proto.Equal(launchPlanNamedIdentifier, request.GetId())) @@ -153,7 +154,7 @@ func TestGetActiveLaunchPlanVersion(t *testing.T) { }, }, nil }) - testExecutor := newWorkflowExecutorForTest(nil, nil, launchPlanManager) + testExecutor := newWorkflowExecutorForTest(nil, nil, &launchPlanManager) launchPlan, err := testExecutor.getActiveLaunchPlanVersion(launchPlanNamedIdentifier) assert.Nil(t, err) assert.True(t, proto.Equal(&launchPlanIdentifier, launchPlan.GetId())) @@ -167,13 +168,13 @@ func TestGetActiveLaunchPlanVersion_ManagerError(t *testing.T) { } expectedErr := errors.New("expected error") - launchPlanManager := mocks.NewMockLaunchPlanManager() - launchPlanManager.(*mocks.MockLaunchPlanManager).SetListLaunchPlansCallback( + launchPlanManager := mocks.LaunchPlanInterface{} + launchPlanManager.EXPECT().ListLaunchPlans(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ResourceListRequest) ( *admin.LaunchPlanList, error) { return nil, expectedErr }) - testExecutor := newWorkflowExecutorForTest(nil, nil, launchPlanManager) + testExecutor := newWorkflowExecutorForTest(nil, nil, &launchPlanManager) _, err := testExecutor.getActiveLaunchPlanVersion(launchPlanIdentifier) assert.EqualError(t, err, expectedErr.Error()) } @@ -229,9 +230,9 @@ func TestRun(t *testing.T) { testSubscriber := pubsubtest.TestSubscriber{ JSONMessages: messages, } - testExecutionManager := mocks.MockExecutionManager{} + testExecutionManager := mocks.ExecutionInterface{} var messagesSeen int - testExecutionManager.SetCreateCallback(func( + testExecutionManager.EXPECT().CreateExecution(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func( ctx context.Context, request *admin.ExecutionCreateRequest, requestedAt time.Time) ( *admin.ExecutionCreateResponse, error) { assert.Equal(t, "project", request.GetProject()) @@ -239,13 +240,13 @@ func TestRun(t *testing.T) { assert.Equal(t, "ar8fphnlc5wh9dksjncj", request.GetName()) if messagesSeen == 0 { assert.Contains(t, request.GetInputs().GetLiterals(), testKickoffTime) - assert.Equal(t, testKickoffTimeProtoLiteral, request.GetInputs().GetLiterals()[testKickoffTime]) + assert.True(t, proto.Equal(testKickoffTimeProtoLiteral, request.GetInputs().GetLiterals()[testKickoffTime])) } messagesSeen++ return &admin.ExecutionCreateResponse{}, nil }) - launchPlanManager := mocks.NewMockLaunchPlanManager() - launchPlanManager.(*mocks.MockLaunchPlanManager).SetListLaunchPlansCallback( + launchPlanManager := mocks.LaunchPlanInterface{} + launchPlanManager.EXPECT().ListLaunchPlans(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ResourceListRequest) ( *admin.LaunchPlanList, error) { assert.Equal(t, "project", request.GetId().GetProject()) @@ -280,7 +281,7 @@ func TestRun(t *testing.T) { }, }, nil }) - testExecutor := newWorkflowExecutorForTest(&testSubscriber, &testExecutionManager, launchPlanManager) + testExecutor := newWorkflowExecutorForTest(&testSubscriber, &testExecutionManager, &launchPlanManager) err := testExecutor.run() assert.Len(t, messages, messagesSeen) assert.Nil(t, err) diff --git a/flyteadmin/pkg/clusterresource/impl/db_admin_data_provider_test.go b/flyteadmin/pkg/clusterresource/impl/db_admin_data_provider_test.go index 7fa0039799..bec6fa8ed2 100644 --- a/flyteadmin/pkg/clusterresource/impl/db_admin_data_provider_test.go +++ b/flyteadmin/pkg/clusterresource/impl/db_admin_data_provider_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -28,9 +29,9 @@ func TestGetClusterResourceAttributes(t *testing.T) { "K1": "V1", "K2": "V2", } - resourceManager := mocks.MockResourceManager{} t.Run("happy case", func(t *testing.T) { - resourceManager.GetResourceFunc = func(ctx context.Context, request interfaces.ResourceRequest) (*interfaces.ResourceResponse, error) { + resourceManager := mocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request interfaces.ResourceRequest) (*interfaces.ResourceResponse, error) { return &interfaces.ResourceResponse{ Project: request.Project, Domain: request.Domain, @@ -43,7 +44,7 @@ func TestGetClusterResourceAttributes(t *testing.T) { }, }, }, nil - } + }) provider := dbAdminProvider{ resourceManager: &resourceManager, } @@ -52,9 +53,10 @@ func TestGetClusterResourceAttributes(t *testing.T) { assert.EqualValues(t, attrs.GetAttributes(), attributes) }) t.Run("error", func(t *testing.T) { - resourceManager.GetResourceFunc = func(ctx context.Context, request interfaces.ResourceRequest) (*interfaces.ResourceResponse, error) { + resourceManager := mocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request interfaces.ResourceRequest) (*interfaces.ResourceResponse, error) { return nil, errFoo - } + }) provider := dbAdminProvider{ resourceManager: &resourceManager, } @@ -62,7 +64,8 @@ func TestGetClusterResourceAttributes(t *testing.T) { assert.EqualError(t, err, errFoo.Error()) }) t.Run("weird db response", func(t *testing.T) { - resourceManager.GetResourceFunc = func(ctx context.Context, request interfaces.ResourceRequest) (*interfaces.ResourceResponse, error) { + resourceManager := mocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request interfaces.ResourceRequest) (*interfaces.ResourceResponse, error) { return &interfaces.ResourceResponse{ Project: request.Project, Domain: request.Domain, @@ -75,7 +78,7 @@ func TestGetClusterResourceAttributes(t *testing.T) { }, }, }, nil - } + }) provider := dbAdminProvider{ resourceManager: &resourceManager, } diff --git a/flyteadmin/pkg/manager/impl/execution_manager_test.go b/flyteadmin/pkg/manager/impl/execution_manager_test.go index 79068d25ff..aba22839db 100644 --- a/flyteadmin/pkg/manager/impl/execution_manager_test.go +++ b/flyteadmin/pkg/manager/impl/execution_manager_test.go @@ -34,6 +34,7 @@ import ( "github.com/flyteorg/flyte/flyteadmin/pkg/manager/impl/shared" "github.com/flyteorg/flyte/flyteadmin/pkg/manager/impl/testutils" managerInterfaces "github.com/flyteorg/flyte/flyteadmin/pkg/manager/interfaces" + "github.com/flyteorg/flyte/flyteadmin/pkg/manager/mocks" managerMocks "github.com/flyteorg/flyte/flyteadmin/pkg/manager/mocks" "github.com/flyteorg/flyte/flyteadmin/pkg/repositories/interfaces" repositoryMocks "github.com/flyteorg/flyte/flyteadmin/pkg/repositories/mocks" @@ -4574,12 +4575,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { rmInterruptible := false rmOverwriteCache := false - resourceManager := managerMocks.MockResourceManager{} + resourceManager := managerMocks.ResourceInterface{} executionManager := ExecutionManager{ resourceManager: &resourceManager, config: applicationConfig, } - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { // two requests will be made, one with empty domain and one with filled in domain assert.Contains(t, []managerInterfaces.ResourceRequest{{ @@ -4627,7 +4628,7 @@ func TestGetExecutionConfigOverrides(t *testing.T) { return projectResponse, nil } return projectDomainResponse, nil - } + }) t.Run("request with full config", func(t *testing.T) { request := &admin.ExecutionCreateRequest{ @@ -4832,7 +4833,8 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetEnvs()) }) t.Run("matchable resource partial config", func(t *testing.T) { - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.Contains(t, []managerInterfaces.ResourceRequest{{ Project: workflowIdentifier.GetProject(), @@ -4858,7 +4860,7 @@ func TestGetExecutionConfigOverrides(t *testing.T) { }, }, }, nil - } + }) request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -4879,7 +4881,8 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetEnvs()) }) t.Run("matchable resource with no config", func(t *testing.T) { - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.Contains(t, []managerInterfaces.ResourceRequest{{ Project: workflowIdentifier.GetProject(), @@ -4896,7 +4899,7 @@ func TestGetExecutionConfigOverrides(t *testing.T) { }, }, }, nil - } + }) request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -4917,7 +4920,8 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetEnvs()) }) t.Run("fetch security context from deprecated config", func(t *testing.T) { - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.Contains(t, []managerInterfaces.ResourceRequest{{ Project: workflowIdentifier.GetProject(), @@ -4935,7 +4939,7 @@ func TestGetExecutionConfigOverrides(t *testing.T) { }, }, }, nil - } + }) request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -4960,7 +4964,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetEnvs()) }) t.Run("matchable resource workflow resource", func(t *testing.T) { - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager.ExpectedCalls = nil + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.Contains(t, []managerInterfaces.ResourceRequest{{ Project: workflowIdentifier.GetProject(), @@ -4989,7 +4998,7 @@ func TestGetExecutionConfigOverrides(t *testing.T) { }, }, }, nil - } + }) request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5014,7 +5023,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetEnvs()) }) t.Run("matchable resource failure", func(t *testing.T) { - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager.ExpectedCalls = nil + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.Contains(t, []managerInterfaces.ResourceRequest{{ Project: workflowIdentifier.GetProject(), @@ -5025,7 +5039,7 @@ func TestGetExecutionConfigOverrides(t *testing.T) { ResourceType: admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG}, }, request) return nil, fmt.Errorf("failed to fetch the resources") - } + }) request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5046,7 +5060,8 @@ func TestGetExecutionConfigOverrides(t *testing.T) { }) t.Run("application configuration", func(t *testing.T) { - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.Contains(t, []managerInterfaces.ResourceRequest{{ Project: workflowIdentifier.GetProject(), @@ -5063,12 +5078,18 @@ func TestGetExecutionConfigOverrides(t *testing.T) { }, }, }, nil - } + }) executionManager.config.ApplicationConfiguration().GetTopLevelConfig().Interruptible = true executionManager.config.ApplicationConfiguration().GetTopLevelConfig().OverwriteCache = true t.Run("request with interruptible override disabled", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5087,6 +5108,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetAnnotations()) }) t.Run("request with interruptible override enabled", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5105,6 +5132,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetAnnotations()) }) t.Run("request with no interruptible override specified", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5121,6 +5154,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetAnnotations()) }) t.Run("launch plan with interruptible override disabled", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5143,6 +5182,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetAnnotations()) }) t.Run("launch plan with interruptible override enabled", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5169,6 +5214,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Equal(t, "bar", execConfig.GetEnvs().GetValues()[0].GetValue()) }) t.Run("launch plan with no interruptible override specified", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5189,6 +5240,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetAnnotations()) }) t.Run("request and launch plan with different interruptible overrides", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5213,6 +5270,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetAnnotations()) }) t.Run("request with skip cache override enabled", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5231,6 +5294,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetAnnotations()) }) t.Run("request with no skip cache override specified", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5247,6 +5316,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetAnnotations()) }) t.Run("launch plan with skip cache override enabled", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5269,6 +5344,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetAnnotations()) }) t.Run("launch plan with no skip cache override specified", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5289,6 +5370,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { assert.Nil(t, execConfig.GetAnnotations()) }) t.Run("request and launch plan with different skip cache overrides", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), Domain: workflowIdentifier.GetDomain(), @@ -5314,6 +5401,12 @@ func TestGetExecutionConfigOverrides(t *testing.T) { }) t.Run("test pick up security context from admin system config", func(t *testing.T) { + resourceManager.ExpectedCalls = nil + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, + config: applicationConfig, + } executionManager.config.ApplicationConfiguration().GetTopLevelConfig().K8SServiceAccount = "flyte-test" request := &admin.ExecutionCreateRequest{ Project: workflowIdentifier.GetProject(), @@ -5329,8 +5422,8 @@ func TestGetExecutionConfigOverrides(t *testing.T) { } func TestGetExecutionConfig(t *testing.T) { - resourceManager := managerMocks.MockResourceManager{} - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager := managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.Contains(t, []managerInterfaces.ResourceRequest{{ Project: workflowIdentifier.GetProject(), @@ -5350,7 +5443,7 @@ func TestGetExecutionConfig(t *testing.T) { }, }, }, nil - } + }) applicationConfig := runtime.NewConfigurationProvider() executionManager := ExecutionManager{ @@ -5368,11 +5461,11 @@ func TestGetExecutionConfig(t *testing.T) { } func TestGetExecutionConfig_Spec(t *testing.T) { - resourceManager := managerMocks.MockResourceManager{} - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager := managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { return nil, nil - } + }) applicationConfig := runtime.NewConfigurationProvider() executionManager := ExecutionManager{ resourceManager: &resourceManager, @@ -5409,11 +5502,11 @@ func TestGetExecutionConfig_Spec(t *testing.T) { assert.Equal(t, int32(50), execConfig.GetMaxParallelism()) assert.True(t, execConfig.GetOverwriteCache()) - resourceManager = managerMocks.MockResourceManager{} - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager = managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { return nil, nil - } + }) executionManager = ExecutionManager{ resourceManager: &resourceManager, config: applicationConfig, @@ -5435,8 +5528,8 @@ func TestGetExecutionConfig_Spec(t *testing.T) { func TestGetClusterAssignment(t *testing.T) { clusterAssignment := admin.ClusterAssignment{ClusterPoolName: "gpu"} - resourceManager := managerMocks.MockResourceManager{} - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager := managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.EqualValues(t, request, managerInterfaces.ResourceRequest{ Project: workflowIdentifier.GetProject(), @@ -5450,7 +5543,7 @@ func TestGetClusterAssignment(t *testing.T) { }, }, }, nil - } + }) executionManager := ExecutionManager{ resourceManager: &resourceManager, @@ -5475,8 +5568,10 @@ func TestGetClusterAssignment(t *testing.T) { mockConfig := getMockExecutionsConfigProvider() mockConfig.(*runtimeMocks.MockConfigurationProvider).AddClusterPoolAssignmentConfiguration(clusterPoolAsstProvider) + resourceManager := mocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) executionManager := ExecutionManager{ - resourceManager: &managerMocks.MockResourceManager{}, + resourceManager: &resourceManager, config: mockConfig, } @@ -5502,9 +5597,11 @@ func TestGetClusterAssignment(t *testing.T) { }) t.Run("no value in DB nor in config, takes value from request", func(t *testing.T) { mockConfig := getMockExecutionsConfigProvider() + resourceManager := mocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) executionManager := ExecutionManager{ - resourceManager: &managerMocks.MockResourceManager{}, + resourceManager: &resourceManager, config: mockConfig, } @@ -5529,8 +5626,10 @@ func TestGetClusterAssignment(t *testing.T) { mockConfig := getMockExecutionsConfigProvider() mockConfig.(*runtimeMocks.MockConfigurationProvider).AddClusterPoolAssignmentConfiguration(clusterPoolAsstProvider) + resourceManager := mocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) executionManager := ExecutionManager{ - resourceManager: &managerMocks.MockResourceManager{}, + resourceManager: &resourceManager, config: mockConfig, } @@ -5561,7 +5660,8 @@ func TestGetClusterAssignment(t *testing.T) { }) t.Run("db error", func(t *testing.T) { expected := errors.New("fail db") - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager := mocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.EqualValues(t, request, managerInterfaces.ResourceRequest{ Project: workflowIdentifier.GetProject(), @@ -5575,6 +5675,9 @@ func TestGetClusterAssignment(t *testing.T) { }, }, }, expected + }) + executionManager := ExecutionManager{ + resourceManager: &resourceManager, } _, err := executionManager.getClusterAssignment(context.TODO(), &admin.ExecutionCreateRequest{ diff --git a/flyteadmin/pkg/manager/impl/executions/quality_of_service_test.go b/flyteadmin/pkg/manager/impl/executions/quality_of_service_test.go index 0ad76cd3c7..e38beaa133 100644 --- a/flyteadmin/pkg/manager/impl/executions/quality_of_service_test.go +++ b/flyteadmin/pkg/manager/impl/executions/quality_of_service_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/protobuf/ptypes" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/flyteorg/flyte/flyteadmin/pkg/manager/interfaces" managerMocks "github.com/flyteorg/flyte/flyteadmin/pkg/manager/mocks" @@ -60,7 +61,7 @@ func getMockConfig() runtimeInterfaces.Configuration { } func addGetResourceFunc(t *testing.T, resourceManager interfaces.ResourceInterface) { - resourceManager.(*managerMocks.MockResourceManager).GetResourceFunc = func(ctx context.Context, + resourceManager.(*managerMocks.ResourceInterface).EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request interfaces.ResourceRequest) (*interfaces.ResourceResponse, error) { assert.EqualValues(t, request, interfaces.ResourceRequest{ Project: workflowIdentifier.GetProject(), @@ -75,7 +76,7 @@ func addGetResourceFunc(t *testing.T, resourceManager interfaces.ResourceInterfa }, }, }, nil - } + }) } func getWorkflowWithQosSpec(qualityOfService *core.QualityOfService) *admin.Workflow { @@ -96,7 +97,7 @@ func getWorkflowWithQosSpec(qualityOfService *core.QualityOfService) *admin.Work } func TestGetQualityOfService_ExecutionCreateRequest(t *testing.T) { - resourceManager := managerMocks.MockResourceManager{} + resourceManager := managerMocks.ResourceInterface{} addGetResourceFunc(t, &resourceManager) allocator := NewQualityOfServiceAllocator(getMockConfig(), &resourceManager) @@ -119,7 +120,7 @@ func TestGetQualityOfService_ExecutionCreateRequest(t *testing.T) { } func TestGetQualityOfService_LaunchPlan(t *testing.T) { - resourceManager := managerMocks.MockResourceManager{} + resourceManager := managerMocks.ResourceInterface{} addGetResourceFunc(t, &resourceManager) allocator := NewQualityOfServiceAllocator(getMockConfig(), &resourceManager) @@ -140,7 +141,7 @@ func TestGetQualityOfService_LaunchPlan(t *testing.T) { } func TestGetQualityOfService_Workflow(t *testing.T) { - resourceManager := managerMocks.MockResourceManager{} + resourceManager := managerMocks.ResourceInterface{} addGetResourceFunc(t, &resourceManager) allocator := NewQualityOfServiceAllocator(getMockConfig(), &resourceManager) @@ -159,7 +160,7 @@ func TestGetQualityOfService_Workflow(t *testing.T) { } func TestGetQualityOfService_MatchableResource(t *testing.T) { - resourceManager := managerMocks.MockResourceManager{} + resourceManager := managerMocks.ResourceInterface{} addGetResourceFunc(t, &resourceManager) allocator := NewQualityOfServiceAllocator(getMockConfig(), &resourceManager) @@ -178,7 +179,8 @@ func TestGetQualityOfService_MatchableResource(t *testing.T) { } func TestGetQualityOfService_ConfigValues(t *testing.T) { - resourceManager := managerMocks.MockResourceManager{} + resourceManager := managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) allocator := NewQualityOfServiceAllocator(getMockConfig(), &resourceManager) spec, err := allocator.GetQualityOfService(context.Background(), GetQualityOfServiceInput{ @@ -196,7 +198,8 @@ func TestGetQualityOfService_ConfigValues(t *testing.T) { } func TestGetQualityOfService_NoDefault(t *testing.T) { - resourceManager := managerMocks.MockResourceManager{} + resourceManager := managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).Return(nil, nil) allocator := NewQualityOfServiceAllocator(getMockConfig(), &resourceManager) spec, err := allocator.GetQualityOfService(context.Background(), GetQualityOfServiceInput{ diff --git a/flyteadmin/pkg/manager/impl/metrics_manager_test.go b/flyteadmin/pkg/manager/impl/metrics_manager_test.go index b99e0d3243..561340caf0 100644 --- a/flyteadmin/pkg/manager/impl/metrics_manager_test.go +++ b/flyteadmin/pkg/manager/impl/metrics_manager_test.go @@ -8,6 +8,7 @@ import ( "github.com/golang/protobuf/ptypes/duration" "github.com/golang/protobuf/ptypes/timestamp" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/flyteorg/flyte/flyteadmin/pkg/manager/interfaces" "github.com/flyteorg/flyte/flyteadmin/pkg/manager/mocks" @@ -34,8 +35,8 @@ func addTimestamp(ts *timestamp.Timestamp, seconds int64) *timestamp.Timestamp { } func getMockExecutionManager(execution *admin.Execution) interfaces.ExecutionInterface { - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetGetCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().GetExecution(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.WorkflowExecutionGetRequest) (*admin.Execution, error) { return execution, nil }) @@ -46,14 +47,14 @@ func getMockExecutionManager(execution *admin.Execution) interfaces.ExecutionInt func getMockNodeExecutionManager(nodeExecutions []*admin.NodeExecution, dynamicWorkflow *admin.DynamicWorkflowNodeMetadata) interfaces.NodeExecutionInterface { - mockNodeExecutionManager := mocks.MockNodeExecutionManager{} - mockNodeExecutionManager.SetListNodeExecutionsFunc( + mockNodeExecutionManager := mocks.NodeExecutionInterface{} + mockNodeExecutionManager.EXPECT().ListNodeExecutions(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.NodeExecutionListRequest) (*admin.NodeExecutionList, error) { return &admin.NodeExecutionList{ NodeExecutions: nodeExecutions, }, nil }) - mockNodeExecutionManager.SetGetNodeExecutionDataFunc( + mockNodeExecutionManager.EXPECT().GetNodeExecutionData(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.NodeExecutionGetDataRequest) (*admin.NodeExecutionGetDataResponse, error) { return &admin.NodeExecutionGetDataResponse{ DynamicWorkflow: dynamicWorkflow, @@ -64,8 +65,8 @@ func getMockNodeExecutionManager(nodeExecutions []*admin.NodeExecution, } func getMockTaskExecutionManager(taskExecutions []*admin.TaskExecution) interfaces.TaskExecutionInterface { - mockTaskExecutionManager := mocks.MockTaskExecutionManager{} - mockTaskExecutionManager.SetListTaskExecutionsCallback( + mockTaskExecutionManager := mocks.TaskExecutionInterface{} + mockTaskExecutionManager.EXPECT().ListTaskExecutions(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error) { return &admin.TaskExecutionList{ TaskExecutions: taskExecutions, @@ -76,8 +77,8 @@ func getMockTaskExecutionManager(taskExecutions []*admin.TaskExecution) interfac } func getMockWorkflowManager(workflow *admin.Workflow) interfaces.WorkflowInterface { - mockWorkflowManager := mocks.MockWorkflowManager{} - mockWorkflowManager.SetGetCallback( + mockWorkflowManager := mocks.WorkflowInterface{} + mockWorkflowManager.EXPECT().GetWorkflow(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ObjectGetRequest) (*admin.Workflow, error) { return workflow, nil }) diff --git a/flyteadmin/pkg/manager/impl/util/resources_test.go b/flyteadmin/pkg/manager/impl/util/resources_test.go index 932792f307..aa3a70eaf7 100644 --- a/flyteadmin/pkg/manager/impl/util/resources_test.go +++ b/flyteadmin/pkg/manager/impl/util/resources_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "k8s.io/apimachinery/pkg/api/resource" managerInterfaces "github.com/flyteorg/flyte/flyteadmin/pkg/manager/interfaces" @@ -40,8 +41,8 @@ func TestGetTaskResources(t *testing.T) { } t.Run("use runtime application values", func(t *testing.T) { - resourceManager := managerMocks.MockResourceManager{} - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager := managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.EqualValues(t, request, managerInterfaces.ResourceRequest{ Project: workflowIdentifier.GetProject(), @@ -50,7 +51,7 @@ func TestGetTaskResources(t *testing.T) { ResourceType: admin.MatchableResource_TASK_RESOURCE, }) return &managerInterfaces.ResourceResponse{}, nil - } + }) taskResourceAttrs := GetTaskResources(context.TODO(), &workflowIdentifier, &resourceManager, &taskConfig) assert.EqualValues(t, taskResourceAttrs, workflowengineInterfaces.TaskResources{ @@ -69,8 +70,8 @@ func TestGetTaskResources(t *testing.T) { }) }) t.Run("use specific overrides", func(t *testing.T) { - resourceManager := managerMocks.MockResourceManager{} - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager := managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.EqualValues(t, request, managerInterfaces.ResourceRequest{ Project: workflowIdentifier.GetProject(), @@ -98,7 +99,7 @@ func TestGetTaskResources(t *testing.T) { }, }, }, nil - } + }) taskResourceAttrs := GetTaskResources(context.TODO(), &workflowIdentifier, &resourceManager, &taskConfig) assert.EqualValues(t, taskResourceAttrs, workflowengineInterfaces.TaskResources{ Defaults: runtimeInterfaces.TaskResourceSet{ diff --git a/flyteadmin/pkg/manager/impl/util/shared_test.go b/flyteadmin/pkg/manager/impl/util/shared_test.go index 09cb172638..3987d1549a 100644 --- a/flyteadmin/pkg/manager/impl/util/shared_test.go +++ b/flyteadmin/pkg/manager/impl/util/shared_test.go @@ -10,6 +10,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes/wrappers" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "google.golang.org/grpc/codes" "github.com/flyteorg/flyte/flyteadmin/pkg/common" @@ -485,8 +486,8 @@ func TestGetMatchableResource(t *testing.T) { domain := "dummyDomain" workflow := "dummyWorkflow" t.Run("successful fetch", func(t *testing.T) { - resourceManager := &managerMocks.MockResourceManager{} - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager := &managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.EqualValues(t, request, managerInterfaces.ResourceRequest{ Project: project, @@ -502,15 +503,15 @@ func TestGetMatchableResource(t *testing.T) { }, }, }, nil - } + }) mr, err := GetMatchableResource(context.Background(), resourceManager, resourceType, project, domain, "") assert.Equal(t, int32(12), mr.Attributes.GetWorkflowExecutionConfig().GetMaxParallelism()) assert.Nil(t, err) }) t.Run("successful fetch workflow matchable", func(t *testing.T) { - resourceManager := &managerMocks.MockResourceManager{} - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager := &managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.EqualValues(t, request, managerInterfaces.ResourceRequest{ Project: project, @@ -527,7 +528,7 @@ func TestGetMatchableResource(t *testing.T) { }, }, }, nil - } + }) mr, err := GetMatchableResource(context.Background(), resourceManager, resourceType, project, domain, workflow) assert.Equal(t, int32(12), mr.Attributes.GetWorkflowExecutionConfig().GetMaxParallelism()) @@ -535,8 +536,8 @@ func TestGetMatchableResource(t *testing.T) { }) t.Run("not found", func(t *testing.T) { - resourceManager := &managerMocks.MockResourceManager{} - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager := &managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.EqualValues(t, request, managerInterfaces.ResourceRequest{ Project: project, @@ -544,15 +545,15 @@ func TestGetMatchableResource(t *testing.T) { ResourceType: resourceType, }) return nil, flyteAdminErrors.NewFlyteAdminError(codes.NotFound, "resource not found") - } + }) _, err := GetMatchableResource(context.Background(), resourceManager, resourceType, project, domain, "") assert.Nil(t, err) }) t.Run("internal error", func(t *testing.T) { - resourceManager := &managerMocks.MockResourceManager{} - resourceManager.GetResourceFunc = func(ctx context.Context, + resourceManager := &managerMocks.ResourceInterface{} + resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.EqualValues(t, request, managerInterfaces.ResourceRequest{ Project: project, @@ -560,7 +561,7 @@ func TestGetMatchableResource(t *testing.T) { ResourceType: resourceType, }) return nil, flyteAdminErrors.NewFlyteAdminError(codes.Internal, "internal error") - } + }) _, err := GetMatchableResource(context.Background(), resourceManager, resourceType, project, domain, "") assert.NotNil(t, err) diff --git a/flyteadmin/pkg/manager/impl/util/single_task_execution_test.go b/flyteadmin/pkg/manager/impl/util/single_task_execution_test.go index d0aff9edef..987806411b 100644 --- a/flyteadmin/pkg/manager/impl/util/single_task_execution_test.go +++ b/flyteadmin/pkg/manager/impl/util/single_task_execution_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "google.golang.org/grpc/codes" flyteAdminErrors "github.com/flyteorg/flyte/flyteadmin/pkg/errors" @@ -86,8 +87,8 @@ func TestCreateOrGetWorkflowModel(t *testing.T) { } repository.WorkflowRepo().(*repositoryMocks.MockWorkflowRepo).SetGetCallback(workflowGetFunc) - mockNamedEntityManager := managerMocks.NamedEntityManager{} - mockNamedEntityManager.UpdateNamedEntityFunc = func(ctx context.Context, request *admin.NamedEntityUpdateRequest) (*admin.NamedEntityUpdateResponse, error) { + mockNamedEntityManager := managerMocks.NamedEntityInterface{} + mockNamedEntityManager.EXPECT().UpdateNamedEntity(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.NamedEntityUpdateRequest) (*admin.NamedEntityUpdateResponse, error) { assert.Equal(t, request.GetResourceType(), core.ResourceType_WORKFLOW) assert.True(t, proto.Equal(request.GetId(), &admin.NamedEntityIdentifier{ Project: "flytekit", @@ -98,10 +99,10 @@ func TestCreateOrGetWorkflowModel(t *testing.T) { State: admin.NamedEntityState_SYSTEM_GENERATED, })) return &admin.NamedEntityUpdateResponse{}, nil - } + }) - mockWorkflowManager := managerMocks.MockWorkflowManager{} - mockWorkflowManager.SetCreateCallback(func(ctx context.Context, request *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error) { + mockWorkflowManager := managerMocks.WorkflowInterface{} + mockWorkflowManager.EXPECT().CreateWorkflow(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error) { assert.True(t, proto.Equal(request.GetId(), &core.Identifier{ ResourceType: core.ResourceType_WORKFLOW, Project: "flytekit", @@ -218,8 +219,8 @@ func TestCreateOrGetLaunchPlan(t *testing.T) { } workflowID := uint(12) - mockNamedEntityManager := managerMocks.NamedEntityManager{} - mockNamedEntityManager.UpdateNamedEntityFunc = func(ctx context.Context, request *admin.NamedEntityUpdateRequest) (*admin.NamedEntityUpdateResponse, error) { + mockNamedEntityManager := managerMocks.NamedEntityInterface{} + mockNamedEntityManager.EXPECT().UpdateNamedEntity(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.NamedEntityUpdateRequest) (*admin.NamedEntityUpdateResponse, error) { assert.Equal(t, request.GetResourceType(), core.ResourceType_LAUNCH_PLAN) assert.True(t, proto.Equal(request.GetId(), &admin.NamedEntityIdentifier{ Project: "flytekit", @@ -230,7 +231,7 @@ func TestCreateOrGetLaunchPlan(t *testing.T) { State: admin.NamedEntityState_SYSTEM_GENERATED, })) return &admin.NamedEntityUpdateResponse{}, nil - } + }) taskIdentifier := &core.Identifier{ ResourceType: core.ResourceType_TASK, diff --git a/flyteadmin/pkg/manager/mocks/execution.go b/flyteadmin/pkg/manager/mocks/execution.go deleted file mode 100644 index 2695eaffb0..0000000000 --- a/flyteadmin/pkg/manager/mocks/execution.go +++ /dev/null @@ -1,146 +0,0 @@ -package mocks - -import ( - "context" - "time" - - "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" -) - -type CreateExecutionFunc func( - ctx context.Context, request *admin.ExecutionCreateRequest, requestedAt time.Time) ( - *admin.ExecutionCreateResponse, error) -type RelaunchExecutionFunc func( - ctx context.Context, request *admin.ExecutionRelaunchRequest, requestedAt time.Time) ( - *admin.ExecutionCreateResponse, error) -type RecoverExecutionFunc func(ctx context.Context, request *admin.ExecutionRecoverRequest, requestedAt time.Time) ( - *admin.ExecutionCreateResponse, error) -type CreateExecutionEventFunc func(ctx context.Context, request *admin.WorkflowExecutionEventRequest) ( - *admin.WorkflowExecutionEventResponse, error) -type GetExecutionFunc func(ctx context.Context, request *admin.WorkflowExecutionGetRequest) (*admin.Execution, error) -type UpdateExecutionFunc func(ctx context.Context, request *admin.ExecutionUpdateRequest, requestedAt time.Time) ( - *admin.ExecutionUpdateResponse, error) -type GetExecutionDataFunc func(ctx context.Context, request *admin.WorkflowExecutionGetDataRequest) ( - *admin.WorkflowExecutionGetDataResponse, error) -type ListExecutionFunc func(ctx context.Context, request *admin.ResourceListRequest) (*admin.ExecutionList, error) -type TerminateExecutionFunc func( - ctx context.Context, request *admin.ExecutionTerminateRequest) (*admin.ExecutionTerminateResponse, error) - -type MockExecutionManager struct { - createExecutionFunc CreateExecutionFunc - relaunchExecutionFunc RelaunchExecutionFunc - RecoverExecutionFunc RecoverExecutionFunc - createExecutionEventFunc CreateExecutionEventFunc - getExecutionFunc GetExecutionFunc - updateExecutionFunc UpdateExecutionFunc - getExecutionDataFunc GetExecutionDataFunc - listExecutionFunc ListExecutionFunc - terminateExecutionFunc TerminateExecutionFunc -} - -func (m *MockExecutionManager) SetCreateCallback(createFunction CreateExecutionFunc) { - m.createExecutionFunc = createFunction -} - -func (m *MockExecutionManager) CreateExecution( - ctx context.Context, request *admin.ExecutionCreateRequest, requestedAt time.Time) ( - *admin.ExecutionCreateResponse, error) { - if m.createExecutionFunc != nil { - return m.createExecutionFunc(ctx, request, requestedAt) - } - return nil, nil -} - -func (m *MockExecutionManager) SetRelaunchCallback(relaunchFunction RelaunchExecutionFunc) { - m.relaunchExecutionFunc = relaunchFunction -} - -func (m *MockExecutionManager) RelaunchExecution( - ctx context.Context, request *admin.ExecutionRelaunchRequest, requestedAt time.Time) ( - *admin.ExecutionCreateResponse, error) { - if m.relaunchExecutionFunc != nil { - return m.relaunchExecutionFunc(ctx, request, requestedAt) - } - return nil, nil -} - -func (m *MockExecutionManager) SetCreateEventCallback(createEventFunc CreateExecutionEventFunc) { - m.createExecutionEventFunc = createEventFunc -} - -func (m *MockExecutionManager) RecoverExecution(ctx context.Context, request *admin.ExecutionRecoverRequest, requestedAt time.Time) ( - *admin.ExecutionCreateResponse, error) { - if m.RecoverExecutionFunc != nil { - return m.RecoverExecutionFunc(ctx, request, requestedAt) - } - return &admin.ExecutionCreateResponse{}, nil -} - -func (m *MockExecutionManager) CreateWorkflowEvent( - ctx context.Context, - request *admin.WorkflowExecutionEventRequest) (*admin.WorkflowExecutionEventResponse, error) { - if m.createExecutionEventFunc != nil { - return m.createExecutionEventFunc(ctx, request) - } - return nil, nil -} - -func (m *MockExecutionManager) SetUpdateExecutionCallback(updateExecutionFunc UpdateExecutionFunc) { - m.updateExecutionFunc = updateExecutionFunc -} - -func (m *MockExecutionManager) UpdateExecution(ctx context.Context, request *admin.ExecutionUpdateRequest, - requestedAt time.Time) (*admin.ExecutionUpdateResponse, error) { - if m.updateExecutionFunc != nil { - return m.updateExecutionFunc(ctx, request, requestedAt) - } - return nil, nil -} - -func (m *MockExecutionManager) SetGetCallback(getExecutionFunc GetExecutionFunc) { - m.getExecutionFunc = getExecutionFunc -} - -func (m *MockExecutionManager) GetExecution( - ctx context.Context, request *admin.WorkflowExecutionGetRequest) (*admin.Execution, error) { - if m.getExecutionFunc != nil { - return m.getExecutionFunc(ctx, request) - } - return nil, nil -} - -func (m *MockExecutionManager) SetGetDataCallback(getExecutionDataFunc GetExecutionDataFunc) { - m.getExecutionDataFunc = getExecutionDataFunc -} - -func (m *MockExecutionManager) GetExecutionData(ctx context.Context, request *admin.WorkflowExecutionGetDataRequest) ( - *admin.WorkflowExecutionGetDataResponse, error) { - if m.getExecutionDataFunc != nil { - return m.getExecutionDataFunc(ctx, request) - } - return nil, nil -} - -func (m *MockExecutionManager) SetListCallback(listExecutionFunc ListExecutionFunc) { - m.listExecutionFunc = listExecutionFunc -} - -func (m *MockExecutionManager) ListExecutions( - ctx context.Context, request *admin.ResourceListRequest) (*admin.ExecutionList, error) { - if m.listExecutionFunc != nil { - return m.listExecutionFunc(ctx, request) - } - return nil, nil -} - -func (m *MockExecutionManager) SetTerminateExecutionCallback(terminateExecutionFunc TerminateExecutionFunc) { - m.terminateExecutionFunc = terminateExecutionFunc -} - -func (m *MockExecutionManager) TerminateExecution( - ctx context.Context, request *admin.ExecutionTerminateRequest) (*admin.ExecutionTerminateResponse, error) { - if m.terminateExecutionFunc != nil { - return m.terminateExecutionFunc(ctx, request) - } - return nil, nil -} diff --git a/flyteadmin/pkg/manager/mocks/execution_interface.go b/flyteadmin/pkg/manager/mocks/execution_interface.go new file mode 100644 index 0000000000..c9ad4ca18c --- /dev/null +++ b/flyteadmin/pkg/manager/mocks/execution_interface.go @@ -0,0 +1,575 @@ +// Code generated by mockery v2.40.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + admin "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" + + mock "github.com/stretchr/testify/mock" + + time "time" +) + +// ExecutionInterface is an autogenerated mock type for the ExecutionInterface type +type ExecutionInterface struct { + mock.Mock +} + +type ExecutionInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *ExecutionInterface) EXPECT() *ExecutionInterface_Expecter { + return &ExecutionInterface_Expecter{mock: &_m.Mock} +} + +// CreateExecution provides a mock function with given fields: ctx, request, requestedAt +func (_m *ExecutionInterface) CreateExecution(ctx context.Context, request *admin.ExecutionCreateRequest, requestedAt time.Time) (*admin.ExecutionCreateResponse, error) { + ret := _m.Called(ctx, request, requestedAt) + + if len(ret) == 0 { + panic("no return value specified for CreateExecution") + } + + var r0 *admin.ExecutionCreateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ExecutionCreateRequest, time.Time) (*admin.ExecutionCreateResponse, error)); ok { + return rf(ctx, request, requestedAt) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ExecutionCreateRequest, time.Time) *admin.ExecutionCreateResponse); ok { + r0 = rf(ctx, request, requestedAt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.ExecutionCreateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ExecutionCreateRequest, time.Time) error); ok { + r1 = rf(ctx, request, requestedAt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ExecutionInterface_CreateExecution_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateExecution' +type ExecutionInterface_CreateExecution_Call struct { + *mock.Call +} + +// CreateExecution is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ExecutionCreateRequest +// - requestedAt time.Time +func (_e *ExecutionInterface_Expecter) CreateExecution(ctx interface{}, request interface{}, requestedAt interface{}) *ExecutionInterface_CreateExecution_Call { + return &ExecutionInterface_CreateExecution_Call{Call: _e.mock.On("CreateExecution", ctx, request, requestedAt)} +} + +func (_c *ExecutionInterface_CreateExecution_Call) Run(run func(ctx context.Context, request *admin.ExecutionCreateRequest, requestedAt time.Time)) *ExecutionInterface_CreateExecution_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ExecutionCreateRequest), args[2].(time.Time)) + }) + return _c +} + +func (_c *ExecutionInterface_CreateExecution_Call) Return(_a0 *admin.ExecutionCreateResponse, _a1 error) *ExecutionInterface_CreateExecution_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ExecutionInterface_CreateExecution_Call) RunAndReturn(run func(context.Context, *admin.ExecutionCreateRequest, time.Time) (*admin.ExecutionCreateResponse, error)) *ExecutionInterface_CreateExecution_Call { + _c.Call.Return(run) + return _c +} + +// CreateWorkflowEvent provides a mock function with given fields: ctx, request +func (_m *ExecutionInterface) CreateWorkflowEvent(ctx context.Context, request *admin.WorkflowExecutionEventRequest) (*admin.WorkflowExecutionEventResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for CreateWorkflowEvent") + } + + var r0 *admin.WorkflowExecutionEventResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowExecutionEventRequest) (*admin.WorkflowExecutionEventResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowExecutionEventRequest) *admin.WorkflowExecutionEventResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.WorkflowExecutionEventResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.WorkflowExecutionEventRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ExecutionInterface_CreateWorkflowEvent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateWorkflowEvent' +type ExecutionInterface_CreateWorkflowEvent_Call struct { + *mock.Call +} + +// CreateWorkflowEvent is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.WorkflowExecutionEventRequest +func (_e *ExecutionInterface_Expecter) CreateWorkflowEvent(ctx interface{}, request interface{}) *ExecutionInterface_CreateWorkflowEvent_Call { + return &ExecutionInterface_CreateWorkflowEvent_Call{Call: _e.mock.On("CreateWorkflowEvent", ctx, request)} +} + +func (_c *ExecutionInterface_CreateWorkflowEvent_Call) Run(run func(ctx context.Context, request *admin.WorkflowExecutionEventRequest)) *ExecutionInterface_CreateWorkflowEvent_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.WorkflowExecutionEventRequest)) + }) + return _c +} + +func (_c *ExecutionInterface_CreateWorkflowEvent_Call) Return(_a0 *admin.WorkflowExecutionEventResponse, _a1 error) *ExecutionInterface_CreateWorkflowEvent_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ExecutionInterface_CreateWorkflowEvent_Call) RunAndReturn(run func(context.Context, *admin.WorkflowExecutionEventRequest) (*admin.WorkflowExecutionEventResponse, error)) *ExecutionInterface_CreateWorkflowEvent_Call { + _c.Call.Return(run) + return _c +} + +// GetExecution provides a mock function with given fields: ctx, request +func (_m *ExecutionInterface) GetExecution(ctx context.Context, request *admin.WorkflowExecutionGetRequest) (*admin.Execution, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetExecution") + } + + var r0 *admin.Execution + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowExecutionGetRequest) (*admin.Execution, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowExecutionGetRequest) *admin.Execution); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.Execution) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.WorkflowExecutionGetRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ExecutionInterface_GetExecution_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetExecution' +type ExecutionInterface_GetExecution_Call struct { + *mock.Call +} + +// GetExecution is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.WorkflowExecutionGetRequest +func (_e *ExecutionInterface_Expecter) GetExecution(ctx interface{}, request interface{}) *ExecutionInterface_GetExecution_Call { + return &ExecutionInterface_GetExecution_Call{Call: _e.mock.On("GetExecution", ctx, request)} +} + +func (_c *ExecutionInterface_GetExecution_Call) Run(run func(ctx context.Context, request *admin.WorkflowExecutionGetRequest)) *ExecutionInterface_GetExecution_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.WorkflowExecutionGetRequest)) + }) + return _c +} + +func (_c *ExecutionInterface_GetExecution_Call) Return(_a0 *admin.Execution, _a1 error) *ExecutionInterface_GetExecution_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ExecutionInterface_GetExecution_Call) RunAndReturn(run func(context.Context, *admin.WorkflowExecutionGetRequest) (*admin.Execution, error)) *ExecutionInterface_GetExecution_Call { + _c.Call.Return(run) + return _c +} + +// GetExecutionData provides a mock function with given fields: ctx, request +func (_m *ExecutionInterface) GetExecutionData(ctx context.Context, request *admin.WorkflowExecutionGetDataRequest) (*admin.WorkflowExecutionGetDataResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetExecutionData") + } + + var r0 *admin.WorkflowExecutionGetDataResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowExecutionGetDataRequest) (*admin.WorkflowExecutionGetDataResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowExecutionGetDataRequest) *admin.WorkflowExecutionGetDataResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.WorkflowExecutionGetDataResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.WorkflowExecutionGetDataRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ExecutionInterface_GetExecutionData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetExecutionData' +type ExecutionInterface_GetExecutionData_Call struct { + *mock.Call +} + +// GetExecutionData is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.WorkflowExecutionGetDataRequest +func (_e *ExecutionInterface_Expecter) GetExecutionData(ctx interface{}, request interface{}) *ExecutionInterface_GetExecutionData_Call { + return &ExecutionInterface_GetExecutionData_Call{Call: _e.mock.On("GetExecutionData", ctx, request)} +} + +func (_c *ExecutionInterface_GetExecutionData_Call) Run(run func(ctx context.Context, request *admin.WorkflowExecutionGetDataRequest)) *ExecutionInterface_GetExecutionData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.WorkflowExecutionGetDataRequest)) + }) + return _c +} + +func (_c *ExecutionInterface_GetExecutionData_Call) Return(_a0 *admin.WorkflowExecutionGetDataResponse, _a1 error) *ExecutionInterface_GetExecutionData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ExecutionInterface_GetExecutionData_Call) RunAndReturn(run func(context.Context, *admin.WorkflowExecutionGetDataRequest) (*admin.WorkflowExecutionGetDataResponse, error)) *ExecutionInterface_GetExecutionData_Call { + _c.Call.Return(run) + return _c +} + +// ListExecutions provides a mock function with given fields: ctx, request +func (_m *ExecutionInterface) ListExecutions(ctx context.Context, request *admin.ResourceListRequest) (*admin.ExecutionList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListExecutions") + } + + var r0 *admin.ExecutionList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ResourceListRequest) (*admin.ExecutionList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ResourceListRequest) *admin.ExecutionList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.ExecutionList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ResourceListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ExecutionInterface_ListExecutions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListExecutions' +type ExecutionInterface_ListExecutions_Call struct { + *mock.Call +} + +// ListExecutions is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ResourceListRequest +func (_e *ExecutionInterface_Expecter) ListExecutions(ctx interface{}, request interface{}) *ExecutionInterface_ListExecutions_Call { + return &ExecutionInterface_ListExecutions_Call{Call: _e.mock.On("ListExecutions", ctx, request)} +} + +func (_c *ExecutionInterface_ListExecutions_Call) Run(run func(ctx context.Context, request *admin.ResourceListRequest)) *ExecutionInterface_ListExecutions_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ResourceListRequest)) + }) + return _c +} + +func (_c *ExecutionInterface_ListExecutions_Call) Return(_a0 *admin.ExecutionList, _a1 error) *ExecutionInterface_ListExecutions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ExecutionInterface_ListExecutions_Call) RunAndReturn(run func(context.Context, *admin.ResourceListRequest) (*admin.ExecutionList, error)) *ExecutionInterface_ListExecutions_Call { + _c.Call.Return(run) + return _c +} + +// RecoverExecution provides a mock function with given fields: ctx, request, requestedAt +func (_m *ExecutionInterface) RecoverExecution(ctx context.Context, request *admin.ExecutionRecoverRequest, requestedAt time.Time) (*admin.ExecutionCreateResponse, error) { + ret := _m.Called(ctx, request, requestedAt) + + if len(ret) == 0 { + panic("no return value specified for RecoverExecution") + } + + var r0 *admin.ExecutionCreateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ExecutionRecoverRequest, time.Time) (*admin.ExecutionCreateResponse, error)); ok { + return rf(ctx, request, requestedAt) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ExecutionRecoverRequest, time.Time) *admin.ExecutionCreateResponse); ok { + r0 = rf(ctx, request, requestedAt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.ExecutionCreateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ExecutionRecoverRequest, time.Time) error); ok { + r1 = rf(ctx, request, requestedAt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ExecutionInterface_RecoverExecution_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RecoverExecution' +type ExecutionInterface_RecoverExecution_Call struct { + *mock.Call +} + +// RecoverExecution is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ExecutionRecoverRequest +// - requestedAt time.Time +func (_e *ExecutionInterface_Expecter) RecoverExecution(ctx interface{}, request interface{}, requestedAt interface{}) *ExecutionInterface_RecoverExecution_Call { + return &ExecutionInterface_RecoverExecution_Call{Call: _e.mock.On("RecoverExecution", ctx, request, requestedAt)} +} + +func (_c *ExecutionInterface_RecoverExecution_Call) Run(run func(ctx context.Context, request *admin.ExecutionRecoverRequest, requestedAt time.Time)) *ExecutionInterface_RecoverExecution_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ExecutionRecoverRequest), args[2].(time.Time)) + }) + return _c +} + +func (_c *ExecutionInterface_RecoverExecution_Call) Return(_a0 *admin.ExecutionCreateResponse, _a1 error) *ExecutionInterface_RecoverExecution_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ExecutionInterface_RecoverExecution_Call) RunAndReturn(run func(context.Context, *admin.ExecutionRecoverRequest, time.Time) (*admin.ExecutionCreateResponse, error)) *ExecutionInterface_RecoverExecution_Call { + _c.Call.Return(run) + return _c +} + +// RelaunchExecution provides a mock function with given fields: ctx, request, requestedAt +func (_m *ExecutionInterface) RelaunchExecution(ctx context.Context, request *admin.ExecutionRelaunchRequest, requestedAt time.Time) (*admin.ExecutionCreateResponse, error) { + ret := _m.Called(ctx, request, requestedAt) + + if len(ret) == 0 { + panic("no return value specified for RelaunchExecution") + } + + var r0 *admin.ExecutionCreateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ExecutionRelaunchRequest, time.Time) (*admin.ExecutionCreateResponse, error)); ok { + return rf(ctx, request, requestedAt) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ExecutionRelaunchRequest, time.Time) *admin.ExecutionCreateResponse); ok { + r0 = rf(ctx, request, requestedAt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.ExecutionCreateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ExecutionRelaunchRequest, time.Time) error); ok { + r1 = rf(ctx, request, requestedAt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ExecutionInterface_RelaunchExecution_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RelaunchExecution' +type ExecutionInterface_RelaunchExecution_Call struct { + *mock.Call +} + +// RelaunchExecution is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ExecutionRelaunchRequest +// - requestedAt time.Time +func (_e *ExecutionInterface_Expecter) RelaunchExecution(ctx interface{}, request interface{}, requestedAt interface{}) *ExecutionInterface_RelaunchExecution_Call { + return &ExecutionInterface_RelaunchExecution_Call{Call: _e.mock.On("RelaunchExecution", ctx, request, requestedAt)} +} + +func (_c *ExecutionInterface_RelaunchExecution_Call) Run(run func(ctx context.Context, request *admin.ExecutionRelaunchRequest, requestedAt time.Time)) *ExecutionInterface_RelaunchExecution_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ExecutionRelaunchRequest), args[2].(time.Time)) + }) + return _c +} + +func (_c *ExecutionInterface_RelaunchExecution_Call) Return(_a0 *admin.ExecutionCreateResponse, _a1 error) *ExecutionInterface_RelaunchExecution_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ExecutionInterface_RelaunchExecution_Call) RunAndReturn(run func(context.Context, *admin.ExecutionRelaunchRequest, time.Time) (*admin.ExecutionCreateResponse, error)) *ExecutionInterface_RelaunchExecution_Call { + _c.Call.Return(run) + return _c +} + +// TerminateExecution provides a mock function with given fields: ctx, request +func (_m *ExecutionInterface) TerminateExecution(ctx context.Context, request *admin.ExecutionTerminateRequest) (*admin.ExecutionTerminateResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for TerminateExecution") + } + + var r0 *admin.ExecutionTerminateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ExecutionTerminateRequest) (*admin.ExecutionTerminateResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ExecutionTerminateRequest) *admin.ExecutionTerminateResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.ExecutionTerminateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ExecutionTerminateRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ExecutionInterface_TerminateExecution_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TerminateExecution' +type ExecutionInterface_TerminateExecution_Call struct { + *mock.Call +} + +// TerminateExecution is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ExecutionTerminateRequest +func (_e *ExecutionInterface_Expecter) TerminateExecution(ctx interface{}, request interface{}) *ExecutionInterface_TerminateExecution_Call { + return &ExecutionInterface_TerminateExecution_Call{Call: _e.mock.On("TerminateExecution", ctx, request)} +} + +func (_c *ExecutionInterface_TerminateExecution_Call) Run(run func(ctx context.Context, request *admin.ExecutionTerminateRequest)) *ExecutionInterface_TerminateExecution_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ExecutionTerminateRequest)) + }) + return _c +} + +func (_c *ExecutionInterface_TerminateExecution_Call) Return(_a0 *admin.ExecutionTerminateResponse, _a1 error) *ExecutionInterface_TerminateExecution_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ExecutionInterface_TerminateExecution_Call) RunAndReturn(run func(context.Context, *admin.ExecutionTerminateRequest) (*admin.ExecutionTerminateResponse, error)) *ExecutionInterface_TerminateExecution_Call { + _c.Call.Return(run) + return _c +} + +// UpdateExecution provides a mock function with given fields: ctx, request, requestedAt +func (_m *ExecutionInterface) UpdateExecution(ctx context.Context, request *admin.ExecutionUpdateRequest, requestedAt time.Time) (*admin.ExecutionUpdateResponse, error) { + ret := _m.Called(ctx, request, requestedAt) + + if len(ret) == 0 { + panic("no return value specified for UpdateExecution") + } + + var r0 *admin.ExecutionUpdateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ExecutionUpdateRequest, time.Time) (*admin.ExecutionUpdateResponse, error)); ok { + return rf(ctx, request, requestedAt) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ExecutionUpdateRequest, time.Time) *admin.ExecutionUpdateResponse); ok { + r0 = rf(ctx, request, requestedAt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.ExecutionUpdateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ExecutionUpdateRequest, time.Time) error); ok { + r1 = rf(ctx, request, requestedAt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ExecutionInterface_UpdateExecution_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateExecution' +type ExecutionInterface_UpdateExecution_Call struct { + *mock.Call +} + +// UpdateExecution is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ExecutionUpdateRequest +// - requestedAt time.Time +func (_e *ExecutionInterface_Expecter) UpdateExecution(ctx interface{}, request interface{}, requestedAt interface{}) *ExecutionInterface_UpdateExecution_Call { + return &ExecutionInterface_UpdateExecution_Call{Call: _e.mock.On("UpdateExecution", ctx, request, requestedAt)} +} + +func (_c *ExecutionInterface_UpdateExecution_Call) Run(run func(ctx context.Context, request *admin.ExecutionUpdateRequest, requestedAt time.Time)) *ExecutionInterface_UpdateExecution_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ExecutionUpdateRequest), args[2].(time.Time)) + }) + return _c +} + +func (_c *ExecutionInterface_UpdateExecution_Call) Return(_a0 *admin.ExecutionUpdateResponse, _a1 error) *ExecutionInterface_UpdateExecution_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ExecutionInterface_UpdateExecution_Call) RunAndReturn(run func(context.Context, *admin.ExecutionUpdateRequest, time.Time) (*admin.ExecutionUpdateResponse, error)) *ExecutionInterface_UpdateExecution_Call { + _c.Call.Return(run) + return _c +} + +// NewExecutionInterface creates a new instance of ExecutionInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewExecutionInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *ExecutionInterface { + mock := &ExecutionInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/flyteadmin/pkg/manager/mocks/launch_plan.go b/flyteadmin/pkg/manager/mocks/launch_plan.go deleted file mode 100644 index 5850f95ceb..0000000000 --- a/flyteadmin/pkg/manager/mocks/launch_plan.go +++ /dev/null @@ -1,114 +0,0 @@ -package mocks - -import ( - "context" - - "github.com/flyteorg/flyte/flyteadmin/pkg/manager/interfaces" - "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" -) - -type CreateLaunchPlanFunc func(ctx context.Context, request *admin.LaunchPlanCreateRequest) ( - *admin.LaunchPlanCreateResponse, error) -type UpdateLaunchPlanFunc func(ctx context.Context, request *admin.LaunchPlanUpdateRequest) ( - *admin.LaunchPlanUpdateResponse, error) -type GetLaunchPlanFunc func(ctx context.Context, request *admin.ObjectGetRequest) ( - *admin.LaunchPlan, error) -type GetActiveLaunchPlanFunc func(ctx context.Context, request *admin.ActiveLaunchPlanRequest) ( - *admin.LaunchPlan, error) -type ListLaunchPlansFunc func(ctx context.Context, request *admin.ResourceListRequest) ( - *admin.LaunchPlanList, error) -type ListLaunchPlanIdsFunc func(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) ( - *admin.NamedEntityIdentifierList, error) -type ListActiveLaunchPlansFunc func(ctx context.Context, request *admin.ActiveLaunchPlanListRequest) ( - *admin.LaunchPlanList, error) - -type MockLaunchPlanManager struct { - createLaunchPlanFunc CreateLaunchPlanFunc - updateLaunchPlanFunc UpdateLaunchPlanFunc - getLaunchPlanFunc GetLaunchPlanFunc - getActiveLaunchPlanFunc GetActiveLaunchPlanFunc - listLaunchPlansFunc ListLaunchPlansFunc - listLaunchPlanIdsFunc ListLaunchPlanIdsFunc - listActiveLaunchPlansFunc ListActiveLaunchPlansFunc -} - -func (r *MockLaunchPlanManager) SetCreateCallback(createFunction CreateLaunchPlanFunc) { - r.createLaunchPlanFunc = createFunction -} - -func (r *MockLaunchPlanManager) CreateLaunchPlan( - ctx context.Context, - request *admin.LaunchPlanCreateRequest) (*admin.LaunchPlanCreateResponse, error) { - if r.createLaunchPlanFunc != nil { - return r.createLaunchPlanFunc(ctx, request) - } - return nil, nil -} - -func (r *MockLaunchPlanManager) SetUpdateLaunchPlan(updateFunction UpdateLaunchPlanFunc) { - r.updateLaunchPlanFunc = updateFunction -} - -func (r *MockLaunchPlanManager) UpdateLaunchPlan(ctx context.Context, request *admin.LaunchPlanUpdateRequest) ( - *admin.LaunchPlanUpdateResponse, error) { - if r.updateLaunchPlanFunc != nil { - return r.updateLaunchPlanFunc(ctx, request) - } - return nil, nil -} - -func (r *MockLaunchPlanManager) GetLaunchPlan(ctx context.Context, request *admin.ObjectGetRequest) ( - *admin.LaunchPlan, error) { - if r.getLaunchPlanFunc != nil { - return r.getLaunchPlanFunc(ctx, request) - } - return nil, nil -} - -func (r *MockLaunchPlanManager) SetGetActiveLaunchPlanCallback(plansFunc GetActiveLaunchPlanFunc) { - r.getActiveLaunchPlanFunc = plansFunc -} - -func (r *MockLaunchPlanManager) GetActiveLaunchPlan(ctx context.Context, request *admin.ActiveLaunchPlanRequest) ( - *admin.LaunchPlan, error) { - if r.getActiveLaunchPlanFunc != nil { - return r.getActiveLaunchPlanFunc(ctx, request) - } - return nil, nil -} - -func (r *MockLaunchPlanManager) SetListLaunchPlansCallback(listLaunchPlansFunc ListLaunchPlansFunc) { - r.listLaunchPlansFunc = listLaunchPlansFunc -} - -func (r *MockLaunchPlanManager) ListLaunchPlans(ctx context.Context, request *admin.ResourceListRequest) ( - *admin.LaunchPlanList, error) { - if r.listLaunchPlansFunc != nil { - return r.listLaunchPlansFunc(ctx, request) - } - return nil, nil -} - -func (r *MockLaunchPlanManager) SetListActiveLaunchPlansCallback(plansFunc ListActiveLaunchPlansFunc) { - r.listActiveLaunchPlansFunc = plansFunc -} - -func (r *MockLaunchPlanManager) ListActiveLaunchPlans(ctx context.Context, request *admin.ActiveLaunchPlanListRequest) ( - *admin.LaunchPlanList, error) { - if r.listActiveLaunchPlansFunc != nil { - return r.listActiveLaunchPlansFunc(ctx, request) - } - return nil, nil -} - -func (r *MockLaunchPlanManager) ListLaunchPlanIds(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) ( - *admin.NamedEntityIdentifierList, error) { - if r.listLaunchPlanIdsFunc != nil { - return r.ListLaunchPlanIds(ctx, request) - } - return nil, nil -} - -func NewMockLaunchPlanManager() interfaces.LaunchPlanInterface { - return &MockLaunchPlanManager{} -} diff --git a/flyteadmin/pkg/manager/mocks/launch_plan_interface.go b/flyteadmin/pkg/manager/mocks/launch_plan_interface.go new file mode 100644 index 0000000000..f75256350f --- /dev/null +++ b/flyteadmin/pkg/manager/mocks/launch_plan_interface.go @@ -0,0 +1,451 @@ +// Code generated by mockery v2.40.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + admin "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" + + mock "github.com/stretchr/testify/mock" +) + +// LaunchPlanInterface is an autogenerated mock type for the LaunchPlanInterface type +type LaunchPlanInterface struct { + mock.Mock +} + +type LaunchPlanInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *LaunchPlanInterface) EXPECT() *LaunchPlanInterface_Expecter { + return &LaunchPlanInterface_Expecter{mock: &_m.Mock} +} + +// CreateLaunchPlan provides a mock function with given fields: ctx, request +func (_m *LaunchPlanInterface) CreateLaunchPlan(ctx context.Context, request *admin.LaunchPlanCreateRequest) (*admin.LaunchPlanCreateResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for CreateLaunchPlan") + } + + var r0 *admin.LaunchPlanCreateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.LaunchPlanCreateRequest) (*admin.LaunchPlanCreateResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.LaunchPlanCreateRequest) *admin.LaunchPlanCreateResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.LaunchPlanCreateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.LaunchPlanCreateRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LaunchPlanInterface_CreateLaunchPlan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateLaunchPlan' +type LaunchPlanInterface_CreateLaunchPlan_Call struct { + *mock.Call +} + +// CreateLaunchPlan is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.LaunchPlanCreateRequest +func (_e *LaunchPlanInterface_Expecter) CreateLaunchPlan(ctx interface{}, request interface{}) *LaunchPlanInterface_CreateLaunchPlan_Call { + return &LaunchPlanInterface_CreateLaunchPlan_Call{Call: _e.mock.On("CreateLaunchPlan", ctx, request)} +} + +func (_c *LaunchPlanInterface_CreateLaunchPlan_Call) Run(run func(ctx context.Context, request *admin.LaunchPlanCreateRequest)) *LaunchPlanInterface_CreateLaunchPlan_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.LaunchPlanCreateRequest)) + }) + return _c +} + +func (_c *LaunchPlanInterface_CreateLaunchPlan_Call) Return(_a0 *admin.LaunchPlanCreateResponse, _a1 error) *LaunchPlanInterface_CreateLaunchPlan_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LaunchPlanInterface_CreateLaunchPlan_Call) RunAndReturn(run func(context.Context, *admin.LaunchPlanCreateRequest) (*admin.LaunchPlanCreateResponse, error)) *LaunchPlanInterface_CreateLaunchPlan_Call { + _c.Call.Return(run) + return _c +} + +// GetActiveLaunchPlan provides a mock function with given fields: ctx, request +func (_m *LaunchPlanInterface) GetActiveLaunchPlan(ctx context.Context, request *admin.ActiveLaunchPlanRequest) (*admin.LaunchPlan, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetActiveLaunchPlan") + } + + var r0 *admin.LaunchPlan + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ActiveLaunchPlanRequest) (*admin.LaunchPlan, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ActiveLaunchPlanRequest) *admin.LaunchPlan); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.LaunchPlan) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ActiveLaunchPlanRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LaunchPlanInterface_GetActiveLaunchPlan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetActiveLaunchPlan' +type LaunchPlanInterface_GetActiveLaunchPlan_Call struct { + *mock.Call +} + +// GetActiveLaunchPlan is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ActiveLaunchPlanRequest +func (_e *LaunchPlanInterface_Expecter) GetActiveLaunchPlan(ctx interface{}, request interface{}) *LaunchPlanInterface_GetActiveLaunchPlan_Call { + return &LaunchPlanInterface_GetActiveLaunchPlan_Call{Call: _e.mock.On("GetActiveLaunchPlan", ctx, request)} +} + +func (_c *LaunchPlanInterface_GetActiveLaunchPlan_Call) Run(run func(ctx context.Context, request *admin.ActiveLaunchPlanRequest)) *LaunchPlanInterface_GetActiveLaunchPlan_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ActiveLaunchPlanRequest)) + }) + return _c +} + +func (_c *LaunchPlanInterface_GetActiveLaunchPlan_Call) Return(_a0 *admin.LaunchPlan, _a1 error) *LaunchPlanInterface_GetActiveLaunchPlan_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LaunchPlanInterface_GetActiveLaunchPlan_Call) RunAndReturn(run func(context.Context, *admin.ActiveLaunchPlanRequest) (*admin.LaunchPlan, error)) *LaunchPlanInterface_GetActiveLaunchPlan_Call { + _c.Call.Return(run) + return _c +} + +// GetLaunchPlan provides a mock function with given fields: ctx, request +func (_m *LaunchPlanInterface) GetLaunchPlan(ctx context.Context, request *admin.ObjectGetRequest) (*admin.LaunchPlan, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetLaunchPlan") + } + + var r0 *admin.LaunchPlan + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ObjectGetRequest) (*admin.LaunchPlan, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ObjectGetRequest) *admin.LaunchPlan); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.LaunchPlan) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ObjectGetRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LaunchPlanInterface_GetLaunchPlan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLaunchPlan' +type LaunchPlanInterface_GetLaunchPlan_Call struct { + *mock.Call +} + +// GetLaunchPlan is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ObjectGetRequest +func (_e *LaunchPlanInterface_Expecter) GetLaunchPlan(ctx interface{}, request interface{}) *LaunchPlanInterface_GetLaunchPlan_Call { + return &LaunchPlanInterface_GetLaunchPlan_Call{Call: _e.mock.On("GetLaunchPlan", ctx, request)} +} + +func (_c *LaunchPlanInterface_GetLaunchPlan_Call) Run(run func(ctx context.Context, request *admin.ObjectGetRequest)) *LaunchPlanInterface_GetLaunchPlan_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ObjectGetRequest)) + }) + return _c +} + +func (_c *LaunchPlanInterface_GetLaunchPlan_Call) Return(_a0 *admin.LaunchPlan, _a1 error) *LaunchPlanInterface_GetLaunchPlan_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LaunchPlanInterface_GetLaunchPlan_Call) RunAndReturn(run func(context.Context, *admin.ObjectGetRequest) (*admin.LaunchPlan, error)) *LaunchPlanInterface_GetLaunchPlan_Call { + _c.Call.Return(run) + return _c +} + +// ListActiveLaunchPlans provides a mock function with given fields: ctx, request +func (_m *LaunchPlanInterface) ListActiveLaunchPlans(ctx context.Context, request *admin.ActiveLaunchPlanListRequest) (*admin.LaunchPlanList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListActiveLaunchPlans") + } + + var r0 *admin.LaunchPlanList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ActiveLaunchPlanListRequest) (*admin.LaunchPlanList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ActiveLaunchPlanListRequest) *admin.LaunchPlanList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.LaunchPlanList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ActiveLaunchPlanListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LaunchPlanInterface_ListActiveLaunchPlans_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListActiveLaunchPlans' +type LaunchPlanInterface_ListActiveLaunchPlans_Call struct { + *mock.Call +} + +// ListActiveLaunchPlans is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ActiveLaunchPlanListRequest +func (_e *LaunchPlanInterface_Expecter) ListActiveLaunchPlans(ctx interface{}, request interface{}) *LaunchPlanInterface_ListActiveLaunchPlans_Call { + return &LaunchPlanInterface_ListActiveLaunchPlans_Call{Call: _e.mock.On("ListActiveLaunchPlans", ctx, request)} +} + +func (_c *LaunchPlanInterface_ListActiveLaunchPlans_Call) Run(run func(ctx context.Context, request *admin.ActiveLaunchPlanListRequest)) *LaunchPlanInterface_ListActiveLaunchPlans_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ActiveLaunchPlanListRequest)) + }) + return _c +} + +func (_c *LaunchPlanInterface_ListActiveLaunchPlans_Call) Return(_a0 *admin.LaunchPlanList, _a1 error) *LaunchPlanInterface_ListActiveLaunchPlans_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LaunchPlanInterface_ListActiveLaunchPlans_Call) RunAndReturn(run func(context.Context, *admin.ActiveLaunchPlanListRequest) (*admin.LaunchPlanList, error)) *LaunchPlanInterface_ListActiveLaunchPlans_Call { + _c.Call.Return(run) + return _c +} + +// ListLaunchPlanIds provides a mock function with given fields: ctx, request +func (_m *LaunchPlanInterface) ListLaunchPlanIds(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListLaunchPlanIds") + } + + var r0 *admin.NamedEntityIdentifierList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityIdentifierListRequest) *admin.NamedEntityIdentifierList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NamedEntityIdentifierList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NamedEntityIdentifierListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LaunchPlanInterface_ListLaunchPlanIds_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListLaunchPlanIds' +type LaunchPlanInterface_ListLaunchPlanIds_Call struct { + *mock.Call +} + +// ListLaunchPlanIds is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NamedEntityIdentifierListRequest +func (_e *LaunchPlanInterface_Expecter) ListLaunchPlanIds(ctx interface{}, request interface{}) *LaunchPlanInterface_ListLaunchPlanIds_Call { + return &LaunchPlanInterface_ListLaunchPlanIds_Call{Call: _e.mock.On("ListLaunchPlanIds", ctx, request)} +} + +func (_c *LaunchPlanInterface_ListLaunchPlanIds_Call) Run(run func(ctx context.Context, request *admin.NamedEntityIdentifierListRequest)) *LaunchPlanInterface_ListLaunchPlanIds_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NamedEntityIdentifierListRequest)) + }) + return _c +} + +func (_c *LaunchPlanInterface_ListLaunchPlanIds_Call) Return(_a0 *admin.NamedEntityIdentifierList, _a1 error) *LaunchPlanInterface_ListLaunchPlanIds_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LaunchPlanInterface_ListLaunchPlanIds_Call) RunAndReturn(run func(context.Context, *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error)) *LaunchPlanInterface_ListLaunchPlanIds_Call { + _c.Call.Return(run) + return _c +} + +// ListLaunchPlans provides a mock function with given fields: ctx, request +func (_m *LaunchPlanInterface) ListLaunchPlans(ctx context.Context, request *admin.ResourceListRequest) (*admin.LaunchPlanList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListLaunchPlans") + } + + var r0 *admin.LaunchPlanList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ResourceListRequest) (*admin.LaunchPlanList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ResourceListRequest) *admin.LaunchPlanList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.LaunchPlanList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ResourceListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LaunchPlanInterface_ListLaunchPlans_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListLaunchPlans' +type LaunchPlanInterface_ListLaunchPlans_Call struct { + *mock.Call +} + +// ListLaunchPlans is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ResourceListRequest +func (_e *LaunchPlanInterface_Expecter) ListLaunchPlans(ctx interface{}, request interface{}) *LaunchPlanInterface_ListLaunchPlans_Call { + return &LaunchPlanInterface_ListLaunchPlans_Call{Call: _e.mock.On("ListLaunchPlans", ctx, request)} +} + +func (_c *LaunchPlanInterface_ListLaunchPlans_Call) Run(run func(ctx context.Context, request *admin.ResourceListRequest)) *LaunchPlanInterface_ListLaunchPlans_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ResourceListRequest)) + }) + return _c +} + +func (_c *LaunchPlanInterface_ListLaunchPlans_Call) Return(_a0 *admin.LaunchPlanList, _a1 error) *LaunchPlanInterface_ListLaunchPlans_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LaunchPlanInterface_ListLaunchPlans_Call) RunAndReturn(run func(context.Context, *admin.ResourceListRequest) (*admin.LaunchPlanList, error)) *LaunchPlanInterface_ListLaunchPlans_Call { + _c.Call.Return(run) + return _c +} + +// UpdateLaunchPlan provides a mock function with given fields: ctx, request +func (_m *LaunchPlanInterface) UpdateLaunchPlan(ctx context.Context, request *admin.LaunchPlanUpdateRequest) (*admin.LaunchPlanUpdateResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for UpdateLaunchPlan") + } + + var r0 *admin.LaunchPlanUpdateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.LaunchPlanUpdateRequest) (*admin.LaunchPlanUpdateResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.LaunchPlanUpdateRequest) *admin.LaunchPlanUpdateResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.LaunchPlanUpdateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.LaunchPlanUpdateRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LaunchPlanInterface_UpdateLaunchPlan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateLaunchPlan' +type LaunchPlanInterface_UpdateLaunchPlan_Call struct { + *mock.Call +} + +// UpdateLaunchPlan is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.LaunchPlanUpdateRequest +func (_e *LaunchPlanInterface_Expecter) UpdateLaunchPlan(ctx interface{}, request interface{}) *LaunchPlanInterface_UpdateLaunchPlan_Call { + return &LaunchPlanInterface_UpdateLaunchPlan_Call{Call: _e.mock.On("UpdateLaunchPlan", ctx, request)} +} + +func (_c *LaunchPlanInterface_UpdateLaunchPlan_Call) Run(run func(ctx context.Context, request *admin.LaunchPlanUpdateRequest)) *LaunchPlanInterface_UpdateLaunchPlan_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.LaunchPlanUpdateRequest)) + }) + return _c +} + +func (_c *LaunchPlanInterface_UpdateLaunchPlan_Call) Return(_a0 *admin.LaunchPlanUpdateResponse, _a1 error) *LaunchPlanInterface_UpdateLaunchPlan_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LaunchPlanInterface_UpdateLaunchPlan_Call) RunAndReturn(run func(context.Context, *admin.LaunchPlanUpdateRequest) (*admin.LaunchPlanUpdateResponse, error)) *LaunchPlanInterface_UpdateLaunchPlan_Call { + _c.Call.Return(run) + return _c +} + +// NewLaunchPlanInterface creates a new instance of LaunchPlanInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLaunchPlanInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *LaunchPlanInterface { + mock := &LaunchPlanInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/flyteadmin/pkg/manager/mocks/named_entity.go b/flyteadmin/pkg/manager/mocks/named_entity.go deleted file mode 100644 index a9be253a5d..0000000000 --- a/flyteadmin/pkg/manager/mocks/named_entity.go +++ /dev/null @@ -1,38 +0,0 @@ -package mocks - -import ( - "context" - - "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" -) - -type GetNamedEntityFunc func(ctx context.Context, request *admin.NamedEntityGetRequest) (*admin.NamedEntity, error) -type UpdateNamedEntityFunc func(ctx context.Context, request *admin.NamedEntityUpdateRequest) (*admin.NamedEntityUpdateResponse, error) -type ListNamedEntitiesFunc func(ctx context.Context, request *admin.NamedEntityListRequest) (*admin.NamedEntityList, error) - -type NamedEntityManager struct { - GetNamedEntityFunc GetNamedEntityFunc - UpdateNamedEntityFunc UpdateNamedEntityFunc - ListNamedEntitiesFunc ListNamedEntitiesFunc -} - -func (m *NamedEntityManager) GetNamedEntity(ctx context.Context, request *admin.NamedEntityGetRequest) (*admin.NamedEntity, error) { - if m.GetNamedEntityFunc != nil { - return m.GetNamedEntityFunc(ctx, request) - } - return nil, nil -} - -func (m *NamedEntityManager) UpdateNamedEntity(ctx context.Context, request *admin.NamedEntityUpdateRequest) (*admin.NamedEntityUpdateResponse, error) { - if m.UpdateNamedEntityFunc != nil { - return m.UpdateNamedEntityFunc(ctx, request) - } - return nil, nil -} - -func (m *NamedEntityManager) ListNamedEntities(ctx context.Context, request *admin.NamedEntityListRequest) (*admin.NamedEntityList, error) { - if m.ListNamedEntitiesFunc != nil { - return m.ListNamedEntitiesFunc(ctx, request) - } - return nil, nil -} diff --git a/flyteadmin/pkg/manager/mocks/named_entity_interface.go b/flyteadmin/pkg/manager/mocks/named_entity_interface.go new file mode 100644 index 0000000000..a71e10da07 --- /dev/null +++ b/flyteadmin/pkg/manager/mocks/named_entity_interface.go @@ -0,0 +1,215 @@ +// Code generated by mockery v2.40.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + admin "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" + + mock "github.com/stretchr/testify/mock" +) + +// NamedEntityInterface is an autogenerated mock type for the NamedEntityInterface type +type NamedEntityInterface struct { + mock.Mock +} + +type NamedEntityInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *NamedEntityInterface) EXPECT() *NamedEntityInterface_Expecter { + return &NamedEntityInterface_Expecter{mock: &_m.Mock} +} + +// GetNamedEntity provides a mock function with given fields: ctx, request +func (_m *NamedEntityInterface) GetNamedEntity(ctx context.Context, request *admin.NamedEntityGetRequest) (*admin.NamedEntity, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetNamedEntity") + } + + var r0 *admin.NamedEntity + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityGetRequest) (*admin.NamedEntity, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityGetRequest) *admin.NamedEntity); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NamedEntity) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NamedEntityGetRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NamedEntityInterface_GetNamedEntity_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNamedEntity' +type NamedEntityInterface_GetNamedEntity_Call struct { + *mock.Call +} + +// GetNamedEntity is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NamedEntityGetRequest +func (_e *NamedEntityInterface_Expecter) GetNamedEntity(ctx interface{}, request interface{}) *NamedEntityInterface_GetNamedEntity_Call { + return &NamedEntityInterface_GetNamedEntity_Call{Call: _e.mock.On("GetNamedEntity", ctx, request)} +} + +func (_c *NamedEntityInterface_GetNamedEntity_Call) Run(run func(ctx context.Context, request *admin.NamedEntityGetRequest)) *NamedEntityInterface_GetNamedEntity_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NamedEntityGetRequest)) + }) + return _c +} + +func (_c *NamedEntityInterface_GetNamedEntity_Call) Return(_a0 *admin.NamedEntity, _a1 error) *NamedEntityInterface_GetNamedEntity_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NamedEntityInterface_GetNamedEntity_Call) RunAndReturn(run func(context.Context, *admin.NamedEntityGetRequest) (*admin.NamedEntity, error)) *NamedEntityInterface_GetNamedEntity_Call { + _c.Call.Return(run) + return _c +} + +// ListNamedEntities provides a mock function with given fields: ctx, request +func (_m *NamedEntityInterface) ListNamedEntities(ctx context.Context, request *admin.NamedEntityListRequest) (*admin.NamedEntityList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListNamedEntities") + } + + var r0 *admin.NamedEntityList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityListRequest) (*admin.NamedEntityList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityListRequest) *admin.NamedEntityList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NamedEntityList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NamedEntityListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NamedEntityInterface_ListNamedEntities_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListNamedEntities' +type NamedEntityInterface_ListNamedEntities_Call struct { + *mock.Call +} + +// ListNamedEntities is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NamedEntityListRequest +func (_e *NamedEntityInterface_Expecter) ListNamedEntities(ctx interface{}, request interface{}) *NamedEntityInterface_ListNamedEntities_Call { + return &NamedEntityInterface_ListNamedEntities_Call{Call: _e.mock.On("ListNamedEntities", ctx, request)} +} + +func (_c *NamedEntityInterface_ListNamedEntities_Call) Run(run func(ctx context.Context, request *admin.NamedEntityListRequest)) *NamedEntityInterface_ListNamedEntities_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NamedEntityListRequest)) + }) + return _c +} + +func (_c *NamedEntityInterface_ListNamedEntities_Call) Return(_a0 *admin.NamedEntityList, _a1 error) *NamedEntityInterface_ListNamedEntities_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NamedEntityInterface_ListNamedEntities_Call) RunAndReturn(run func(context.Context, *admin.NamedEntityListRequest) (*admin.NamedEntityList, error)) *NamedEntityInterface_ListNamedEntities_Call { + _c.Call.Return(run) + return _c +} + +// UpdateNamedEntity provides a mock function with given fields: ctx, request +func (_m *NamedEntityInterface) UpdateNamedEntity(ctx context.Context, request *admin.NamedEntityUpdateRequest) (*admin.NamedEntityUpdateResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for UpdateNamedEntity") + } + + var r0 *admin.NamedEntityUpdateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityUpdateRequest) (*admin.NamedEntityUpdateResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityUpdateRequest) *admin.NamedEntityUpdateResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NamedEntityUpdateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NamedEntityUpdateRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NamedEntityInterface_UpdateNamedEntity_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateNamedEntity' +type NamedEntityInterface_UpdateNamedEntity_Call struct { + *mock.Call +} + +// UpdateNamedEntity is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NamedEntityUpdateRequest +func (_e *NamedEntityInterface_Expecter) UpdateNamedEntity(ctx interface{}, request interface{}) *NamedEntityInterface_UpdateNamedEntity_Call { + return &NamedEntityInterface_UpdateNamedEntity_Call{Call: _e.mock.On("UpdateNamedEntity", ctx, request)} +} + +func (_c *NamedEntityInterface_UpdateNamedEntity_Call) Run(run func(ctx context.Context, request *admin.NamedEntityUpdateRequest)) *NamedEntityInterface_UpdateNamedEntity_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NamedEntityUpdateRequest)) + }) + return _c +} + +func (_c *NamedEntityInterface_UpdateNamedEntity_Call) Return(_a0 *admin.NamedEntityUpdateResponse, _a1 error) *NamedEntityInterface_UpdateNamedEntity_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NamedEntityInterface_UpdateNamedEntity_Call) RunAndReturn(run func(context.Context, *admin.NamedEntityUpdateRequest) (*admin.NamedEntityUpdateResponse, error)) *NamedEntityInterface_UpdateNamedEntity_Call { + _c.Call.Return(run) + return _c +} + +// NewNamedEntityInterface creates a new instance of NamedEntityInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewNamedEntityInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *NamedEntityInterface { + mock := &NamedEntityInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/flyteadmin/pkg/manager/mocks/node_execution.go b/flyteadmin/pkg/manager/mocks/node_execution.go deleted file mode 100644 index 809398830f..0000000000 --- a/flyteadmin/pkg/manager/mocks/node_execution.go +++ /dev/null @@ -1,90 +0,0 @@ -package mocks - -import ( - "context" - - "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" -) - -type CreateNodeEventFunc func(ctx context.Context, request *admin.NodeExecutionEventRequest) ( - *admin.NodeExecutionEventResponse, error) -type GetNodeExecutionFunc func(ctx context.Context, request *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error) -type ListNodeExecutionsFunc func( - ctx context.Context, request *admin.NodeExecutionListRequest) (*admin.NodeExecutionList, error) -type ListNodeExecutionsForTaskFunc func(ctx context.Context, request *admin.NodeExecutionForTaskListRequest) ( - *admin.NodeExecutionList, error) -type GetNodeExecutionDataFunc func( - ctx context.Context, request *admin.NodeExecutionGetDataRequest) (*admin.NodeExecutionGetDataResponse, error) - -type MockNodeExecutionManager struct { - createNodeEventFunc CreateNodeEventFunc - getNodeExecutionFunc GetNodeExecutionFunc - listNodeExecutionsFunc ListNodeExecutionsFunc - listNodeExecutionsForTaskFunc ListNodeExecutionsForTaskFunc - getNodeExecutionDataFunc GetNodeExecutionDataFunc -} - -func (m *MockNodeExecutionManager) SetCreateNodeEventCallback(createNodeEventFunc CreateNodeEventFunc) { - m.createNodeEventFunc = createNodeEventFunc -} - -func (m *MockNodeExecutionManager) CreateNodeEvent( - ctx context.Context, - request *admin.NodeExecutionEventRequest) (*admin.NodeExecutionEventResponse, error) { - if m.createNodeEventFunc != nil { - return m.createNodeEventFunc(ctx, request) - } - return nil, nil -} - -func (m *MockNodeExecutionManager) SetGetNodeExecutionFunc(getNodeExecutionFunc GetNodeExecutionFunc) { - m.getNodeExecutionFunc = getNodeExecutionFunc -} - -func (m *MockNodeExecutionManager) GetNodeExecution( - ctx context.Context, request *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error) { - if m.getNodeExecutionFunc != nil { - return m.getNodeExecutionFunc(ctx, request) - } - return nil, nil -} - -func (m *MockNodeExecutionManager) SetListNodeExecutionsFunc(listNodeExecutionsFunc ListNodeExecutionsFunc) { - m.listNodeExecutionsFunc = listNodeExecutionsFunc -} - -func (m *MockNodeExecutionManager) ListNodeExecutions( - ctx context.Context, request *admin.NodeExecutionListRequest) (*admin.NodeExecutionList, error) { - if m.listNodeExecutionsFunc != nil { - return m.listNodeExecutionsFunc(ctx, request) - } - return nil, nil -} - -func (m *MockNodeExecutionManager) SetListNodeExecutionsForTaskFunc(listNodeExecutionsForTaskFunc ListNodeExecutionsForTaskFunc) { - m.listNodeExecutionsForTaskFunc = listNodeExecutionsForTaskFunc -} - -func (m *MockNodeExecutionManager) ListNodeExecutionsForTask( - ctx context.Context, request *admin.NodeExecutionForTaskListRequest) (*admin.NodeExecutionList, error) { - if m.listNodeExecutionsForTaskFunc != nil { - return m.listNodeExecutionsForTaskFunc(ctx, request) - } - return nil, nil -} - -func (m *MockNodeExecutionManager) SetGetNodeExecutionDataFunc(getNodeExecutionDataFunc GetNodeExecutionDataFunc) { - m.getNodeExecutionDataFunc = getNodeExecutionDataFunc -} - -func (m *MockNodeExecutionManager) GetNodeExecutionData( - ctx context.Context, request *admin.NodeExecutionGetDataRequest) (*admin.NodeExecutionGetDataResponse, error) { - if m.getNodeExecutionDataFunc != nil { - return m.getNodeExecutionDataFunc(ctx, request) - } - return nil, nil -} - -func (m *MockNodeExecutionManager) GetDynamicNodeWorkflow(ctx context.Context, request *admin.GetDynamicNodeWorkflowRequest) (*admin.DynamicNodeWorkflowResponse, error) { - return nil, nil -} diff --git a/flyteadmin/pkg/manager/mocks/node_execution_interface.go b/flyteadmin/pkg/manager/mocks/node_execution_interface.go new file mode 100644 index 0000000000..54858c7c25 --- /dev/null +++ b/flyteadmin/pkg/manager/mocks/node_execution_interface.go @@ -0,0 +1,392 @@ +// Code generated by mockery v2.40.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + admin "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" + + mock "github.com/stretchr/testify/mock" +) + +// NodeExecutionInterface is an autogenerated mock type for the NodeExecutionInterface type +type NodeExecutionInterface struct { + mock.Mock +} + +type NodeExecutionInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *NodeExecutionInterface) EXPECT() *NodeExecutionInterface_Expecter { + return &NodeExecutionInterface_Expecter{mock: &_m.Mock} +} + +// CreateNodeEvent provides a mock function with given fields: ctx, request +func (_m *NodeExecutionInterface) CreateNodeEvent(ctx context.Context, request *admin.NodeExecutionEventRequest) (*admin.NodeExecutionEventResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for CreateNodeEvent") + } + + var r0 *admin.NodeExecutionEventResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NodeExecutionEventRequest) (*admin.NodeExecutionEventResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NodeExecutionEventRequest) *admin.NodeExecutionEventResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NodeExecutionEventResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NodeExecutionEventRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NodeExecutionInterface_CreateNodeEvent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateNodeEvent' +type NodeExecutionInterface_CreateNodeEvent_Call struct { + *mock.Call +} + +// CreateNodeEvent is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NodeExecutionEventRequest +func (_e *NodeExecutionInterface_Expecter) CreateNodeEvent(ctx interface{}, request interface{}) *NodeExecutionInterface_CreateNodeEvent_Call { + return &NodeExecutionInterface_CreateNodeEvent_Call{Call: _e.mock.On("CreateNodeEvent", ctx, request)} +} + +func (_c *NodeExecutionInterface_CreateNodeEvent_Call) Run(run func(ctx context.Context, request *admin.NodeExecutionEventRequest)) *NodeExecutionInterface_CreateNodeEvent_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NodeExecutionEventRequest)) + }) + return _c +} + +func (_c *NodeExecutionInterface_CreateNodeEvent_Call) Return(_a0 *admin.NodeExecutionEventResponse, _a1 error) *NodeExecutionInterface_CreateNodeEvent_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NodeExecutionInterface_CreateNodeEvent_Call) RunAndReturn(run func(context.Context, *admin.NodeExecutionEventRequest) (*admin.NodeExecutionEventResponse, error)) *NodeExecutionInterface_CreateNodeEvent_Call { + _c.Call.Return(run) + return _c +} + +// GetDynamicNodeWorkflow provides a mock function with given fields: ctx, request +func (_m *NodeExecutionInterface) GetDynamicNodeWorkflow(ctx context.Context, request *admin.GetDynamicNodeWorkflowRequest) (*admin.DynamicNodeWorkflowResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetDynamicNodeWorkflow") + } + + var r0 *admin.DynamicNodeWorkflowResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.GetDynamicNodeWorkflowRequest) (*admin.DynamicNodeWorkflowResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.GetDynamicNodeWorkflowRequest) *admin.DynamicNodeWorkflowResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.DynamicNodeWorkflowResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.GetDynamicNodeWorkflowRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NodeExecutionInterface_GetDynamicNodeWorkflow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDynamicNodeWorkflow' +type NodeExecutionInterface_GetDynamicNodeWorkflow_Call struct { + *mock.Call +} + +// GetDynamicNodeWorkflow is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.GetDynamicNodeWorkflowRequest +func (_e *NodeExecutionInterface_Expecter) GetDynamicNodeWorkflow(ctx interface{}, request interface{}) *NodeExecutionInterface_GetDynamicNodeWorkflow_Call { + return &NodeExecutionInterface_GetDynamicNodeWorkflow_Call{Call: _e.mock.On("GetDynamicNodeWorkflow", ctx, request)} +} + +func (_c *NodeExecutionInterface_GetDynamicNodeWorkflow_Call) Run(run func(ctx context.Context, request *admin.GetDynamicNodeWorkflowRequest)) *NodeExecutionInterface_GetDynamicNodeWorkflow_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.GetDynamicNodeWorkflowRequest)) + }) + return _c +} + +func (_c *NodeExecutionInterface_GetDynamicNodeWorkflow_Call) Return(_a0 *admin.DynamicNodeWorkflowResponse, _a1 error) *NodeExecutionInterface_GetDynamicNodeWorkflow_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NodeExecutionInterface_GetDynamicNodeWorkflow_Call) RunAndReturn(run func(context.Context, *admin.GetDynamicNodeWorkflowRequest) (*admin.DynamicNodeWorkflowResponse, error)) *NodeExecutionInterface_GetDynamicNodeWorkflow_Call { + _c.Call.Return(run) + return _c +} + +// GetNodeExecution provides a mock function with given fields: ctx, request +func (_m *NodeExecutionInterface) GetNodeExecution(ctx context.Context, request *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetNodeExecution") + } + + var r0 *admin.NodeExecution + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NodeExecutionGetRequest) *admin.NodeExecution); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NodeExecution) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NodeExecutionGetRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NodeExecutionInterface_GetNodeExecution_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNodeExecution' +type NodeExecutionInterface_GetNodeExecution_Call struct { + *mock.Call +} + +// GetNodeExecution is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NodeExecutionGetRequest +func (_e *NodeExecutionInterface_Expecter) GetNodeExecution(ctx interface{}, request interface{}) *NodeExecutionInterface_GetNodeExecution_Call { + return &NodeExecutionInterface_GetNodeExecution_Call{Call: _e.mock.On("GetNodeExecution", ctx, request)} +} + +func (_c *NodeExecutionInterface_GetNodeExecution_Call) Run(run func(ctx context.Context, request *admin.NodeExecutionGetRequest)) *NodeExecutionInterface_GetNodeExecution_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NodeExecutionGetRequest)) + }) + return _c +} + +func (_c *NodeExecutionInterface_GetNodeExecution_Call) Return(_a0 *admin.NodeExecution, _a1 error) *NodeExecutionInterface_GetNodeExecution_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NodeExecutionInterface_GetNodeExecution_Call) RunAndReturn(run func(context.Context, *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error)) *NodeExecutionInterface_GetNodeExecution_Call { + _c.Call.Return(run) + return _c +} + +// GetNodeExecutionData provides a mock function with given fields: ctx, request +func (_m *NodeExecutionInterface) GetNodeExecutionData(ctx context.Context, request *admin.NodeExecutionGetDataRequest) (*admin.NodeExecutionGetDataResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetNodeExecutionData") + } + + var r0 *admin.NodeExecutionGetDataResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NodeExecutionGetDataRequest) (*admin.NodeExecutionGetDataResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NodeExecutionGetDataRequest) *admin.NodeExecutionGetDataResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NodeExecutionGetDataResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NodeExecutionGetDataRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NodeExecutionInterface_GetNodeExecutionData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNodeExecutionData' +type NodeExecutionInterface_GetNodeExecutionData_Call struct { + *mock.Call +} + +// GetNodeExecutionData is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NodeExecutionGetDataRequest +func (_e *NodeExecutionInterface_Expecter) GetNodeExecutionData(ctx interface{}, request interface{}) *NodeExecutionInterface_GetNodeExecutionData_Call { + return &NodeExecutionInterface_GetNodeExecutionData_Call{Call: _e.mock.On("GetNodeExecutionData", ctx, request)} +} + +func (_c *NodeExecutionInterface_GetNodeExecutionData_Call) Run(run func(ctx context.Context, request *admin.NodeExecutionGetDataRequest)) *NodeExecutionInterface_GetNodeExecutionData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NodeExecutionGetDataRequest)) + }) + return _c +} + +func (_c *NodeExecutionInterface_GetNodeExecutionData_Call) Return(_a0 *admin.NodeExecutionGetDataResponse, _a1 error) *NodeExecutionInterface_GetNodeExecutionData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NodeExecutionInterface_GetNodeExecutionData_Call) RunAndReturn(run func(context.Context, *admin.NodeExecutionGetDataRequest) (*admin.NodeExecutionGetDataResponse, error)) *NodeExecutionInterface_GetNodeExecutionData_Call { + _c.Call.Return(run) + return _c +} + +// ListNodeExecutions provides a mock function with given fields: ctx, request +func (_m *NodeExecutionInterface) ListNodeExecutions(ctx context.Context, request *admin.NodeExecutionListRequest) (*admin.NodeExecutionList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListNodeExecutions") + } + + var r0 *admin.NodeExecutionList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NodeExecutionListRequest) (*admin.NodeExecutionList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NodeExecutionListRequest) *admin.NodeExecutionList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NodeExecutionList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NodeExecutionListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NodeExecutionInterface_ListNodeExecutions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListNodeExecutions' +type NodeExecutionInterface_ListNodeExecutions_Call struct { + *mock.Call +} + +// ListNodeExecutions is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NodeExecutionListRequest +func (_e *NodeExecutionInterface_Expecter) ListNodeExecutions(ctx interface{}, request interface{}) *NodeExecutionInterface_ListNodeExecutions_Call { + return &NodeExecutionInterface_ListNodeExecutions_Call{Call: _e.mock.On("ListNodeExecutions", ctx, request)} +} + +func (_c *NodeExecutionInterface_ListNodeExecutions_Call) Run(run func(ctx context.Context, request *admin.NodeExecutionListRequest)) *NodeExecutionInterface_ListNodeExecutions_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NodeExecutionListRequest)) + }) + return _c +} + +func (_c *NodeExecutionInterface_ListNodeExecutions_Call) Return(_a0 *admin.NodeExecutionList, _a1 error) *NodeExecutionInterface_ListNodeExecutions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NodeExecutionInterface_ListNodeExecutions_Call) RunAndReturn(run func(context.Context, *admin.NodeExecutionListRequest) (*admin.NodeExecutionList, error)) *NodeExecutionInterface_ListNodeExecutions_Call { + _c.Call.Return(run) + return _c +} + +// ListNodeExecutionsForTask provides a mock function with given fields: ctx, request +func (_m *NodeExecutionInterface) ListNodeExecutionsForTask(ctx context.Context, request *admin.NodeExecutionForTaskListRequest) (*admin.NodeExecutionList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListNodeExecutionsForTask") + } + + var r0 *admin.NodeExecutionList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NodeExecutionForTaskListRequest) (*admin.NodeExecutionList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NodeExecutionForTaskListRequest) *admin.NodeExecutionList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NodeExecutionList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NodeExecutionForTaskListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NodeExecutionInterface_ListNodeExecutionsForTask_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListNodeExecutionsForTask' +type NodeExecutionInterface_ListNodeExecutionsForTask_Call struct { + *mock.Call +} + +// ListNodeExecutionsForTask is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NodeExecutionForTaskListRequest +func (_e *NodeExecutionInterface_Expecter) ListNodeExecutionsForTask(ctx interface{}, request interface{}) *NodeExecutionInterface_ListNodeExecutionsForTask_Call { + return &NodeExecutionInterface_ListNodeExecutionsForTask_Call{Call: _e.mock.On("ListNodeExecutionsForTask", ctx, request)} +} + +func (_c *NodeExecutionInterface_ListNodeExecutionsForTask_Call) Run(run func(ctx context.Context, request *admin.NodeExecutionForTaskListRequest)) *NodeExecutionInterface_ListNodeExecutionsForTask_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NodeExecutionForTaskListRequest)) + }) + return _c +} + +func (_c *NodeExecutionInterface_ListNodeExecutionsForTask_Call) Return(_a0 *admin.NodeExecutionList, _a1 error) *NodeExecutionInterface_ListNodeExecutionsForTask_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *NodeExecutionInterface_ListNodeExecutionsForTask_Call) RunAndReturn(run func(context.Context, *admin.NodeExecutionForTaskListRequest) (*admin.NodeExecutionList, error)) *NodeExecutionInterface_ListNodeExecutionsForTask_Call { + _c.Call.Return(run) + return _c +} + +// NewNodeExecutionInterface creates a new instance of NodeExecutionInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewNodeExecutionInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *NodeExecutionInterface { + mock := &NodeExecutionInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/flyteadmin/pkg/manager/mocks/project.go b/flyteadmin/pkg/manager/mocks/project.go deleted file mode 100644 index f98dc0d6a9..0000000000 --- a/flyteadmin/pkg/manager/mocks/project.go +++ /dev/null @@ -1,69 +0,0 @@ -package mocks - -import ( - "context" - - "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" -) - -type CreateProjectFunc func(ctx context.Context, request *admin.ProjectRegisterRequest) (*admin.ProjectRegisterResponse, error) -type ListProjectFunc func(ctx context.Context, request *admin.ProjectListRequest) (*admin.Projects, error) -type UpdateProjectFunc func(ctx context.Context, request *admin.Project) (*admin.ProjectUpdateResponse, error) -type GetProjectFunc func(ctx context.Context, request *admin.ProjectGetRequest) (*admin.Project, error) -type GetDomainsFunc func(ctx context.Context, request *admin.GetDomainRequest) *admin.GetDomainsResponse - -type MockProjectManager struct { - listProjectFunc ListProjectFunc - createProjectFunc CreateProjectFunc - updateProjectFunc UpdateProjectFunc - getProjectFunc GetProjectFunc - getDomainsFunc GetDomainsFunc -} - -func (m *MockProjectManager) SetCreateProject(createProjectFunc CreateProjectFunc) { - m.createProjectFunc = createProjectFunc -} - -func (m *MockProjectManager) CreateProject(ctx context.Context, request *admin.ProjectRegisterRequest) (*admin.ProjectRegisterResponse, error) { - if m.createProjectFunc != nil { - return m.createProjectFunc(ctx, request) - } - return nil, nil -} - -func (m *MockProjectManager) UpdateProject(ctx context.Context, request *admin.Project) (*admin.ProjectUpdateResponse, error) { - if m.updateProjectFunc != nil { - return m.updateProjectFunc(ctx, request) - } - return nil, nil -} - -func (m *MockProjectManager) SetListCallback(listProjectFunc ListProjectFunc) { - m.listProjectFunc = listProjectFunc -} - -func (m *MockProjectManager) ListProjects( - ctx context.Context, request *admin.ProjectListRequest) (*admin.Projects, error) { - if m.listProjectFunc != nil { - return m.listProjectFunc(ctx, request) - } - return nil, nil -} - -func (m *MockProjectManager) SetGetCallBack(getProjectFunc GetProjectFunc) { - m.getProjectFunc = getProjectFunc -} - -func (m *MockProjectManager) GetProject(ctx context.Context, request *admin.ProjectGetRequest) (*admin.Project, error) { - if m.getProjectFunc != nil { - return m.getProjectFunc(ctx, request) - } - return nil, nil -} - -func (m *MockProjectManager) GetDomains(ctx context.Context, request *admin.GetDomainRequest) *admin.GetDomainsResponse { - if m.getDomainsFunc != nil { - return m.getDomainsFunc(ctx, request) - } - return nil -} diff --git a/flyteadmin/pkg/manager/mocks/project_interface.go b/flyteadmin/pkg/manager/mocks/project_interface.go new file mode 100644 index 0000000000..e6322260f8 --- /dev/null +++ b/flyteadmin/pkg/manager/mocks/project_interface.go @@ -0,0 +1,323 @@ +// Code generated by mockery v2.40.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + admin "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" + + mock "github.com/stretchr/testify/mock" +) + +// ProjectInterface is an autogenerated mock type for the ProjectInterface type +type ProjectInterface struct { + mock.Mock +} + +type ProjectInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *ProjectInterface) EXPECT() *ProjectInterface_Expecter { + return &ProjectInterface_Expecter{mock: &_m.Mock} +} + +// CreateProject provides a mock function with given fields: ctx, request +func (_m *ProjectInterface) CreateProject(ctx context.Context, request *admin.ProjectRegisterRequest) (*admin.ProjectRegisterResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for CreateProject") + } + + var r0 *admin.ProjectRegisterResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectRegisterRequest) (*admin.ProjectRegisterResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectRegisterRequest) *admin.ProjectRegisterResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.ProjectRegisterResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ProjectRegisterRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProjectInterface_CreateProject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateProject' +type ProjectInterface_CreateProject_Call struct { + *mock.Call +} + +// CreateProject is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ProjectRegisterRequest +func (_e *ProjectInterface_Expecter) CreateProject(ctx interface{}, request interface{}) *ProjectInterface_CreateProject_Call { + return &ProjectInterface_CreateProject_Call{Call: _e.mock.On("CreateProject", ctx, request)} +} + +func (_c *ProjectInterface_CreateProject_Call) Run(run func(ctx context.Context, request *admin.ProjectRegisterRequest)) *ProjectInterface_CreateProject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ProjectRegisterRequest)) + }) + return _c +} + +func (_c *ProjectInterface_CreateProject_Call) Return(_a0 *admin.ProjectRegisterResponse, _a1 error) *ProjectInterface_CreateProject_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProjectInterface_CreateProject_Call) RunAndReturn(run func(context.Context, *admin.ProjectRegisterRequest) (*admin.ProjectRegisterResponse, error)) *ProjectInterface_CreateProject_Call { + _c.Call.Return(run) + return _c +} + +// GetDomains provides a mock function with given fields: ctx, request +func (_m *ProjectInterface) GetDomains(ctx context.Context, request *admin.GetDomainRequest) *admin.GetDomainsResponse { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetDomains") + } + + var r0 *admin.GetDomainsResponse + if rf, ok := ret.Get(0).(func(context.Context, *admin.GetDomainRequest) *admin.GetDomainsResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.GetDomainsResponse) + } + } + + return r0 +} + +// ProjectInterface_GetDomains_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDomains' +type ProjectInterface_GetDomains_Call struct { + *mock.Call +} + +// GetDomains is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.GetDomainRequest +func (_e *ProjectInterface_Expecter) GetDomains(ctx interface{}, request interface{}) *ProjectInterface_GetDomains_Call { + return &ProjectInterface_GetDomains_Call{Call: _e.mock.On("GetDomains", ctx, request)} +} + +func (_c *ProjectInterface_GetDomains_Call) Run(run func(ctx context.Context, request *admin.GetDomainRequest)) *ProjectInterface_GetDomains_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.GetDomainRequest)) + }) + return _c +} + +func (_c *ProjectInterface_GetDomains_Call) Return(_a0 *admin.GetDomainsResponse) *ProjectInterface_GetDomains_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProjectInterface_GetDomains_Call) RunAndReturn(run func(context.Context, *admin.GetDomainRequest) *admin.GetDomainsResponse) *ProjectInterface_GetDomains_Call { + _c.Call.Return(run) + return _c +} + +// GetProject provides a mock function with given fields: ctx, request +func (_m *ProjectInterface) GetProject(ctx context.Context, request *admin.ProjectGetRequest) (*admin.Project, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetProject") + } + + var r0 *admin.Project + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectGetRequest) (*admin.Project, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectGetRequest) *admin.Project); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.Project) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ProjectGetRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProjectInterface_GetProject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetProject' +type ProjectInterface_GetProject_Call struct { + *mock.Call +} + +// GetProject is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ProjectGetRequest +func (_e *ProjectInterface_Expecter) GetProject(ctx interface{}, request interface{}) *ProjectInterface_GetProject_Call { + return &ProjectInterface_GetProject_Call{Call: _e.mock.On("GetProject", ctx, request)} +} + +func (_c *ProjectInterface_GetProject_Call) Run(run func(ctx context.Context, request *admin.ProjectGetRequest)) *ProjectInterface_GetProject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ProjectGetRequest)) + }) + return _c +} + +func (_c *ProjectInterface_GetProject_Call) Return(_a0 *admin.Project, _a1 error) *ProjectInterface_GetProject_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProjectInterface_GetProject_Call) RunAndReturn(run func(context.Context, *admin.ProjectGetRequest) (*admin.Project, error)) *ProjectInterface_GetProject_Call { + _c.Call.Return(run) + return _c +} + +// ListProjects provides a mock function with given fields: ctx, request +func (_m *ProjectInterface) ListProjects(ctx context.Context, request *admin.ProjectListRequest) (*admin.Projects, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListProjects") + } + + var r0 *admin.Projects + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectListRequest) (*admin.Projects, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectListRequest) *admin.Projects); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.Projects) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ProjectListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProjectInterface_ListProjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListProjects' +type ProjectInterface_ListProjects_Call struct { + *mock.Call +} + +// ListProjects is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ProjectListRequest +func (_e *ProjectInterface_Expecter) ListProjects(ctx interface{}, request interface{}) *ProjectInterface_ListProjects_Call { + return &ProjectInterface_ListProjects_Call{Call: _e.mock.On("ListProjects", ctx, request)} +} + +func (_c *ProjectInterface_ListProjects_Call) Run(run func(ctx context.Context, request *admin.ProjectListRequest)) *ProjectInterface_ListProjects_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ProjectListRequest)) + }) + return _c +} + +func (_c *ProjectInterface_ListProjects_Call) Return(_a0 *admin.Projects, _a1 error) *ProjectInterface_ListProjects_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProjectInterface_ListProjects_Call) RunAndReturn(run func(context.Context, *admin.ProjectListRequest) (*admin.Projects, error)) *ProjectInterface_ListProjects_Call { + _c.Call.Return(run) + return _c +} + +// UpdateProject provides a mock function with given fields: ctx, request +func (_m *ProjectInterface) UpdateProject(ctx context.Context, request *admin.Project) (*admin.ProjectUpdateResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for UpdateProject") + } + + var r0 *admin.ProjectUpdateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.Project) (*admin.ProjectUpdateResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.Project) *admin.ProjectUpdateResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.ProjectUpdateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.Project) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProjectInterface_UpdateProject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateProject' +type ProjectInterface_UpdateProject_Call struct { + *mock.Call +} + +// UpdateProject is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.Project +func (_e *ProjectInterface_Expecter) UpdateProject(ctx interface{}, request interface{}) *ProjectInterface_UpdateProject_Call { + return &ProjectInterface_UpdateProject_Call{Call: _e.mock.On("UpdateProject", ctx, request)} +} + +func (_c *ProjectInterface_UpdateProject_Call) Run(run func(ctx context.Context, request *admin.Project)) *ProjectInterface_UpdateProject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.Project)) + }) + return _c +} + +func (_c *ProjectInterface_UpdateProject_Call) Return(_a0 *admin.ProjectUpdateResponse, _a1 error) *ProjectInterface_UpdateProject_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProjectInterface_UpdateProject_Call) RunAndReturn(run func(context.Context, *admin.Project) (*admin.ProjectUpdateResponse, error)) *ProjectInterface_UpdateProject_Call { + _c.Call.Return(run) + return _c +} + +// NewProjectInterface creates a new instance of ProjectInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewProjectInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *ProjectInterface { + mock := &ProjectInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/flyteadmin/pkg/manager/mocks/resource.go b/flyteadmin/pkg/manager/mocks/resource.go deleted file mode 100644 index df9ef11d79..0000000000 --- a/flyteadmin/pkg/manager/mocks/resource.go +++ /dev/null @@ -1,133 +0,0 @@ -package mocks - -import ( - "context" - - "github.com/flyteorg/flyte/flyteadmin/pkg/manager/interfaces" - "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" -) - -type UpdateProjectAttrsFunc func(ctx context.Context, request *admin.ProjectAttributesUpdateRequest) ( - *admin.ProjectAttributesUpdateResponse, error) -type GetProjectAttrFunc func(ctx context.Context, request *admin.ProjectAttributesGetRequest) ( - *admin.ProjectAttributesGetResponse, error) -type DeleteProjectAttrFunc func(ctx context.Context, request *admin.ProjectAttributesDeleteRequest) ( - *admin.ProjectAttributesDeleteResponse, error) - -type UpdateProjectDomainFunc func(ctx context.Context, request *admin.ProjectDomainAttributesUpdateRequest) ( - *admin.ProjectDomainAttributesUpdateResponse, error) -type GetProjectDomainFunc func(ctx context.Context, request *admin.ProjectDomainAttributesGetRequest) ( - *admin.ProjectDomainAttributesGetResponse, error) -type DeleteProjectDomainFunc func(ctx context.Context, request *admin.ProjectDomainAttributesDeleteRequest) ( - *admin.ProjectDomainAttributesDeleteResponse, error) -type ListResourceFunc func(ctx context.Context, request *admin.ListMatchableAttributesRequest) ( - *admin.ListMatchableAttributesResponse, error) -type GetResourceFunc func(ctx context.Context, request interfaces.ResourceRequest) (*interfaces.ResourceResponse, error) - -type MockResourceManager struct { - updateProjectDomainFunc UpdateProjectDomainFunc - GetFunc GetProjectDomainFunc - DeleteFunc DeleteProjectDomainFunc - ListFunc ListResourceFunc - GetResourceFunc GetResourceFunc - updateProjectAttrsFunc UpdateProjectAttrsFunc - getProjectAttrFunc GetProjectAttrFunc - deleteProjectAttrFunc DeleteProjectAttrFunc -} - -func (m *MockResourceManager) GetResource(ctx context.Context, request interfaces.ResourceRequest) (*interfaces.ResourceResponse, error) { - if m.GetResourceFunc != nil { - return m.GetResourceFunc(ctx, request) - } - return nil, nil -} - -func (m *MockResourceManager) UpdateWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesUpdateRequest) ( - *admin.WorkflowAttributesUpdateResponse, error) { - panic("implement me") -} - -func (m *MockResourceManager) GetWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesGetRequest) ( - *admin.WorkflowAttributesGetResponse, error) { - panic("implement me") -} - -func (m *MockResourceManager) DeleteWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesDeleteRequest) ( - *admin.WorkflowAttributesDeleteResponse, error) { - panic("implement me") -} - -func (m *MockResourceManager) SetUpdateProjectDomainAttributes(updateProjectDomainFunc UpdateProjectDomainFunc) { - m.updateProjectDomainFunc = updateProjectDomainFunc -} - -func (m *MockResourceManager) UpdateProjectDomainAttributes( - ctx context.Context, request *admin.ProjectDomainAttributesUpdateRequest) ( - *admin.ProjectDomainAttributesUpdateResponse, error) { - if m.updateProjectDomainFunc != nil { - return m.updateProjectDomainFunc(ctx, request) - } - return nil, nil -} - -func (m *MockResourceManager) GetProjectDomainAttributes( - ctx context.Context, request *admin.ProjectDomainAttributesGetRequest) ( - *admin.ProjectDomainAttributesGetResponse, error) { - if m.GetFunc != nil { - return m.GetFunc(ctx, request) - } - return nil, nil -} - -func (m *MockResourceManager) DeleteProjectDomainAttributes( - ctx context.Context, request *admin.ProjectDomainAttributesDeleteRequest) ( - *admin.ProjectDomainAttributesDeleteResponse, error) { - if m.DeleteFunc != nil { - return m.DeleteFunc(ctx, request) - } - return nil, nil -} - -func (m *MockResourceManager) SetUpdateProjectAttributes(updateProjectAttrsFunc UpdateProjectAttrsFunc) { - m.updateProjectAttrsFunc = updateProjectAttrsFunc -} - -func (m *MockResourceManager) UpdateProjectAttributes(ctx context.Context, request *admin.ProjectAttributesUpdateRequest) ( - *admin.ProjectAttributesUpdateResponse, error) { - if m.updateProjectAttrsFunc != nil { - return m.updateProjectAttrsFunc(ctx, request) - } - return nil, nil -} - -func (m *MockResourceManager) SetGetProjectAttributes(getProjectFunc GetProjectAttrFunc) { - m.getProjectAttrFunc = getProjectFunc -} - -func (m *MockResourceManager) GetProjectAttributes(ctx context.Context, request *admin.ProjectAttributesGetRequest) ( - *admin.ProjectAttributesGetResponse, error) { - if m.getProjectAttrFunc != nil { - return m.getProjectAttrFunc(ctx, request) - } - return nil, nil -} - -func (m *MockResourceManager) SetDeleteProjectAttributes(deleteProjectFunc DeleteProjectAttrFunc) { - m.deleteProjectAttrFunc = deleteProjectFunc -} - -func (m *MockResourceManager) DeleteProjectAttributes(ctx context.Context, request *admin.ProjectAttributesDeleteRequest) ( - *admin.ProjectAttributesDeleteResponse, error) { - if m.deleteProjectAttrFunc != nil { - return m.deleteProjectAttrFunc(ctx, request) - } - return nil, nil -} - -func (m *MockResourceManager) ListAll(ctx context.Context, request *admin.ListMatchableAttributesRequest) ( - *admin.ListMatchableAttributesResponse, error) { - if m.ListFunc != nil { - return m.ListFunc(ctx, request) - } - return nil, nil -} diff --git a/flyteadmin/pkg/manager/mocks/resource_interface.go b/flyteadmin/pkg/manager/mocks/resource_interface.go index c1b416eb9d..c99378d29f 100644 --- a/flyteadmin/pkg/manager/mocks/resource_interface.go +++ b/flyteadmin/pkg/manager/mocks/resource_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.1. DO NOT EDIT. +// Code generated by mockery v2.40.3. DO NOT EDIT. package mocks @@ -17,29 +17,27 @@ type ResourceInterface struct { mock.Mock } -type ResourceInterface_DeleteProjectAttributes struct { - *mock.Call -} - -func (_m ResourceInterface_DeleteProjectAttributes) Return(_a0 *admin.ProjectAttributesDeleteResponse, _a1 error) *ResourceInterface_DeleteProjectAttributes { - return &ResourceInterface_DeleteProjectAttributes{Call: _m.Call.Return(_a0, _a1)} +type ResourceInterface_Expecter struct { + mock *mock.Mock } -func (_m *ResourceInterface) OnDeleteProjectAttributes(ctx context.Context, request *admin.ProjectAttributesDeleteRequest) *ResourceInterface_DeleteProjectAttributes { - c_call := _m.On("DeleteProjectAttributes", ctx, request) - return &ResourceInterface_DeleteProjectAttributes{Call: c_call} -} - -func (_m *ResourceInterface) OnDeleteProjectAttributesMatch(matchers ...interface{}) *ResourceInterface_DeleteProjectAttributes { - c_call := _m.On("DeleteProjectAttributes", matchers...) - return &ResourceInterface_DeleteProjectAttributes{Call: c_call} +func (_m *ResourceInterface) EXPECT() *ResourceInterface_Expecter { + return &ResourceInterface_Expecter{mock: &_m.Mock} } // DeleteProjectAttributes provides a mock function with given fields: ctx, request func (_m *ResourceInterface) DeleteProjectAttributes(ctx context.Context, request *admin.ProjectAttributesDeleteRequest) (*admin.ProjectAttributesDeleteResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for DeleteProjectAttributes") + } + var r0 *admin.ProjectAttributesDeleteResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectAttributesDeleteRequest) (*admin.ProjectAttributesDeleteResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectAttributesDeleteRequest) *admin.ProjectAttributesDeleteResponse); ok { r0 = rf(ctx, request) } else { @@ -48,7 +46,6 @@ func (_m *ResourceInterface) DeleteProjectAttributes(ctx context.Context, reques } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.ProjectAttributesDeleteRequest) error); ok { r1 = rf(ctx, request) } else { @@ -58,29 +55,48 @@ func (_m *ResourceInterface) DeleteProjectAttributes(ctx context.Context, reques return r0, r1 } -type ResourceInterface_DeleteProjectDomainAttributes struct { +// ResourceInterface_DeleteProjectAttributes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteProjectAttributes' +type ResourceInterface_DeleteProjectAttributes_Call struct { *mock.Call } -func (_m ResourceInterface_DeleteProjectDomainAttributes) Return(_a0 *admin.ProjectDomainAttributesDeleteResponse, _a1 error) *ResourceInterface_DeleteProjectDomainAttributes { - return &ResourceInterface_DeleteProjectDomainAttributes{Call: _m.Call.Return(_a0, _a1)} +// DeleteProjectAttributes is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ProjectAttributesDeleteRequest +func (_e *ResourceInterface_Expecter) DeleteProjectAttributes(ctx interface{}, request interface{}) *ResourceInterface_DeleteProjectAttributes_Call { + return &ResourceInterface_DeleteProjectAttributes_Call{Call: _e.mock.On("DeleteProjectAttributes", ctx, request)} +} + +func (_c *ResourceInterface_DeleteProjectAttributes_Call) Run(run func(ctx context.Context, request *admin.ProjectAttributesDeleteRequest)) *ResourceInterface_DeleteProjectAttributes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ProjectAttributesDeleteRequest)) + }) + return _c } -func (_m *ResourceInterface) OnDeleteProjectDomainAttributes(ctx context.Context, request *admin.ProjectDomainAttributesDeleteRequest) *ResourceInterface_DeleteProjectDomainAttributes { - c_call := _m.On("DeleteProjectDomainAttributes", ctx, request) - return &ResourceInterface_DeleteProjectDomainAttributes{Call: c_call} +func (_c *ResourceInterface_DeleteProjectAttributes_Call) Return(_a0 *admin.ProjectAttributesDeleteResponse, _a1 error) *ResourceInterface_DeleteProjectAttributes_Call { + _c.Call.Return(_a0, _a1) + return _c } -func (_m *ResourceInterface) OnDeleteProjectDomainAttributesMatch(matchers ...interface{}) *ResourceInterface_DeleteProjectDomainAttributes { - c_call := _m.On("DeleteProjectDomainAttributes", matchers...) - return &ResourceInterface_DeleteProjectDomainAttributes{Call: c_call} +func (_c *ResourceInterface_DeleteProjectAttributes_Call) RunAndReturn(run func(context.Context, *admin.ProjectAttributesDeleteRequest) (*admin.ProjectAttributesDeleteResponse, error)) *ResourceInterface_DeleteProjectAttributes_Call { + _c.Call.Return(run) + return _c } // DeleteProjectDomainAttributes provides a mock function with given fields: ctx, request func (_m *ResourceInterface) DeleteProjectDomainAttributes(ctx context.Context, request *admin.ProjectDomainAttributesDeleteRequest) (*admin.ProjectDomainAttributesDeleteResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for DeleteProjectDomainAttributes") + } + var r0 *admin.ProjectDomainAttributesDeleteResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectDomainAttributesDeleteRequest) (*admin.ProjectDomainAttributesDeleteResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectDomainAttributesDeleteRequest) *admin.ProjectDomainAttributesDeleteResponse); ok { r0 = rf(ctx, request) } else { @@ -89,7 +105,6 @@ func (_m *ResourceInterface) DeleteProjectDomainAttributes(ctx context.Context, } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.ProjectDomainAttributesDeleteRequest) error); ok { r1 = rf(ctx, request) } else { @@ -99,29 +114,48 @@ func (_m *ResourceInterface) DeleteProjectDomainAttributes(ctx context.Context, return r0, r1 } -type ResourceInterface_DeleteWorkflowAttributes struct { +// ResourceInterface_DeleteProjectDomainAttributes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteProjectDomainAttributes' +type ResourceInterface_DeleteProjectDomainAttributes_Call struct { *mock.Call } -func (_m ResourceInterface_DeleteWorkflowAttributes) Return(_a0 *admin.WorkflowAttributesDeleteResponse, _a1 error) *ResourceInterface_DeleteWorkflowAttributes { - return &ResourceInterface_DeleteWorkflowAttributes{Call: _m.Call.Return(_a0, _a1)} +// DeleteProjectDomainAttributes is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ProjectDomainAttributesDeleteRequest +func (_e *ResourceInterface_Expecter) DeleteProjectDomainAttributes(ctx interface{}, request interface{}) *ResourceInterface_DeleteProjectDomainAttributes_Call { + return &ResourceInterface_DeleteProjectDomainAttributes_Call{Call: _e.mock.On("DeleteProjectDomainAttributes", ctx, request)} +} + +func (_c *ResourceInterface_DeleteProjectDomainAttributes_Call) Run(run func(ctx context.Context, request *admin.ProjectDomainAttributesDeleteRequest)) *ResourceInterface_DeleteProjectDomainAttributes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ProjectDomainAttributesDeleteRequest)) + }) + return _c } -func (_m *ResourceInterface) OnDeleteWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesDeleteRequest) *ResourceInterface_DeleteWorkflowAttributes { - c_call := _m.On("DeleteWorkflowAttributes", ctx, request) - return &ResourceInterface_DeleteWorkflowAttributes{Call: c_call} +func (_c *ResourceInterface_DeleteProjectDomainAttributes_Call) Return(_a0 *admin.ProjectDomainAttributesDeleteResponse, _a1 error) *ResourceInterface_DeleteProjectDomainAttributes_Call { + _c.Call.Return(_a0, _a1) + return _c } -func (_m *ResourceInterface) OnDeleteWorkflowAttributesMatch(matchers ...interface{}) *ResourceInterface_DeleteWorkflowAttributes { - c_call := _m.On("DeleteWorkflowAttributes", matchers...) - return &ResourceInterface_DeleteWorkflowAttributes{Call: c_call} +func (_c *ResourceInterface_DeleteProjectDomainAttributes_Call) RunAndReturn(run func(context.Context, *admin.ProjectDomainAttributesDeleteRequest) (*admin.ProjectDomainAttributesDeleteResponse, error)) *ResourceInterface_DeleteProjectDomainAttributes_Call { + _c.Call.Return(run) + return _c } // DeleteWorkflowAttributes provides a mock function with given fields: ctx, request func (_m *ResourceInterface) DeleteWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesDeleteRequest) (*admin.WorkflowAttributesDeleteResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for DeleteWorkflowAttributes") + } + var r0 *admin.WorkflowAttributesDeleteResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowAttributesDeleteRequest) (*admin.WorkflowAttributesDeleteResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowAttributesDeleteRequest) *admin.WorkflowAttributesDeleteResponse); ok { r0 = rf(ctx, request) } else { @@ -130,7 +164,6 @@ func (_m *ResourceInterface) DeleteWorkflowAttributes(ctx context.Context, reque } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.WorkflowAttributesDeleteRequest) error); ok { r1 = rf(ctx, request) } else { @@ -140,29 +173,48 @@ func (_m *ResourceInterface) DeleteWorkflowAttributes(ctx context.Context, reque return r0, r1 } -type ResourceInterface_GetProjectAttributes struct { +// ResourceInterface_DeleteWorkflowAttributes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteWorkflowAttributes' +type ResourceInterface_DeleteWorkflowAttributes_Call struct { *mock.Call } -func (_m ResourceInterface_GetProjectAttributes) Return(_a0 *admin.ProjectAttributesGetResponse, _a1 error) *ResourceInterface_GetProjectAttributes { - return &ResourceInterface_GetProjectAttributes{Call: _m.Call.Return(_a0, _a1)} +// DeleteWorkflowAttributes is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.WorkflowAttributesDeleteRequest +func (_e *ResourceInterface_Expecter) DeleteWorkflowAttributes(ctx interface{}, request interface{}) *ResourceInterface_DeleteWorkflowAttributes_Call { + return &ResourceInterface_DeleteWorkflowAttributes_Call{Call: _e.mock.On("DeleteWorkflowAttributes", ctx, request)} } -func (_m *ResourceInterface) OnGetProjectAttributes(ctx context.Context, request *admin.ProjectAttributesGetRequest) *ResourceInterface_GetProjectAttributes { - c_call := _m.On("GetProjectAttributes", ctx, request) - return &ResourceInterface_GetProjectAttributes{Call: c_call} +func (_c *ResourceInterface_DeleteWorkflowAttributes_Call) Run(run func(ctx context.Context, request *admin.WorkflowAttributesDeleteRequest)) *ResourceInterface_DeleteWorkflowAttributes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.WorkflowAttributesDeleteRequest)) + }) + return _c } -func (_m *ResourceInterface) OnGetProjectAttributesMatch(matchers ...interface{}) *ResourceInterface_GetProjectAttributes { - c_call := _m.On("GetProjectAttributes", matchers...) - return &ResourceInterface_GetProjectAttributes{Call: c_call} +func (_c *ResourceInterface_DeleteWorkflowAttributes_Call) Return(_a0 *admin.WorkflowAttributesDeleteResponse, _a1 error) *ResourceInterface_DeleteWorkflowAttributes_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ResourceInterface_DeleteWorkflowAttributes_Call) RunAndReturn(run func(context.Context, *admin.WorkflowAttributesDeleteRequest) (*admin.WorkflowAttributesDeleteResponse, error)) *ResourceInterface_DeleteWorkflowAttributes_Call { + _c.Call.Return(run) + return _c } // GetProjectAttributes provides a mock function with given fields: ctx, request func (_m *ResourceInterface) GetProjectAttributes(ctx context.Context, request *admin.ProjectAttributesGetRequest) (*admin.ProjectAttributesGetResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for GetProjectAttributes") + } + var r0 *admin.ProjectAttributesGetResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectAttributesGetRequest) (*admin.ProjectAttributesGetResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectAttributesGetRequest) *admin.ProjectAttributesGetResponse); ok { r0 = rf(ctx, request) } else { @@ -171,7 +223,6 @@ func (_m *ResourceInterface) GetProjectAttributes(ctx context.Context, request * } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.ProjectAttributesGetRequest) error); ok { r1 = rf(ctx, request) } else { @@ -181,29 +232,48 @@ func (_m *ResourceInterface) GetProjectAttributes(ctx context.Context, request * return r0, r1 } -type ResourceInterface_GetProjectDomainAttributes struct { +// ResourceInterface_GetProjectAttributes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetProjectAttributes' +type ResourceInterface_GetProjectAttributes_Call struct { *mock.Call } -func (_m ResourceInterface_GetProjectDomainAttributes) Return(_a0 *admin.ProjectDomainAttributesGetResponse, _a1 error) *ResourceInterface_GetProjectDomainAttributes { - return &ResourceInterface_GetProjectDomainAttributes{Call: _m.Call.Return(_a0, _a1)} +// GetProjectAttributes is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ProjectAttributesGetRequest +func (_e *ResourceInterface_Expecter) GetProjectAttributes(ctx interface{}, request interface{}) *ResourceInterface_GetProjectAttributes_Call { + return &ResourceInterface_GetProjectAttributes_Call{Call: _e.mock.On("GetProjectAttributes", ctx, request)} +} + +func (_c *ResourceInterface_GetProjectAttributes_Call) Run(run func(ctx context.Context, request *admin.ProjectAttributesGetRequest)) *ResourceInterface_GetProjectAttributes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ProjectAttributesGetRequest)) + }) + return _c } -func (_m *ResourceInterface) OnGetProjectDomainAttributes(ctx context.Context, request *admin.ProjectDomainAttributesGetRequest) *ResourceInterface_GetProjectDomainAttributes { - c_call := _m.On("GetProjectDomainAttributes", ctx, request) - return &ResourceInterface_GetProjectDomainAttributes{Call: c_call} +func (_c *ResourceInterface_GetProjectAttributes_Call) Return(_a0 *admin.ProjectAttributesGetResponse, _a1 error) *ResourceInterface_GetProjectAttributes_Call { + _c.Call.Return(_a0, _a1) + return _c } -func (_m *ResourceInterface) OnGetProjectDomainAttributesMatch(matchers ...interface{}) *ResourceInterface_GetProjectDomainAttributes { - c_call := _m.On("GetProjectDomainAttributes", matchers...) - return &ResourceInterface_GetProjectDomainAttributes{Call: c_call} +func (_c *ResourceInterface_GetProjectAttributes_Call) RunAndReturn(run func(context.Context, *admin.ProjectAttributesGetRequest) (*admin.ProjectAttributesGetResponse, error)) *ResourceInterface_GetProjectAttributes_Call { + _c.Call.Return(run) + return _c } // GetProjectDomainAttributes provides a mock function with given fields: ctx, request func (_m *ResourceInterface) GetProjectDomainAttributes(ctx context.Context, request *admin.ProjectDomainAttributesGetRequest) (*admin.ProjectDomainAttributesGetResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for GetProjectDomainAttributes") + } + var r0 *admin.ProjectDomainAttributesGetResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectDomainAttributesGetRequest) (*admin.ProjectDomainAttributesGetResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectDomainAttributesGetRequest) *admin.ProjectDomainAttributesGetResponse); ok { r0 = rf(ctx, request) } else { @@ -212,7 +282,6 @@ func (_m *ResourceInterface) GetProjectDomainAttributes(ctx context.Context, req } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.ProjectDomainAttributesGetRequest) error); ok { r1 = rf(ctx, request) } else { @@ -222,29 +291,48 @@ func (_m *ResourceInterface) GetProjectDomainAttributes(ctx context.Context, req return r0, r1 } -type ResourceInterface_GetResource struct { +// ResourceInterface_GetProjectDomainAttributes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetProjectDomainAttributes' +type ResourceInterface_GetProjectDomainAttributes_Call struct { *mock.Call } -func (_m ResourceInterface_GetResource) Return(_a0 *interfaces.ResourceResponse, _a1 error) *ResourceInterface_GetResource { - return &ResourceInterface_GetResource{Call: _m.Call.Return(_a0, _a1)} +// GetProjectDomainAttributes is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ProjectDomainAttributesGetRequest +func (_e *ResourceInterface_Expecter) GetProjectDomainAttributes(ctx interface{}, request interface{}) *ResourceInterface_GetProjectDomainAttributes_Call { + return &ResourceInterface_GetProjectDomainAttributes_Call{Call: _e.mock.On("GetProjectDomainAttributes", ctx, request)} +} + +func (_c *ResourceInterface_GetProjectDomainAttributes_Call) Run(run func(ctx context.Context, request *admin.ProjectDomainAttributesGetRequest)) *ResourceInterface_GetProjectDomainAttributes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ProjectDomainAttributesGetRequest)) + }) + return _c } -func (_m *ResourceInterface) OnGetResource(ctx context.Context, request interfaces.ResourceRequest) *ResourceInterface_GetResource { - c_call := _m.On("GetResource", ctx, request) - return &ResourceInterface_GetResource{Call: c_call} +func (_c *ResourceInterface_GetProjectDomainAttributes_Call) Return(_a0 *admin.ProjectDomainAttributesGetResponse, _a1 error) *ResourceInterface_GetProjectDomainAttributes_Call { + _c.Call.Return(_a0, _a1) + return _c } -func (_m *ResourceInterface) OnGetResourceMatch(matchers ...interface{}) *ResourceInterface_GetResource { - c_call := _m.On("GetResource", matchers...) - return &ResourceInterface_GetResource{Call: c_call} +func (_c *ResourceInterface_GetProjectDomainAttributes_Call) RunAndReturn(run func(context.Context, *admin.ProjectDomainAttributesGetRequest) (*admin.ProjectDomainAttributesGetResponse, error)) *ResourceInterface_GetProjectDomainAttributes_Call { + _c.Call.Return(run) + return _c } // GetResource provides a mock function with given fields: ctx, request func (_m *ResourceInterface) GetResource(ctx context.Context, request interfaces.ResourceRequest) (*interfaces.ResourceResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for GetResource") + } + var r0 *interfaces.ResourceResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, interfaces.ResourceRequest) (*interfaces.ResourceResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, interfaces.ResourceRequest) *interfaces.ResourceResponse); ok { r0 = rf(ctx, request) } else { @@ -253,7 +341,6 @@ func (_m *ResourceInterface) GetResource(ctx context.Context, request interfaces } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, interfaces.ResourceRequest) error); ok { r1 = rf(ctx, request) } else { @@ -263,29 +350,48 @@ func (_m *ResourceInterface) GetResource(ctx context.Context, request interfaces return r0, r1 } -type ResourceInterface_GetWorkflowAttributes struct { +// ResourceInterface_GetResource_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetResource' +type ResourceInterface_GetResource_Call struct { *mock.Call } -func (_m ResourceInterface_GetWorkflowAttributes) Return(_a0 *admin.WorkflowAttributesGetResponse, _a1 error) *ResourceInterface_GetWorkflowAttributes { - return &ResourceInterface_GetWorkflowAttributes{Call: _m.Call.Return(_a0, _a1)} +// GetResource is a helper method to define mock.On call +// - ctx context.Context +// - request interfaces.ResourceRequest +func (_e *ResourceInterface_Expecter) GetResource(ctx interface{}, request interface{}) *ResourceInterface_GetResource_Call { + return &ResourceInterface_GetResource_Call{Call: _e.mock.On("GetResource", ctx, request)} } -func (_m *ResourceInterface) OnGetWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesGetRequest) *ResourceInterface_GetWorkflowAttributes { - c_call := _m.On("GetWorkflowAttributes", ctx, request) - return &ResourceInterface_GetWorkflowAttributes{Call: c_call} +func (_c *ResourceInterface_GetResource_Call) Run(run func(ctx context.Context, request interfaces.ResourceRequest)) *ResourceInterface_GetResource_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(interfaces.ResourceRequest)) + }) + return _c } -func (_m *ResourceInterface) OnGetWorkflowAttributesMatch(matchers ...interface{}) *ResourceInterface_GetWorkflowAttributes { - c_call := _m.On("GetWorkflowAttributes", matchers...) - return &ResourceInterface_GetWorkflowAttributes{Call: c_call} +func (_c *ResourceInterface_GetResource_Call) Return(_a0 *interfaces.ResourceResponse, _a1 error) *ResourceInterface_GetResource_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ResourceInterface_GetResource_Call) RunAndReturn(run func(context.Context, interfaces.ResourceRequest) (*interfaces.ResourceResponse, error)) *ResourceInterface_GetResource_Call { + _c.Call.Return(run) + return _c } // GetWorkflowAttributes provides a mock function with given fields: ctx, request func (_m *ResourceInterface) GetWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesGetRequest) (*admin.WorkflowAttributesGetResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for GetWorkflowAttributes") + } + var r0 *admin.WorkflowAttributesGetResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowAttributesGetRequest) (*admin.WorkflowAttributesGetResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowAttributesGetRequest) *admin.WorkflowAttributesGetResponse); ok { r0 = rf(ctx, request) } else { @@ -294,7 +400,6 @@ func (_m *ResourceInterface) GetWorkflowAttributes(ctx context.Context, request } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.WorkflowAttributesGetRequest) error); ok { r1 = rf(ctx, request) } else { @@ -304,29 +409,48 @@ func (_m *ResourceInterface) GetWorkflowAttributes(ctx context.Context, request return r0, r1 } -type ResourceInterface_ListAll struct { +// ResourceInterface_GetWorkflowAttributes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetWorkflowAttributes' +type ResourceInterface_GetWorkflowAttributes_Call struct { *mock.Call } -func (_m ResourceInterface_ListAll) Return(_a0 *admin.ListMatchableAttributesResponse, _a1 error) *ResourceInterface_ListAll { - return &ResourceInterface_ListAll{Call: _m.Call.Return(_a0, _a1)} +// GetWorkflowAttributes is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.WorkflowAttributesGetRequest +func (_e *ResourceInterface_Expecter) GetWorkflowAttributes(ctx interface{}, request interface{}) *ResourceInterface_GetWorkflowAttributes_Call { + return &ResourceInterface_GetWorkflowAttributes_Call{Call: _e.mock.On("GetWorkflowAttributes", ctx, request)} +} + +func (_c *ResourceInterface_GetWorkflowAttributes_Call) Run(run func(ctx context.Context, request *admin.WorkflowAttributesGetRequest)) *ResourceInterface_GetWorkflowAttributes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.WorkflowAttributesGetRequest)) + }) + return _c } -func (_m *ResourceInterface) OnListAll(ctx context.Context, request *admin.ListMatchableAttributesRequest) *ResourceInterface_ListAll { - c_call := _m.On("ListAll", ctx, request) - return &ResourceInterface_ListAll{Call: c_call} +func (_c *ResourceInterface_GetWorkflowAttributes_Call) Return(_a0 *admin.WorkflowAttributesGetResponse, _a1 error) *ResourceInterface_GetWorkflowAttributes_Call { + _c.Call.Return(_a0, _a1) + return _c } -func (_m *ResourceInterface) OnListAllMatch(matchers ...interface{}) *ResourceInterface_ListAll { - c_call := _m.On("ListAll", matchers...) - return &ResourceInterface_ListAll{Call: c_call} +func (_c *ResourceInterface_GetWorkflowAttributes_Call) RunAndReturn(run func(context.Context, *admin.WorkflowAttributesGetRequest) (*admin.WorkflowAttributesGetResponse, error)) *ResourceInterface_GetWorkflowAttributes_Call { + _c.Call.Return(run) + return _c } // ListAll provides a mock function with given fields: ctx, request func (_m *ResourceInterface) ListAll(ctx context.Context, request *admin.ListMatchableAttributesRequest) (*admin.ListMatchableAttributesResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for ListAll") + } + var r0 *admin.ListMatchableAttributesResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ListMatchableAttributesRequest) (*admin.ListMatchableAttributesResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.ListMatchableAttributesRequest) *admin.ListMatchableAttributesResponse); ok { r0 = rf(ctx, request) } else { @@ -335,7 +459,6 @@ func (_m *ResourceInterface) ListAll(ctx context.Context, request *admin.ListMat } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.ListMatchableAttributesRequest) error); ok { r1 = rf(ctx, request) } else { @@ -345,29 +468,48 @@ func (_m *ResourceInterface) ListAll(ctx context.Context, request *admin.ListMat return r0, r1 } -type ResourceInterface_UpdateProjectAttributes struct { +// ResourceInterface_ListAll_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAll' +type ResourceInterface_ListAll_Call struct { *mock.Call } -func (_m ResourceInterface_UpdateProjectAttributes) Return(_a0 *admin.ProjectAttributesUpdateResponse, _a1 error) *ResourceInterface_UpdateProjectAttributes { - return &ResourceInterface_UpdateProjectAttributes{Call: _m.Call.Return(_a0, _a1)} +// ListAll is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ListMatchableAttributesRequest +func (_e *ResourceInterface_Expecter) ListAll(ctx interface{}, request interface{}) *ResourceInterface_ListAll_Call { + return &ResourceInterface_ListAll_Call{Call: _e.mock.On("ListAll", ctx, request)} +} + +func (_c *ResourceInterface_ListAll_Call) Run(run func(ctx context.Context, request *admin.ListMatchableAttributesRequest)) *ResourceInterface_ListAll_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ListMatchableAttributesRequest)) + }) + return _c } -func (_m *ResourceInterface) OnUpdateProjectAttributes(ctx context.Context, request *admin.ProjectAttributesUpdateRequest) *ResourceInterface_UpdateProjectAttributes { - c_call := _m.On("UpdateProjectAttributes", ctx, request) - return &ResourceInterface_UpdateProjectAttributes{Call: c_call} +func (_c *ResourceInterface_ListAll_Call) Return(_a0 *admin.ListMatchableAttributesResponse, _a1 error) *ResourceInterface_ListAll_Call { + _c.Call.Return(_a0, _a1) + return _c } -func (_m *ResourceInterface) OnUpdateProjectAttributesMatch(matchers ...interface{}) *ResourceInterface_UpdateProjectAttributes { - c_call := _m.On("UpdateProjectAttributes", matchers...) - return &ResourceInterface_UpdateProjectAttributes{Call: c_call} +func (_c *ResourceInterface_ListAll_Call) RunAndReturn(run func(context.Context, *admin.ListMatchableAttributesRequest) (*admin.ListMatchableAttributesResponse, error)) *ResourceInterface_ListAll_Call { + _c.Call.Return(run) + return _c } // UpdateProjectAttributes provides a mock function with given fields: ctx, request func (_m *ResourceInterface) UpdateProjectAttributes(ctx context.Context, request *admin.ProjectAttributesUpdateRequest) (*admin.ProjectAttributesUpdateResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for UpdateProjectAttributes") + } + var r0 *admin.ProjectAttributesUpdateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectAttributesUpdateRequest) (*admin.ProjectAttributesUpdateResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectAttributesUpdateRequest) *admin.ProjectAttributesUpdateResponse); ok { r0 = rf(ctx, request) } else { @@ -376,7 +518,6 @@ func (_m *ResourceInterface) UpdateProjectAttributes(ctx context.Context, reques } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.ProjectAttributesUpdateRequest) error); ok { r1 = rf(ctx, request) } else { @@ -386,29 +527,48 @@ func (_m *ResourceInterface) UpdateProjectAttributes(ctx context.Context, reques return r0, r1 } -type ResourceInterface_UpdateProjectDomainAttributes struct { +// ResourceInterface_UpdateProjectAttributes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateProjectAttributes' +type ResourceInterface_UpdateProjectAttributes_Call struct { *mock.Call } -func (_m ResourceInterface_UpdateProjectDomainAttributes) Return(_a0 *admin.ProjectDomainAttributesUpdateResponse, _a1 error) *ResourceInterface_UpdateProjectDomainAttributes { - return &ResourceInterface_UpdateProjectDomainAttributes{Call: _m.Call.Return(_a0, _a1)} +// UpdateProjectAttributes is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ProjectAttributesUpdateRequest +func (_e *ResourceInterface_Expecter) UpdateProjectAttributes(ctx interface{}, request interface{}) *ResourceInterface_UpdateProjectAttributes_Call { + return &ResourceInterface_UpdateProjectAttributes_Call{Call: _e.mock.On("UpdateProjectAttributes", ctx, request)} } -func (_m *ResourceInterface) OnUpdateProjectDomainAttributes(ctx context.Context, request *admin.ProjectDomainAttributesUpdateRequest) *ResourceInterface_UpdateProjectDomainAttributes { - c_call := _m.On("UpdateProjectDomainAttributes", ctx, request) - return &ResourceInterface_UpdateProjectDomainAttributes{Call: c_call} +func (_c *ResourceInterface_UpdateProjectAttributes_Call) Run(run func(ctx context.Context, request *admin.ProjectAttributesUpdateRequest)) *ResourceInterface_UpdateProjectAttributes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ProjectAttributesUpdateRequest)) + }) + return _c } -func (_m *ResourceInterface) OnUpdateProjectDomainAttributesMatch(matchers ...interface{}) *ResourceInterface_UpdateProjectDomainAttributes { - c_call := _m.On("UpdateProjectDomainAttributes", matchers...) - return &ResourceInterface_UpdateProjectDomainAttributes{Call: c_call} +func (_c *ResourceInterface_UpdateProjectAttributes_Call) Return(_a0 *admin.ProjectAttributesUpdateResponse, _a1 error) *ResourceInterface_UpdateProjectAttributes_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ResourceInterface_UpdateProjectAttributes_Call) RunAndReturn(run func(context.Context, *admin.ProjectAttributesUpdateRequest) (*admin.ProjectAttributesUpdateResponse, error)) *ResourceInterface_UpdateProjectAttributes_Call { + _c.Call.Return(run) + return _c } // UpdateProjectDomainAttributes provides a mock function with given fields: ctx, request func (_m *ResourceInterface) UpdateProjectDomainAttributes(ctx context.Context, request *admin.ProjectDomainAttributesUpdateRequest) (*admin.ProjectDomainAttributesUpdateResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for UpdateProjectDomainAttributes") + } + var r0 *admin.ProjectDomainAttributesUpdateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectDomainAttributesUpdateRequest) (*admin.ProjectDomainAttributesUpdateResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.ProjectDomainAttributesUpdateRequest) *admin.ProjectDomainAttributesUpdateResponse); ok { r0 = rf(ctx, request) } else { @@ -417,7 +577,6 @@ func (_m *ResourceInterface) UpdateProjectDomainAttributes(ctx context.Context, } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.ProjectDomainAttributesUpdateRequest) error); ok { r1 = rf(ctx, request) } else { @@ -427,29 +586,48 @@ func (_m *ResourceInterface) UpdateProjectDomainAttributes(ctx context.Context, return r0, r1 } -type ResourceInterface_UpdateWorkflowAttributes struct { +// ResourceInterface_UpdateProjectDomainAttributes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateProjectDomainAttributes' +type ResourceInterface_UpdateProjectDomainAttributes_Call struct { *mock.Call } -func (_m ResourceInterface_UpdateWorkflowAttributes) Return(_a0 *admin.WorkflowAttributesUpdateResponse, _a1 error) *ResourceInterface_UpdateWorkflowAttributes { - return &ResourceInterface_UpdateWorkflowAttributes{Call: _m.Call.Return(_a0, _a1)} +// UpdateProjectDomainAttributes is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ProjectDomainAttributesUpdateRequest +func (_e *ResourceInterface_Expecter) UpdateProjectDomainAttributes(ctx interface{}, request interface{}) *ResourceInterface_UpdateProjectDomainAttributes_Call { + return &ResourceInterface_UpdateProjectDomainAttributes_Call{Call: _e.mock.On("UpdateProjectDomainAttributes", ctx, request)} +} + +func (_c *ResourceInterface_UpdateProjectDomainAttributes_Call) Run(run func(ctx context.Context, request *admin.ProjectDomainAttributesUpdateRequest)) *ResourceInterface_UpdateProjectDomainAttributes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ProjectDomainAttributesUpdateRequest)) + }) + return _c } -func (_m *ResourceInterface) OnUpdateWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesUpdateRequest) *ResourceInterface_UpdateWorkflowAttributes { - c_call := _m.On("UpdateWorkflowAttributes", ctx, request) - return &ResourceInterface_UpdateWorkflowAttributes{Call: c_call} +func (_c *ResourceInterface_UpdateProjectDomainAttributes_Call) Return(_a0 *admin.ProjectDomainAttributesUpdateResponse, _a1 error) *ResourceInterface_UpdateProjectDomainAttributes_Call { + _c.Call.Return(_a0, _a1) + return _c } -func (_m *ResourceInterface) OnUpdateWorkflowAttributesMatch(matchers ...interface{}) *ResourceInterface_UpdateWorkflowAttributes { - c_call := _m.On("UpdateWorkflowAttributes", matchers...) - return &ResourceInterface_UpdateWorkflowAttributes{Call: c_call} +func (_c *ResourceInterface_UpdateProjectDomainAttributes_Call) RunAndReturn(run func(context.Context, *admin.ProjectDomainAttributesUpdateRequest) (*admin.ProjectDomainAttributesUpdateResponse, error)) *ResourceInterface_UpdateProjectDomainAttributes_Call { + _c.Call.Return(run) + return _c } // UpdateWorkflowAttributes provides a mock function with given fields: ctx, request func (_m *ResourceInterface) UpdateWorkflowAttributes(ctx context.Context, request *admin.WorkflowAttributesUpdateRequest) (*admin.WorkflowAttributesUpdateResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for UpdateWorkflowAttributes") + } + var r0 *admin.WorkflowAttributesUpdateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowAttributesUpdateRequest) (*admin.WorkflowAttributesUpdateResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowAttributesUpdateRequest) *admin.WorkflowAttributesUpdateResponse); ok { r0 = rf(ctx, request) } else { @@ -458,7 +636,6 @@ func (_m *ResourceInterface) UpdateWorkflowAttributes(ctx context.Context, reque } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.WorkflowAttributesUpdateRequest) error); ok { r1 = rf(ctx, request) } else { @@ -467,3 +644,46 @@ func (_m *ResourceInterface) UpdateWorkflowAttributes(ctx context.Context, reque return r0, r1 } + +// ResourceInterface_UpdateWorkflowAttributes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateWorkflowAttributes' +type ResourceInterface_UpdateWorkflowAttributes_Call struct { + *mock.Call +} + +// UpdateWorkflowAttributes is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.WorkflowAttributesUpdateRequest +func (_e *ResourceInterface_Expecter) UpdateWorkflowAttributes(ctx interface{}, request interface{}) *ResourceInterface_UpdateWorkflowAttributes_Call { + return &ResourceInterface_UpdateWorkflowAttributes_Call{Call: _e.mock.On("UpdateWorkflowAttributes", ctx, request)} +} + +func (_c *ResourceInterface_UpdateWorkflowAttributes_Call) Run(run func(ctx context.Context, request *admin.WorkflowAttributesUpdateRequest)) *ResourceInterface_UpdateWorkflowAttributes_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.WorkflowAttributesUpdateRequest)) + }) + return _c +} + +func (_c *ResourceInterface_UpdateWorkflowAttributes_Call) Return(_a0 *admin.WorkflowAttributesUpdateResponse, _a1 error) *ResourceInterface_UpdateWorkflowAttributes_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ResourceInterface_UpdateWorkflowAttributes_Call) RunAndReturn(run func(context.Context, *admin.WorkflowAttributesUpdateRequest) (*admin.WorkflowAttributesUpdateResponse, error)) *ResourceInterface_UpdateWorkflowAttributes_Call { + _c.Call.Return(run) + return _c +} + +// NewResourceInterface creates a new instance of ResourceInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewResourceInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *ResourceInterface { + mock := &ResourceInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/flyteadmin/pkg/manager/mocks/task.go b/flyteadmin/pkg/manager/mocks/task.go deleted file mode 100644 index 39e1ef6c7a..0000000000 --- a/flyteadmin/pkg/manager/mocks/task.go +++ /dev/null @@ -1,50 +0,0 @@ -package mocks - -import ( - "context" - - "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" -) - -type CreateTaskFunc func(ctx context.Context, request *admin.TaskCreateRequest) (*admin.TaskCreateResponse, error) -type ListUniqueIdsFunc func(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error) - -type MockTaskManager struct { - createTaskFunc CreateTaskFunc - listUniqueIdsFunc ListUniqueIdsFunc -} - -func (r *MockTaskManager) SetCreateCallback(createFunction CreateTaskFunc) { - r.createTaskFunc = createFunction -} - -func (r *MockTaskManager) CreateTask( - ctx context.Context, - request *admin.TaskCreateRequest) (*admin.TaskCreateResponse, error) { - if r.createTaskFunc != nil { - return r.createTaskFunc(ctx, request) - } - return nil, nil -} - -func (r *MockTaskManager) GetTask(ctx context.Context, request *admin.ObjectGetRequest) (*admin.Task, error) { - return nil, nil -} - -func (r *MockTaskManager) ListTasks(ctx context.Context, request *admin.ResourceListRequest) (*admin.TaskList, error) { - return nil, nil -} - -func (r *MockTaskManager) SetListUniqueIdsFunc(fn ListUniqueIdsFunc) { - r.listUniqueIdsFunc = fn -} - -func (r *MockTaskManager) ListUniqueTaskIdentifiers(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) ( - *admin.NamedEntityIdentifierList, error) { - - if r.listUniqueIdsFunc != nil { - return r.listUniqueIdsFunc(ctx, request) - } - - return nil, nil -} diff --git a/flyteadmin/pkg/manager/mocks/task_execution.go b/flyteadmin/pkg/manager/mocks/task_execution.go deleted file mode 100644 index f431b31710..0000000000 --- a/flyteadmin/pkg/manager/mocks/task_execution.go +++ /dev/null @@ -1,75 +0,0 @@ -package mocks - -import ( - "context" - - "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" -) - -type CreateTaskExecutionEventFunc func(ctx context.Context, request *admin.TaskExecutionEventRequest) ( - *admin.TaskExecutionEventResponse, error) -type GetTaskExecutionFunc func(ctx context.Context, request *admin.TaskExecutionGetRequest) ( - *admin.TaskExecution, error) -type ListTaskExecutionsFunc func(ctx context.Context, request *admin.TaskExecutionListRequest) ( - *admin.TaskExecutionList, error) -type GetTaskExecutionDataFunc func(ctx context.Context, request *admin.TaskExecutionGetDataRequest) ( - *admin.TaskExecutionGetDataResponse, error) - -type MockTaskExecutionManager struct { - createTaskExecutionEventFunc CreateTaskExecutionEventFunc - getTaskExecutionFunc GetTaskExecutionFunc - listTaskExecutionsFunc ListTaskExecutionsFunc - getTaskExecutionDataFunc GetTaskExecutionDataFunc -} - -func (m *MockTaskExecutionManager) CreateTaskExecutionEvent( - ctx context.Context, request *admin.TaskExecutionEventRequest) (*admin.TaskExecutionEventResponse, error) { - if m.createTaskExecutionEventFunc != nil { - return m.createTaskExecutionEventFunc(ctx, request) - } - return nil, nil -} - -func (m *MockTaskExecutionManager) SetCreateTaskEventCallback( - createFunc CreateTaskExecutionEventFunc) { - m.createTaskExecutionEventFunc = createFunc -} - -func (m *MockTaskExecutionManager) GetTaskExecution( - ctx context.Context, request *admin.TaskExecutionGetRequest) (*admin.TaskExecution, error) { - if m.getTaskExecutionFunc != nil { - return m.getTaskExecutionFunc(ctx, request) - } - return nil, nil -} - -func (m *MockTaskExecutionManager) SetGetTaskExecutionCallback( - getTaskExecutionFunc GetTaskExecutionFunc) { - m.getTaskExecutionFunc = getTaskExecutionFunc -} - -func (m *MockTaskExecutionManager) ListTaskExecutions( - ctx context.Context, request *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error) { - if m.listTaskExecutionsFunc != nil { - return m.listTaskExecutionsFunc(ctx, request) - } - return nil, nil -} - -func (m *MockTaskExecutionManager) SetListTaskExecutionsCallback( - listTaskExecutionsFunc ListTaskExecutionsFunc) { - m.listTaskExecutionsFunc = listTaskExecutionsFunc -} - -func (m *MockTaskExecutionManager) GetTaskExecutionData( - ctx context.Context, request *admin.TaskExecutionGetDataRequest) (*admin.TaskExecutionGetDataResponse, error) { - if m.getTaskExecutionDataFunc != nil { - return m.getTaskExecutionDataFunc(ctx, request) - } - return nil, nil -} - -func (m *MockTaskExecutionManager) SetGetTaskExecutionDataCallback( - getTaskExecutionDataFunc GetTaskExecutionDataFunc) { - m.getTaskExecutionDataFunc = getTaskExecutionDataFunc -} diff --git a/flyteadmin/pkg/manager/mocks/task_execution_interface.go b/flyteadmin/pkg/manager/mocks/task_execution_interface.go new file mode 100644 index 0000000000..a536e2e168 --- /dev/null +++ b/flyteadmin/pkg/manager/mocks/task_execution_interface.go @@ -0,0 +1,274 @@ +// Code generated by mockery v2.40.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + admin "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" + + mock "github.com/stretchr/testify/mock" +) + +// TaskExecutionInterface is an autogenerated mock type for the TaskExecutionInterface type +type TaskExecutionInterface struct { + mock.Mock +} + +type TaskExecutionInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *TaskExecutionInterface) EXPECT() *TaskExecutionInterface_Expecter { + return &TaskExecutionInterface_Expecter{mock: &_m.Mock} +} + +// CreateTaskExecutionEvent provides a mock function with given fields: ctx, request +func (_m *TaskExecutionInterface) CreateTaskExecutionEvent(ctx context.Context, request *admin.TaskExecutionEventRequest) (*admin.TaskExecutionEventResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for CreateTaskExecutionEvent") + } + + var r0 *admin.TaskExecutionEventResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.TaskExecutionEventRequest) (*admin.TaskExecutionEventResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.TaskExecutionEventRequest) *admin.TaskExecutionEventResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.TaskExecutionEventResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.TaskExecutionEventRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TaskExecutionInterface_CreateTaskExecutionEvent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateTaskExecutionEvent' +type TaskExecutionInterface_CreateTaskExecutionEvent_Call struct { + *mock.Call +} + +// CreateTaskExecutionEvent is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.TaskExecutionEventRequest +func (_e *TaskExecutionInterface_Expecter) CreateTaskExecutionEvent(ctx interface{}, request interface{}) *TaskExecutionInterface_CreateTaskExecutionEvent_Call { + return &TaskExecutionInterface_CreateTaskExecutionEvent_Call{Call: _e.mock.On("CreateTaskExecutionEvent", ctx, request)} +} + +func (_c *TaskExecutionInterface_CreateTaskExecutionEvent_Call) Run(run func(ctx context.Context, request *admin.TaskExecutionEventRequest)) *TaskExecutionInterface_CreateTaskExecutionEvent_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.TaskExecutionEventRequest)) + }) + return _c +} + +func (_c *TaskExecutionInterface_CreateTaskExecutionEvent_Call) Return(_a0 *admin.TaskExecutionEventResponse, _a1 error) *TaskExecutionInterface_CreateTaskExecutionEvent_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TaskExecutionInterface_CreateTaskExecutionEvent_Call) RunAndReturn(run func(context.Context, *admin.TaskExecutionEventRequest) (*admin.TaskExecutionEventResponse, error)) *TaskExecutionInterface_CreateTaskExecutionEvent_Call { + _c.Call.Return(run) + return _c +} + +// GetTaskExecution provides a mock function with given fields: ctx, request +func (_m *TaskExecutionInterface) GetTaskExecution(ctx context.Context, request *admin.TaskExecutionGetRequest) (*admin.TaskExecution, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetTaskExecution") + } + + var r0 *admin.TaskExecution + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.TaskExecutionGetRequest) (*admin.TaskExecution, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.TaskExecutionGetRequest) *admin.TaskExecution); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.TaskExecution) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.TaskExecutionGetRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TaskExecutionInterface_GetTaskExecution_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTaskExecution' +type TaskExecutionInterface_GetTaskExecution_Call struct { + *mock.Call +} + +// GetTaskExecution is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.TaskExecutionGetRequest +func (_e *TaskExecutionInterface_Expecter) GetTaskExecution(ctx interface{}, request interface{}) *TaskExecutionInterface_GetTaskExecution_Call { + return &TaskExecutionInterface_GetTaskExecution_Call{Call: _e.mock.On("GetTaskExecution", ctx, request)} +} + +func (_c *TaskExecutionInterface_GetTaskExecution_Call) Run(run func(ctx context.Context, request *admin.TaskExecutionGetRequest)) *TaskExecutionInterface_GetTaskExecution_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.TaskExecutionGetRequest)) + }) + return _c +} + +func (_c *TaskExecutionInterface_GetTaskExecution_Call) Return(_a0 *admin.TaskExecution, _a1 error) *TaskExecutionInterface_GetTaskExecution_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TaskExecutionInterface_GetTaskExecution_Call) RunAndReturn(run func(context.Context, *admin.TaskExecutionGetRequest) (*admin.TaskExecution, error)) *TaskExecutionInterface_GetTaskExecution_Call { + _c.Call.Return(run) + return _c +} + +// GetTaskExecutionData provides a mock function with given fields: ctx, request +func (_m *TaskExecutionInterface) GetTaskExecutionData(ctx context.Context, request *admin.TaskExecutionGetDataRequest) (*admin.TaskExecutionGetDataResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetTaskExecutionData") + } + + var r0 *admin.TaskExecutionGetDataResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.TaskExecutionGetDataRequest) (*admin.TaskExecutionGetDataResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.TaskExecutionGetDataRequest) *admin.TaskExecutionGetDataResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.TaskExecutionGetDataResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.TaskExecutionGetDataRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TaskExecutionInterface_GetTaskExecutionData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTaskExecutionData' +type TaskExecutionInterface_GetTaskExecutionData_Call struct { + *mock.Call +} + +// GetTaskExecutionData is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.TaskExecutionGetDataRequest +func (_e *TaskExecutionInterface_Expecter) GetTaskExecutionData(ctx interface{}, request interface{}) *TaskExecutionInterface_GetTaskExecutionData_Call { + return &TaskExecutionInterface_GetTaskExecutionData_Call{Call: _e.mock.On("GetTaskExecutionData", ctx, request)} +} + +func (_c *TaskExecutionInterface_GetTaskExecutionData_Call) Run(run func(ctx context.Context, request *admin.TaskExecutionGetDataRequest)) *TaskExecutionInterface_GetTaskExecutionData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.TaskExecutionGetDataRequest)) + }) + return _c +} + +func (_c *TaskExecutionInterface_GetTaskExecutionData_Call) Return(_a0 *admin.TaskExecutionGetDataResponse, _a1 error) *TaskExecutionInterface_GetTaskExecutionData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TaskExecutionInterface_GetTaskExecutionData_Call) RunAndReturn(run func(context.Context, *admin.TaskExecutionGetDataRequest) (*admin.TaskExecutionGetDataResponse, error)) *TaskExecutionInterface_GetTaskExecutionData_Call { + _c.Call.Return(run) + return _c +} + +// ListTaskExecutions provides a mock function with given fields: ctx, request +func (_m *TaskExecutionInterface) ListTaskExecutions(ctx context.Context, request *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListTaskExecutions") + } + + var r0 *admin.TaskExecutionList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.TaskExecutionListRequest) *admin.TaskExecutionList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.TaskExecutionList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.TaskExecutionListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TaskExecutionInterface_ListTaskExecutions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListTaskExecutions' +type TaskExecutionInterface_ListTaskExecutions_Call struct { + *mock.Call +} + +// ListTaskExecutions is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.TaskExecutionListRequest +func (_e *TaskExecutionInterface_Expecter) ListTaskExecutions(ctx interface{}, request interface{}) *TaskExecutionInterface_ListTaskExecutions_Call { + return &TaskExecutionInterface_ListTaskExecutions_Call{Call: _e.mock.On("ListTaskExecutions", ctx, request)} +} + +func (_c *TaskExecutionInterface_ListTaskExecutions_Call) Run(run func(ctx context.Context, request *admin.TaskExecutionListRequest)) *TaskExecutionInterface_ListTaskExecutions_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.TaskExecutionListRequest)) + }) + return _c +} + +func (_c *TaskExecutionInterface_ListTaskExecutions_Call) Return(_a0 *admin.TaskExecutionList, _a1 error) *TaskExecutionInterface_ListTaskExecutions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TaskExecutionInterface_ListTaskExecutions_Call) RunAndReturn(run func(context.Context, *admin.TaskExecutionListRequest) (*admin.TaskExecutionList, error)) *TaskExecutionInterface_ListTaskExecutions_Call { + _c.Call.Return(run) + return _c +} + +// NewTaskExecutionInterface creates a new instance of TaskExecutionInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTaskExecutionInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *TaskExecutionInterface { + mock := &TaskExecutionInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/flyteadmin/pkg/manager/mocks/task_interface.go b/flyteadmin/pkg/manager/mocks/task_interface.go new file mode 100644 index 0000000000..520b555d5f --- /dev/null +++ b/flyteadmin/pkg/manager/mocks/task_interface.go @@ -0,0 +1,274 @@ +// Code generated by mockery v2.40.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + admin "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" + + mock "github.com/stretchr/testify/mock" +) + +// TaskInterface is an autogenerated mock type for the TaskInterface type +type TaskInterface struct { + mock.Mock +} + +type TaskInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *TaskInterface) EXPECT() *TaskInterface_Expecter { + return &TaskInterface_Expecter{mock: &_m.Mock} +} + +// CreateTask provides a mock function with given fields: ctx, request +func (_m *TaskInterface) CreateTask(ctx context.Context, request *admin.TaskCreateRequest) (*admin.TaskCreateResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for CreateTask") + } + + var r0 *admin.TaskCreateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.TaskCreateRequest) (*admin.TaskCreateResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.TaskCreateRequest) *admin.TaskCreateResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.TaskCreateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.TaskCreateRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TaskInterface_CreateTask_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateTask' +type TaskInterface_CreateTask_Call struct { + *mock.Call +} + +// CreateTask is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.TaskCreateRequest +func (_e *TaskInterface_Expecter) CreateTask(ctx interface{}, request interface{}) *TaskInterface_CreateTask_Call { + return &TaskInterface_CreateTask_Call{Call: _e.mock.On("CreateTask", ctx, request)} +} + +func (_c *TaskInterface_CreateTask_Call) Run(run func(ctx context.Context, request *admin.TaskCreateRequest)) *TaskInterface_CreateTask_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.TaskCreateRequest)) + }) + return _c +} + +func (_c *TaskInterface_CreateTask_Call) Return(_a0 *admin.TaskCreateResponse, _a1 error) *TaskInterface_CreateTask_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TaskInterface_CreateTask_Call) RunAndReturn(run func(context.Context, *admin.TaskCreateRequest) (*admin.TaskCreateResponse, error)) *TaskInterface_CreateTask_Call { + _c.Call.Return(run) + return _c +} + +// GetTask provides a mock function with given fields: ctx, request +func (_m *TaskInterface) GetTask(ctx context.Context, request *admin.ObjectGetRequest) (*admin.Task, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetTask") + } + + var r0 *admin.Task + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ObjectGetRequest) (*admin.Task, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ObjectGetRequest) *admin.Task); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.Task) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ObjectGetRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TaskInterface_GetTask_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetTask' +type TaskInterface_GetTask_Call struct { + *mock.Call +} + +// GetTask is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ObjectGetRequest +func (_e *TaskInterface_Expecter) GetTask(ctx interface{}, request interface{}) *TaskInterface_GetTask_Call { + return &TaskInterface_GetTask_Call{Call: _e.mock.On("GetTask", ctx, request)} +} + +func (_c *TaskInterface_GetTask_Call) Run(run func(ctx context.Context, request *admin.ObjectGetRequest)) *TaskInterface_GetTask_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ObjectGetRequest)) + }) + return _c +} + +func (_c *TaskInterface_GetTask_Call) Return(_a0 *admin.Task, _a1 error) *TaskInterface_GetTask_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TaskInterface_GetTask_Call) RunAndReturn(run func(context.Context, *admin.ObjectGetRequest) (*admin.Task, error)) *TaskInterface_GetTask_Call { + _c.Call.Return(run) + return _c +} + +// ListTasks provides a mock function with given fields: ctx, request +func (_m *TaskInterface) ListTasks(ctx context.Context, request *admin.ResourceListRequest) (*admin.TaskList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListTasks") + } + + var r0 *admin.TaskList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ResourceListRequest) (*admin.TaskList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ResourceListRequest) *admin.TaskList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.TaskList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ResourceListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TaskInterface_ListTasks_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListTasks' +type TaskInterface_ListTasks_Call struct { + *mock.Call +} + +// ListTasks is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ResourceListRequest +func (_e *TaskInterface_Expecter) ListTasks(ctx interface{}, request interface{}) *TaskInterface_ListTasks_Call { + return &TaskInterface_ListTasks_Call{Call: _e.mock.On("ListTasks", ctx, request)} +} + +func (_c *TaskInterface_ListTasks_Call) Run(run func(ctx context.Context, request *admin.ResourceListRequest)) *TaskInterface_ListTasks_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ResourceListRequest)) + }) + return _c +} + +func (_c *TaskInterface_ListTasks_Call) Return(_a0 *admin.TaskList, _a1 error) *TaskInterface_ListTasks_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TaskInterface_ListTasks_Call) RunAndReturn(run func(context.Context, *admin.ResourceListRequest) (*admin.TaskList, error)) *TaskInterface_ListTasks_Call { + _c.Call.Return(run) + return _c +} + +// ListUniqueTaskIdentifiers provides a mock function with given fields: ctx, request +func (_m *TaskInterface) ListUniqueTaskIdentifiers(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListUniqueTaskIdentifiers") + } + + var r0 *admin.NamedEntityIdentifierList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityIdentifierListRequest) *admin.NamedEntityIdentifierList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NamedEntityIdentifierList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NamedEntityIdentifierListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TaskInterface_ListUniqueTaskIdentifiers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListUniqueTaskIdentifiers' +type TaskInterface_ListUniqueTaskIdentifiers_Call struct { + *mock.Call +} + +// ListUniqueTaskIdentifiers is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NamedEntityIdentifierListRequest +func (_e *TaskInterface_Expecter) ListUniqueTaskIdentifiers(ctx interface{}, request interface{}) *TaskInterface_ListUniqueTaskIdentifiers_Call { + return &TaskInterface_ListUniqueTaskIdentifiers_Call{Call: _e.mock.On("ListUniqueTaskIdentifiers", ctx, request)} +} + +func (_c *TaskInterface_ListUniqueTaskIdentifiers_Call) Run(run func(ctx context.Context, request *admin.NamedEntityIdentifierListRequest)) *TaskInterface_ListUniqueTaskIdentifiers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NamedEntityIdentifierListRequest)) + }) + return _c +} + +func (_c *TaskInterface_ListUniqueTaskIdentifiers_Call) Return(_a0 *admin.NamedEntityIdentifierList, _a1 error) *TaskInterface_ListUniqueTaskIdentifiers_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TaskInterface_ListUniqueTaskIdentifiers_Call) RunAndReturn(run func(context.Context, *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error)) *TaskInterface_ListUniqueTaskIdentifiers_Call { + _c.Call.Return(run) + return _c +} + +// NewTaskInterface creates a new instance of TaskInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTaskInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *TaskInterface { + mock := &TaskInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/flyteadmin/pkg/manager/mocks/workflow.go b/flyteadmin/pkg/manager/mocks/workflow.go deleted file mode 100644 index 0656f2893c..0000000000 --- a/flyteadmin/pkg/manager/mocks/workflow.go +++ /dev/null @@ -1,50 +0,0 @@ -package mocks - -import ( - "context" - - "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" -) - -type CreateWorkflowFunc func(ctx context.Context, request *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error) -type GetWorkflowFunc func(ctx context.Context, request *admin.ObjectGetRequest) (*admin.Workflow, error) - -type MockWorkflowManager struct { - createWorkflowFunc CreateWorkflowFunc - getWorkflowFunc GetWorkflowFunc -} - -func (r *MockWorkflowManager) SetCreateCallback(createFunction CreateWorkflowFunc) { - r.createWorkflowFunc = createFunction -} - -func (r *MockWorkflowManager) CreateWorkflow( - ctx context.Context, - request *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error) { - if r.createWorkflowFunc != nil { - return r.createWorkflowFunc(ctx, request) - } - return nil, nil -} - -func (r *MockWorkflowManager) ListWorkflows(ctx context.Context, - request *admin.ResourceListRequest) (*admin.WorkflowList, error) { - return nil, nil -} - -func (r *MockWorkflowManager) SetGetCallback(getFunction GetWorkflowFunc) { - r.getWorkflowFunc = getFunction -} - -func (r *MockWorkflowManager) GetWorkflow( - ctx context.Context, request *admin.ObjectGetRequest) (*admin.Workflow, error) { - if r.getWorkflowFunc != nil { - return r.getWorkflowFunc(ctx, request) - } - return nil, nil -} - -func (r *MockWorkflowManager) ListWorkflowIdentifiers(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) ( - *admin.NamedEntityIdentifierList, error) { - return nil, nil -} diff --git a/flyteadmin/pkg/manager/mocks/workflow_interface.go b/flyteadmin/pkg/manager/mocks/workflow_interface.go new file mode 100644 index 0000000000..5b4c2bf200 --- /dev/null +++ b/flyteadmin/pkg/manager/mocks/workflow_interface.go @@ -0,0 +1,274 @@ +// Code generated by mockery v2.40.3. DO NOT EDIT. + +package mocks + +import ( + context "context" + + admin "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" + + mock "github.com/stretchr/testify/mock" +) + +// WorkflowInterface is an autogenerated mock type for the WorkflowInterface type +type WorkflowInterface struct { + mock.Mock +} + +type WorkflowInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *WorkflowInterface) EXPECT() *WorkflowInterface_Expecter { + return &WorkflowInterface_Expecter{mock: &_m.Mock} +} + +// CreateWorkflow provides a mock function with given fields: ctx, request +func (_m *WorkflowInterface) CreateWorkflow(ctx context.Context, request *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for CreateWorkflow") + } + + var r0 *admin.WorkflowCreateResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowCreateRequest) *admin.WorkflowCreateResponse); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.WorkflowCreateResponse) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.WorkflowCreateRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// WorkflowInterface_CreateWorkflow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateWorkflow' +type WorkflowInterface_CreateWorkflow_Call struct { + *mock.Call +} + +// CreateWorkflow is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.WorkflowCreateRequest +func (_e *WorkflowInterface_Expecter) CreateWorkflow(ctx interface{}, request interface{}) *WorkflowInterface_CreateWorkflow_Call { + return &WorkflowInterface_CreateWorkflow_Call{Call: _e.mock.On("CreateWorkflow", ctx, request)} +} + +func (_c *WorkflowInterface_CreateWorkflow_Call) Run(run func(ctx context.Context, request *admin.WorkflowCreateRequest)) *WorkflowInterface_CreateWorkflow_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.WorkflowCreateRequest)) + }) + return _c +} + +func (_c *WorkflowInterface_CreateWorkflow_Call) Return(_a0 *admin.WorkflowCreateResponse, _a1 error) *WorkflowInterface_CreateWorkflow_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *WorkflowInterface_CreateWorkflow_Call) RunAndReturn(run func(context.Context, *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error)) *WorkflowInterface_CreateWorkflow_Call { + _c.Call.Return(run) + return _c +} + +// GetWorkflow provides a mock function with given fields: ctx, request +func (_m *WorkflowInterface) GetWorkflow(ctx context.Context, request *admin.ObjectGetRequest) (*admin.Workflow, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for GetWorkflow") + } + + var r0 *admin.Workflow + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ObjectGetRequest) (*admin.Workflow, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ObjectGetRequest) *admin.Workflow); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.Workflow) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ObjectGetRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// WorkflowInterface_GetWorkflow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetWorkflow' +type WorkflowInterface_GetWorkflow_Call struct { + *mock.Call +} + +// GetWorkflow is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ObjectGetRequest +func (_e *WorkflowInterface_Expecter) GetWorkflow(ctx interface{}, request interface{}) *WorkflowInterface_GetWorkflow_Call { + return &WorkflowInterface_GetWorkflow_Call{Call: _e.mock.On("GetWorkflow", ctx, request)} +} + +func (_c *WorkflowInterface_GetWorkflow_Call) Run(run func(ctx context.Context, request *admin.ObjectGetRequest)) *WorkflowInterface_GetWorkflow_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ObjectGetRequest)) + }) + return _c +} + +func (_c *WorkflowInterface_GetWorkflow_Call) Return(_a0 *admin.Workflow, _a1 error) *WorkflowInterface_GetWorkflow_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *WorkflowInterface_GetWorkflow_Call) RunAndReturn(run func(context.Context, *admin.ObjectGetRequest) (*admin.Workflow, error)) *WorkflowInterface_GetWorkflow_Call { + _c.Call.Return(run) + return _c +} + +// ListWorkflowIdentifiers provides a mock function with given fields: ctx, request +func (_m *WorkflowInterface) ListWorkflowIdentifiers(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListWorkflowIdentifiers") + } + + var r0 *admin.NamedEntityIdentifierList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.NamedEntityIdentifierListRequest) *admin.NamedEntityIdentifierList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.NamedEntityIdentifierList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.NamedEntityIdentifierListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// WorkflowInterface_ListWorkflowIdentifiers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListWorkflowIdentifiers' +type WorkflowInterface_ListWorkflowIdentifiers_Call struct { + *mock.Call +} + +// ListWorkflowIdentifiers is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.NamedEntityIdentifierListRequest +func (_e *WorkflowInterface_Expecter) ListWorkflowIdentifiers(ctx interface{}, request interface{}) *WorkflowInterface_ListWorkflowIdentifiers_Call { + return &WorkflowInterface_ListWorkflowIdentifiers_Call{Call: _e.mock.On("ListWorkflowIdentifiers", ctx, request)} +} + +func (_c *WorkflowInterface_ListWorkflowIdentifiers_Call) Run(run func(ctx context.Context, request *admin.NamedEntityIdentifierListRequest)) *WorkflowInterface_ListWorkflowIdentifiers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.NamedEntityIdentifierListRequest)) + }) + return _c +} + +func (_c *WorkflowInterface_ListWorkflowIdentifiers_Call) Return(_a0 *admin.NamedEntityIdentifierList, _a1 error) *WorkflowInterface_ListWorkflowIdentifiers_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *WorkflowInterface_ListWorkflowIdentifiers_Call) RunAndReturn(run func(context.Context, *admin.NamedEntityIdentifierListRequest) (*admin.NamedEntityIdentifierList, error)) *WorkflowInterface_ListWorkflowIdentifiers_Call { + _c.Call.Return(run) + return _c +} + +// ListWorkflows provides a mock function with given fields: ctx, request +func (_m *WorkflowInterface) ListWorkflows(ctx context.Context, request *admin.ResourceListRequest) (*admin.WorkflowList, error) { + ret := _m.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for ListWorkflows") + } + + var r0 *admin.WorkflowList + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.ResourceListRequest) (*admin.WorkflowList, error)); ok { + return rf(ctx, request) + } + if rf, ok := ret.Get(0).(func(context.Context, *admin.ResourceListRequest) *admin.WorkflowList); ok { + r0 = rf(ctx, request) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*admin.WorkflowList) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, *admin.ResourceListRequest) error); ok { + r1 = rf(ctx, request) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// WorkflowInterface_ListWorkflows_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListWorkflows' +type WorkflowInterface_ListWorkflows_Call struct { + *mock.Call +} + +// ListWorkflows is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.ResourceListRequest +func (_e *WorkflowInterface_Expecter) ListWorkflows(ctx interface{}, request interface{}) *WorkflowInterface_ListWorkflows_Call { + return &WorkflowInterface_ListWorkflows_Call{Call: _e.mock.On("ListWorkflows", ctx, request)} +} + +func (_c *WorkflowInterface_ListWorkflows_Call) Run(run func(ctx context.Context, request *admin.ResourceListRequest)) *WorkflowInterface_ListWorkflows_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.ResourceListRequest)) + }) + return _c +} + +func (_c *WorkflowInterface_ListWorkflows_Call) Return(_a0 *admin.WorkflowList, _a1 error) *WorkflowInterface_ListWorkflows_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *WorkflowInterface_ListWorkflows_Call) RunAndReturn(run func(context.Context, *admin.ResourceListRequest) (*admin.WorkflowList, error)) *WorkflowInterface_ListWorkflows_Call { + _c.Call.Return(run) + return _c +} + +// NewWorkflowInterface creates a new instance of WorkflowInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewWorkflowInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *WorkflowInterface { + mock := &WorkflowInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/flyteadmin/pkg/rpc/adminservice/tests/execution_test.go b/flyteadmin/pkg/rpc/adminservice/tests/execution_test.go index ef73e60eaa..65b22a839b 100644 --- a/flyteadmin/pkg/rpc/adminservice/tests/execution_test.go +++ b/flyteadmin/pkg/rpc/adminservice/tests/execution_test.go @@ -8,6 +8,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "google.golang.org/grpc/codes" flyteAdminErrors "github.com/flyteorg/flyte/flyteadmin/pkg/errors" @@ -30,8 +31,8 @@ var workflowExecutionIdentifier = core.WorkflowExecutionIdentifier{ func TestCreateExecutionHappyCase(t *testing.T) { ctx := context.Background() - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetCreateCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().CreateExecution(mock.Anything, mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ExecutionCreateRequest, requestedAt time.Time) (*admin.ExecutionCreateResponse, error) { return &admin.ExecutionCreateResponse{ @@ -59,8 +60,8 @@ func TestCreateExecutionHappyCase(t *testing.T) { func TestCreateExecutionError(t *testing.T) { ctx := context.Background() - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetCreateCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().CreateExecution(mock.Anything, mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ExecutionCreateRequest, requestedAt time.Time) (*admin.ExecutionCreateResponse, error) { return nil, repoErrors.GetMissingEntityError("execution", &core.Identifier{ @@ -87,8 +88,8 @@ func TestCreateExecutionError(t *testing.T) { func TestRelaunchExecutionHappyCase(t *testing.T) { ctx := context.Background() - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetRelaunchCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().RelaunchExecution(mock.Anything, mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ExecutionRelaunchRequest, requestedAt time.Time) (*admin.ExecutionCreateResponse, error) { return &admin.ExecutionCreateResponse{ @@ -120,8 +121,8 @@ func TestRelaunchExecutionHappyCase(t *testing.T) { func TestRelaunchExecutionError(t *testing.T) { ctx := context.Background() - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetRelaunchCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().RelaunchExecution(mock.Anything, mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ExecutionRelaunchRequest, requestedAt time.Time) (*admin.ExecutionCreateResponse, error) { return nil, repoErrors.GetMissingEntityError("execution", request.GetId()) @@ -142,8 +143,8 @@ func TestRelaunchExecutionError(t *testing.T) { func TestRecoverExecutionHappyCase(t *testing.T) { ctx := context.Background() - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.RecoverExecutionFunc = + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().RecoverExecution(mock.Anything, mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ExecutionRecoverRequest, requestedAt time.Time) (*admin.ExecutionCreateResponse, error) { return &admin.ExecutionCreateResponse{ @@ -153,7 +154,7 @@ func TestRecoverExecutionHappyCase(t *testing.T) { Name: request.GetName(), }, }, nil - } + }) mockServer := NewMockAdminServer(NewMockAdminServerInput{ executionManager: &mockExecutionManager, @@ -175,12 +176,12 @@ func TestRecoverExecutionHappyCase(t *testing.T) { func TestRecoverExecutionError(t *testing.T) { ctx := context.Background() - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.RecoverExecutionFunc = + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().RecoverExecution(mock.Anything, mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ExecutionRecoverRequest, requestedAt time.Time) (*admin.ExecutionCreateResponse, error) { return nil, repoErrors.GetMissingEntityError("execution", request.GetId()) - } + }) mockServer := NewMockAdminServer(NewMockAdminServerInput{ executionManager: &mockExecutionManager, }) @@ -195,8 +196,8 @@ func TestRecoverExecutionError(t *testing.T) { func TestCreateWorkflowEvent(t *testing.T) { phase := core.WorkflowExecution_RUNNING - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetCreateEventCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().CreateWorkflowEvent(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.WorkflowExecutionEventRequest) ( *admin.WorkflowExecutionEventResponse, error) { assert.Equal(t, requestID, request.GetRequestId()) @@ -219,8 +220,8 @@ func TestCreateWorkflowEvent(t *testing.T) { assert.NotNil(t, resp) } func TestCreateWorkflowEventErr(t *testing.T) { - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetCreateEventCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().CreateWorkflowEvent(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.WorkflowExecutionEventRequest) ( *admin.WorkflowExecutionEventResponse, error) { return nil, errors.New("expected error") @@ -244,8 +245,8 @@ func TestGetExecution(t *testing.T) { response := &admin.Execution{ Id: &workflowExecutionIdentifier, } - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetGetCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().GetExecution(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.WorkflowExecutionGetRequest) (*admin.Execution, error) { assert.True(t, proto.Equal(&workflowExecutionIdentifier, request.GetId())) @@ -264,8 +265,8 @@ func TestGetExecution(t *testing.T) { } func TestGetExecutionError(t *testing.T) { - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetGetCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().GetExecution(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.WorkflowExecutionGetRequest) (*admin.Execution, error) { return nil, errors.New("expected error") @@ -284,8 +285,8 @@ func TestGetExecutionError(t *testing.T) { func TestUpdateExecution(t *testing.T) { response := &admin.ExecutionUpdateResponse{} - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetUpdateExecutionCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().UpdateExecution(mock.Anything, mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ExecutionUpdateRequest, requestedAt time.Time) (*admin.ExecutionUpdateResponse, error) { assert.True(t, proto.Equal(&workflowExecutionIdentifier, request.GetId())) @@ -304,8 +305,8 @@ func TestUpdateExecution(t *testing.T) { } func TestUpdateExecutionError(t *testing.T) { - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetUpdateExecutionCallback( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().UpdateExecution(mock.Anything, mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ExecutionUpdateRequest, requestedAt time.Time) (*admin.ExecutionUpdateResponse, error) { return nil, errors.New("expected error") @@ -323,8 +324,8 @@ func TestUpdateExecutionError(t *testing.T) { } func TestListExecutions(t *testing.T) { - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetListCallback(func(ctx context.Context, request *admin.ResourceListRequest) ( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().ListExecutions(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.ResourceListRequest) ( *admin.ExecutionList, error) { assert.Equal(t, "project", request.GetId().GetProject()) assert.Equal(t, "domain", request.GetId().GetDomain()) @@ -354,8 +355,8 @@ func TestListExecutions(t *testing.T) { } func TestListExecutionsError(t *testing.T) { - mockExecutionManager := mocks.MockExecutionManager{} - mockExecutionManager.SetListCallback(func(ctx context.Context, request *admin.ResourceListRequest) ( + mockExecutionManager := mocks.ExecutionInterface{} + mockExecutionManager.EXPECT().ListExecutions(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.ResourceListRequest) ( *admin.ExecutionList, error) { return nil, errors.New("expected error") }) @@ -377,14 +378,14 @@ func TestListExecutionsError(t *testing.T) { } func TestTerminateExecution(t *testing.T) { - mockExecutionManager := mocks.MockExecutionManager{} + mockExecutionManager := mocks.ExecutionInterface{} identifier := core.WorkflowExecutionIdentifier{ Project: "project", Domain: "domain", Name: "name", } abortCause := "abort cause" - mockExecutionManager.SetTerminateExecutionCallback(func( + mockExecutionManager.EXPECT().TerminateExecution(mock.Anything, mock.Anything).RunAndReturn(func( ctx context.Context, request *admin.ExecutionTerminateRequest) (*admin.ExecutionTerminateResponse, error) { assert.True(t, proto.Equal(&identifier, request.GetId())) assert.Equal(t, abortCause, request.GetCause()) @@ -401,14 +402,14 @@ func TestTerminateExecution(t *testing.T) { } func TestTerminateExecution_Error(t *testing.T) { - mockExecutionManager := mocks.MockExecutionManager{} + mockExecutionManager := mocks.ExecutionInterface{} identifier := core.WorkflowExecutionIdentifier{ Project: "project", Domain: "domain", Name: "name", } abortCause := "abort cause" - mockExecutionManager.SetTerminateExecutionCallback(func( + mockExecutionManager.EXPECT().TerminateExecution(mock.Anything, mock.Anything).RunAndReturn(func( ctx context.Context, request *admin.ExecutionTerminateRequest) (*admin.ExecutionTerminateResponse, error) { return nil, errors.New("expected error") }) diff --git a/flyteadmin/pkg/rpc/adminservice/tests/launch_plan_test.go b/flyteadmin/pkg/rpc/adminservice/tests/launch_plan_test.go index 4fabdbb9c0..840182296e 100644 --- a/flyteadmin/pkg/rpc/adminservice/tests/launch_plan_test.go +++ b/flyteadmin/pkg/rpc/adminservice/tests/launch_plan_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/flyteorg/flyte/flyteadmin/pkg/manager/mocks" "github.com/flyteorg/flyte/flyteadmin/pkg/repositories/errors" @@ -16,8 +17,8 @@ import ( func TestCreateLaunchPlanHappyCase(t *testing.T) { ctx := context.Background() - mockLaunchPlanManager := mocks.MockLaunchPlanManager{} - mockLaunchPlanManager.SetCreateCallback( + mockLaunchPlanManager := mocks.LaunchPlanInterface{} + mockLaunchPlanManager.EXPECT().CreateLaunchPlan(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.LaunchPlanCreateRequest) (*admin.LaunchPlanCreateResponse, error) { return &admin.LaunchPlanCreateResponse{}, nil @@ -43,8 +44,8 @@ func TestCreateLaunchPlanHappyCase(t *testing.T) { func TestCreateLaunchPlanError(t *testing.T) { ctx := context.Background() - mockLaunchPlanManager := mocks.MockLaunchPlanManager{} - mockLaunchPlanManager.SetCreateCallback( + mockLaunchPlanManager := mocks.LaunchPlanInterface{} + mockLaunchPlanManager.EXPECT().CreateLaunchPlan(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.LaunchPlanCreateRequest) (*admin.LaunchPlanCreateResponse, error) { return nil, errors.GetMissingEntityError(core.ResourceType_LAUNCH_PLAN.String(), request.GetId()) @@ -71,8 +72,8 @@ func TestCreateLaunchPlanError(t *testing.T) { func TestGetActiveLaunchPlan(t *testing.T) { ctx := context.Background() - mockLaunchPlanManager := mocks.MockLaunchPlanManager{} - mockLaunchPlanManager.SetGetActiveLaunchPlanCallback( + mockLaunchPlanManager := mocks.LaunchPlanInterface{} + mockLaunchPlanManager.EXPECT().GetActiveLaunchPlan(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ActiveLaunchPlanRequest) (*admin.LaunchPlan, error) { return &admin.LaunchPlan{}, nil @@ -96,8 +97,8 @@ func TestGetActiveLaunchPlan(t *testing.T) { func TestGetActiveLaunchPlan_Error(t *testing.T) { ctx := context.Background() - mockLaunchPlanManager := mocks.MockLaunchPlanManager{} - mockLaunchPlanManager.SetGetActiveLaunchPlanCallback( + mockLaunchPlanManager := mocks.LaunchPlanInterface{} + mockLaunchPlanManager.EXPECT().GetActiveLaunchPlan(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ActiveLaunchPlanRequest) (*admin.LaunchPlan, error) { return nil, errors.GetInvalidInputError("invalid input") @@ -121,8 +122,8 @@ func TestGetActiveLaunchPlan_Error(t *testing.T) { func TestListActiveLaunchPlans(t *testing.T) { ctx := context.Background() - mockLaunchPlanManager := mocks.MockLaunchPlanManager{} - mockLaunchPlanManager.SetListActiveLaunchPlansCallback( + mockLaunchPlanManager := mocks.LaunchPlanInterface{} + mockLaunchPlanManager.EXPECT().ListActiveLaunchPlans(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ActiveLaunchPlanListRequest) (*admin.LaunchPlanList, error) { return &admin.LaunchPlanList{}, nil @@ -143,8 +144,8 @@ func TestListActiveLaunchPlans(t *testing.T) { func TestListActiveLaunchPlans_Error(t *testing.T) { ctx := context.Background() - mockLaunchPlanManager := mocks.MockLaunchPlanManager{} - mockLaunchPlanManager.SetListActiveLaunchPlansCallback( + mockLaunchPlanManager := mocks.LaunchPlanInterface{} + mockLaunchPlanManager.EXPECT().ListActiveLaunchPlans(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ActiveLaunchPlanListRequest) (*admin.LaunchPlanList, error) { return nil, errors.GetInvalidInputError("oops") diff --git a/flyteadmin/pkg/rpc/adminservice/tests/node_execution_test.go b/flyteadmin/pkg/rpc/adminservice/tests/node_execution_test.go index 72cdc57ea5..4426d0d259 100644 --- a/flyteadmin/pkg/rpc/adminservice/tests/node_execution_test.go +++ b/flyteadmin/pkg/rpc/adminservice/tests/node_execution_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "google.golang.org/grpc/codes" flyteAdminErrors "github.com/flyteorg/flyte/flyteadmin/pkg/errors" @@ -28,8 +29,8 @@ var nodeExecutionID = core.NodeExecutionIdentifier{ func TestCreateNodeEvent(t *testing.T) { phase := core.NodeExecution_RUNNING - mockNodeExecutionManager := mocks.MockNodeExecutionManager{} - mockNodeExecutionManager.SetCreateNodeEventCallback( + mockNodeExecutionManager := mocks.NodeExecutionInterface{} + mockNodeExecutionManager.EXPECT().CreateNodeEvent(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.NodeExecutionEventRequest) ( *admin.NodeExecutionEventResponse, error) { assert.Equal(t, requestID, request.GetRequestId()) @@ -53,8 +54,8 @@ func TestCreateNodeEvent(t *testing.T) { } func TestCreateNodeEventErr(t *testing.T) { - mockNodeExecutionManager := mocks.MockNodeExecutionManager{} - mockNodeExecutionManager.SetCreateNodeEventCallback( + mockNodeExecutionManager := mocks.NodeExecutionInterface{} + mockNodeExecutionManager.EXPECT().CreateNodeEvent(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.NodeExecutionEventRequest) ( *admin.NodeExecutionEventResponse, error) { return nil, errors.New("expected error") @@ -78,8 +79,8 @@ func TestGetNodeExecution(t *testing.T) { response := &admin.NodeExecution{ Id: &nodeExecutionID, } - mockNodeExecutionManager := mocks.MockNodeExecutionManager{} - mockNodeExecutionManager.SetGetNodeExecutionFunc( + mockNodeExecutionManager := mocks.NodeExecutionInterface{} + mockNodeExecutionManager.EXPECT().GetNodeExecution(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error) { assert.True(t, proto.Equal(&nodeExecutionID, request.GetId())) @@ -98,8 +99,8 @@ func TestGetNodeExecution(t *testing.T) { } func TestGetNodeExecutionError(t *testing.T) { - mockNodeExecutionManager := mocks.MockNodeExecutionManager{} - mockNodeExecutionManager.SetGetNodeExecutionFunc( + mockNodeExecutionManager := mocks.NodeExecutionInterface{} + mockNodeExecutionManager.EXPECT().GetNodeExecution(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.NodeExecutionGetRequest) (*admin.NodeExecution, error) { assert.True(t, proto.Equal(&nodeExecutionID, request.GetId())) @@ -119,9 +120,9 @@ func TestGetNodeExecutionError(t *testing.T) { } func TestListNodeExecutions(t *testing.T) { - mockNodeExecutionManager := mocks.MockNodeExecutionManager{} + mockNodeExecutionManager := mocks.NodeExecutionInterface{} filters := "encoded filters probably" - mockNodeExecutionManager.SetListNodeExecutionsFunc(func(ctx context.Context, request *admin.NodeExecutionListRequest) ( + mockNodeExecutionManager.EXPECT().ListNodeExecutions(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.NodeExecutionListRequest) ( *admin.NodeExecutionList, error) { assert.Equal(t, filters, request.GetFilters()) assert.Equal(t, uint32(1), request.GetLimit()) @@ -149,8 +150,8 @@ func TestListNodeExecutions(t *testing.T) { } func TestListNodeExecutionsError(t *testing.T) { - mockNodeExecutionManager := mocks.MockNodeExecutionManager{} - mockNodeExecutionManager.SetListNodeExecutionsFunc(func(ctx context.Context, request *admin.NodeExecutionListRequest) ( + mockNodeExecutionManager := mocks.NodeExecutionInterface{} + mockNodeExecutionManager.EXPECT().ListNodeExecutions(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.NodeExecutionListRequest) ( *admin.NodeExecutionList, error) { return nil, errors.New("expected error") }) @@ -169,9 +170,9 @@ func TestListNodeExecutionsError(t *testing.T) { } func TestListNodeExecutionsForTask(t *testing.T) { - mockNodeExecutionManager := mocks.MockNodeExecutionManager{} + mockNodeExecutionManager := mocks.NodeExecutionInterface{} filters := "encoded filters probably" - mockNodeExecutionManager.SetListNodeExecutionsForTaskFunc( + mockNodeExecutionManager.EXPECT().ListNodeExecutionsForTask(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.NodeExecutionForTaskListRequest) ( *admin.NodeExecutionList, error) { assert.Equal(t, filters, request.GetFilters()) @@ -200,8 +201,8 @@ func TestListNodeExecutionsForTask(t *testing.T) { } func TestListNodeExecutionsForTaskError(t *testing.T) { - mockNodeExecutionManager := mocks.MockNodeExecutionManager{} - mockNodeExecutionManager.SetListNodeExecutionsForTaskFunc( + mockNodeExecutionManager := mocks.NodeExecutionInterface{} + mockNodeExecutionManager.EXPECT().ListNodeExecutionsForTask(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.NodeExecutionForTaskListRequest) ( *admin.NodeExecutionList, error) { return nil, errors.New("expected error") @@ -221,8 +222,8 @@ func TestListNodeExecutionsForTaskError(t *testing.T) { } func TestGetNodeExecutionData(t *testing.T) { - mockNodeExecutionManager := mocks.MockNodeExecutionManager{} - mockNodeExecutionManager.SetGetNodeExecutionDataFunc( + mockNodeExecutionManager := mocks.NodeExecutionInterface{} + mockNodeExecutionManager.EXPECT().GetNodeExecutionData(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.NodeExecutionGetDataRequest) (*admin.NodeExecutionGetDataResponse, error) { assert.True(t, proto.Equal(&nodeExecutionID, request.GetId())) diff --git a/flyteadmin/pkg/rpc/adminservice/tests/project_domain_test.go b/flyteadmin/pkg/rpc/adminservice/tests/project_domain_test.go index c8787c821c..c71148067b 100644 --- a/flyteadmin/pkg/rpc/adminservice/tests/project_domain_test.go +++ b/flyteadmin/pkg/rpc/adminservice/tests/project_domain_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/flyteorg/flyte/flyteadmin/pkg/manager/mocks" "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" @@ -13,9 +14,9 @@ import ( func TestUpdateProjectDomain(t *testing.T) { ctx := context.Background() - mockProjectDomainManager := mocks.MockResourceManager{} + mockProjectDomainManager := mocks.ResourceInterface{} var updateCalled bool - mockProjectDomainManager.SetUpdateProjectDomainAttributes( + mockProjectDomainManager.EXPECT().UpdateProjectDomainAttributes(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ProjectDomainAttributesUpdateRequest) (*admin.ProjectDomainAttributesUpdateResponse, error) { updateCalled = true @@ -40,14 +41,13 @@ func TestUpdateProjectDomain(t *testing.T) { func TestUpdateProjectAttr(t *testing.T) { ctx := context.Background() - mockProjectDomainManager := mocks.MockResourceManager{} + mockProjectDomainManager := mocks.ResourceInterface{} var updateCalled bool - mockProjectDomainManager.SetUpdateProjectAttributes( - func(ctx context.Context, - request *admin.ProjectAttributesUpdateRequest) (*admin.ProjectAttributesUpdateResponse, error) { - updateCalled = true - return &admin.ProjectAttributesUpdateResponse{}, nil - }, + mockProjectDomainManager.EXPECT().UpdateProjectAttributes(mock.Anything, mock.Anything).RunAndReturn((func(ctx context.Context, + request *admin.ProjectAttributesUpdateRequest) (*admin.ProjectAttributesUpdateResponse, error) { + updateCalled = true + return &admin.ProjectAttributesUpdateResponse{}, nil + }), ) mockServer := NewMockAdminServer(NewMockAdminServerInput{ resourceManager: &mockProjectDomainManager, @@ -66,14 +66,13 @@ func TestUpdateProjectAttr(t *testing.T) { func TestDeleteProjectAttr(t *testing.T) { ctx := context.Background() - mockProjectDomainManager := mocks.MockResourceManager{} + mockProjectDomainManager := mocks.ResourceInterface{} var deleteCalled bool - mockProjectDomainManager.SetDeleteProjectAttributes( - func(ctx context.Context, - request *admin.ProjectAttributesDeleteRequest) (*admin.ProjectAttributesDeleteResponse, error) { - deleteCalled = true - return &admin.ProjectAttributesDeleteResponse{}, nil - }, + mockProjectDomainManager.EXPECT().DeleteProjectAttributes(mock.Anything, mock.Anything).RunAndReturn((func(ctx context.Context, + request *admin.ProjectAttributesDeleteRequest) (*admin.ProjectAttributesDeleteResponse, error) { + deleteCalled = true + return &admin.ProjectAttributesDeleteResponse{}, nil + }), ) mockServer := NewMockAdminServer(NewMockAdminServerInput{ resourceManager: &mockProjectDomainManager, @@ -91,14 +90,13 @@ func TestDeleteProjectAttr(t *testing.T) { func TestGetProjectAttr(t *testing.T) { ctx := context.Background() - mockProjectDomainManager := mocks.MockResourceManager{} + mockProjectDomainManager := mocks.ResourceInterface{} var getCalled bool - mockProjectDomainManager.SetGetProjectAttributes( - func(ctx context.Context, - request *admin.ProjectAttributesGetRequest) (*admin.ProjectAttributesGetResponse, error) { - getCalled = true - return &admin.ProjectAttributesGetResponse{}, nil - }, + mockProjectDomainManager.EXPECT().GetProjectAttributes(mock.Anything, mock.Anything).RunAndReturn((func(ctx context.Context, + request *admin.ProjectAttributesGetRequest) (*admin.ProjectAttributesGetResponse, error) { + getCalled = true + return &admin.ProjectAttributesGetResponse{}, nil + }), ) mockServer := NewMockAdminServer(NewMockAdminServerInput{ resourceManager: &mockProjectDomainManager, diff --git a/flyteadmin/pkg/rpc/adminservice/tests/project_test.go b/flyteadmin/pkg/rpc/adminservice/tests/project_test.go index e6798a25ea..cacbbd50c5 100644 --- a/flyteadmin/pkg/rpc/adminservice/tests/project_test.go +++ b/flyteadmin/pkg/rpc/adminservice/tests/project_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/flyteorg/flyte/flyteadmin/pkg/manager/mocks" "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" @@ -14,8 +15,8 @@ import ( func TestRegisterProject(t *testing.T) { ctx := context.Background() - mockProjectManager := mocks.MockProjectManager{} - mockProjectManager.SetCreateProject( + mockProjectManager := mocks.ProjectInterface{} + mockProjectManager.EXPECT().CreateProject(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.ProjectRegisterRequest) (*admin.ProjectRegisterResponse, error) { return &admin.ProjectRegisterResponse{}, nil @@ -35,7 +36,7 @@ func TestRegisterProject(t *testing.T) { } func TestListProjects(t *testing.T) { - mockProjectManager := mocks.MockProjectManager{} + mockProjectManager := mocks.ProjectInterface{} projects := &admin.Projects{ Projects: []*admin.Project{ { @@ -50,7 +51,7 @@ func TestListProjects(t *testing.T) { }, }, } - mockProjectManager.SetListCallback(func(ctx context.Context, request *admin.ProjectListRequest) (*admin.Projects, error) { + mockProjectManager.EXPECT().ListProjects(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.ProjectListRequest) (*admin.Projects, error) { assert.NotNil(t, request) return projects, nil }) @@ -60,9 +61,9 @@ func TestListProjects(t *testing.T) { } func TestGetProject(t *testing.T) { - mockProjectManager := mocks.MockProjectManager{} + mockProjectManager := mocks.ProjectInterface{} project := &admin.Project{Id: "project id", Name: "project"} - mockProjectManager.SetGetCallBack(func(ctx context.Context, request *admin.ProjectGetRequest) (*admin.Project, error) { + mockProjectManager.EXPECT().GetProject(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.ProjectGetRequest) (*admin.Project, error) { assert.NotNil(t, request) return project, nil }) diff --git a/flyteadmin/pkg/rpc/adminservice/tests/task_execution_test.go b/flyteadmin/pkg/rpc/adminservice/tests/task_execution_test.go index 637426c455..c49c0c9ea1 100644 --- a/flyteadmin/pkg/rpc/adminservice/tests/task_execution_test.go +++ b/flyteadmin/pkg/rpc/adminservice/tests/task_execution_test.go @@ -8,6 +8,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "google.golang.org/grpc/codes" flyteAdminErrors "github.com/flyteorg/flyte/flyteadmin/pkg/errors" @@ -43,8 +44,8 @@ func TestTaskExecution(t *testing.T) { const requestID = "request id" t.Run("TestCreateTaskEvent", func(t *testing.T) { - mockTaskExecutionManager := mocks.MockTaskExecutionManager{} - mockTaskExecutionManager.SetCreateTaskEventCallback( + mockTaskExecutionManager := mocks.TaskExecutionInterface{} + mockTaskExecutionManager.EXPECT().CreateTaskExecutionEvent(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskExecutionEventRequest) ( *admin.TaskExecutionEventResponse, error) { assert.Equal(t, requestID, request.GetRequestId()) @@ -73,7 +74,7 @@ func TestTaskExecution(t *testing.T) { // TEMP: uncomment when we turn on task execution events end to end // t.Run("TestCreateTaskEventErr", func(t *testing.T) { - // mockTaskExecutionManager := mocks.MockTaskExecutionManager{} + // mockTaskExecutionManager := mocks.TaskExecutionInterface{} // mockTaskExecutionManager.SetCreateTaskEventCallback( // func(ctx context.Context, request admin.TaskExecutionEventRequest) ( // *admin.TaskExecutionEventResponse, error) { @@ -97,7 +98,7 @@ func TestTaskExecution(t *testing.T) { // }) // // t.Run("TestCreateTaskEventMissingTimestamp", func(t *testing.T) { - // mockTaskExecutionManager := mocks.MockTaskExecutionManager{} + // mockTaskExecutionManager := mocks.TaskExecutionInterface{} // mockTaskExecutionManager.SetCreateTaskEventCallback( // func(ctx context.Context, request admin.TaskExecutionEventRequest) ( // *admin.TaskExecutionEventResponse, error) { @@ -116,7 +117,7 @@ func TestTaskExecution(t *testing.T) { // }) // // t.Run("TestCreateTaskEventMissingNodeExecutionId", func(t *testing.T) { - // mockTaskExecutionManager := mocks.MockTaskExecutionManager{} + // mockTaskExecutionManager := mocks.TaskExecutionInterface{} // mockTaskExecutionManager.SetCreateTaskEventCallback( // func(ctx context.Context, request admin.TaskExecutionEventRequest) ( // *admin.TaskExecutionEventResponse, error) { @@ -139,8 +140,8 @@ func TestTaskExecution(t *testing.T) { // }) t.Run("TestGetTaskExecution", func(t *testing.T) { - mockTaskExecutionManager := mocks.MockTaskExecutionManager{} - mockTaskExecutionManager.SetGetTaskExecutionCallback( + mockTaskExecutionManager := mocks.TaskExecutionInterface{} + mockTaskExecutionManager.EXPECT().GetTaskExecution(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskExecutionGetRequest) ( *admin.TaskExecution, error) { assert.Equal(t, taskID, request.GetId().GetTaskId()) @@ -163,8 +164,8 @@ func TestTaskExecution(t *testing.T) { }) t.Run("TestGetTaskExecutionErr", func(t *testing.T) { - mockTaskExecutionManager := mocks.MockTaskExecutionManager{} - mockTaskExecutionManager.SetGetTaskExecutionCallback( + mockTaskExecutionManager := mocks.TaskExecutionInterface{} + mockTaskExecutionManager.EXPECT().GetTaskExecution(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskExecutionGetRequest) ( *admin.TaskExecution, error) { return nil, errors.New("expected error") @@ -185,8 +186,8 @@ func TestTaskExecution(t *testing.T) { }) t.Run("TestGetTaskExecutionMissingId", func(t *testing.T) { - mockTaskExecutionManager := mocks.MockTaskExecutionManager{} - mockTaskExecutionManager.SetGetTaskExecutionCallback( + mockTaskExecutionManager := mocks.TaskExecutionInterface{} + mockTaskExecutionManager.EXPECT().GetTaskExecution(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskExecutionGetRequest) ( *admin.TaskExecution, error) { t.Fatal("Parameters should be checked before this call") @@ -206,8 +207,8 @@ func TestTaskExecution(t *testing.T) { }) t.Run("TestGetTaskExecutionMissingNodeExecutionId", func(t *testing.T) { - mockTaskExecutionManager := mocks.MockTaskExecutionManager{} - mockTaskExecutionManager.SetGetTaskExecutionCallback( + mockTaskExecutionManager := mocks.TaskExecutionInterface{} + mockTaskExecutionManager.EXPECT().GetTaskExecution(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskExecutionGetRequest) ( *admin.TaskExecution, error) { t.Fatal("Parameters should be checked before this call") @@ -228,8 +229,8 @@ func TestTaskExecution(t *testing.T) { // List endpoint tests t.Run("TestListTaskExecutions", func(t *testing.T) { - mockTaskExecutionManager := mocks.MockTaskExecutionManager{} - mockTaskExecutionManager.SetListTaskExecutionsCallback( + mockTaskExecutionManager := mocks.TaskExecutionInterface{} + mockTaskExecutionManager.EXPECT().ListTaskExecutions(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskExecutionListRequest) ( *admin.TaskExecutionList, error) { assert.Equal(t, "1", request.GetToken()) @@ -264,8 +265,8 @@ func TestTaskExecution(t *testing.T) { }) t.Run("TestListTaskExecutions_NoLimit", func(t *testing.T) { - mockTaskExecutionManager := mocks.MockTaskExecutionManager{} - mockTaskExecutionManager.SetListTaskExecutionsCallback( + mockTaskExecutionManager := mocks.TaskExecutionInterface{} + mockTaskExecutionManager.EXPECT().ListTaskExecutions(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskExecutionListRequest) ( *admin.TaskExecutionList, error) { return &admin.TaskExecutionList{}, nil @@ -289,8 +290,8 @@ func TestTaskExecution(t *testing.T) { }) t.Run("TestListTaskExecutions_NoFilters", func(t *testing.T) { - mockTaskExecutionManager := mocks.MockTaskExecutionManager{} - mockTaskExecutionManager.SetListTaskExecutionsCallback( + mockTaskExecutionManager := mocks.TaskExecutionInterface{} + mockTaskExecutionManager.EXPECT().ListTaskExecutions(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskExecutionListRequest) ( *admin.TaskExecutionList, error) { return &admin.TaskExecutionList{}, nil @@ -308,8 +309,8 @@ func TestTaskExecution(t *testing.T) { } func TestGetTaskExecutionData(t *testing.T) { - mockTaskExecutionManager := mocks.MockTaskExecutionManager{} - mockTaskExecutionManager.SetGetTaskExecutionDataCallback( + mockTaskExecutionManager := mocks.TaskExecutionInterface{} + mockTaskExecutionManager.EXPECT().GetTaskExecutionData(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskExecutionGetDataRequest) ( *admin.TaskExecutionGetDataResponse, error) { return &admin.TaskExecutionGetDataResponse{ diff --git a/flyteadmin/pkg/rpc/adminservice/tests/task_test.go b/flyteadmin/pkg/rpc/adminservice/tests/task_test.go index bd17b1baa6..2affc93f8e 100644 --- a/flyteadmin/pkg/rpc/adminservice/tests/task_test.go +++ b/flyteadmin/pkg/rpc/adminservice/tests/task_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/flyteorg/flyte/flyteadmin/pkg/manager/mocks" "github.com/flyteorg/flyte/flyteadmin/pkg/repositories/errors" @@ -24,8 +25,8 @@ var taskIdentifier = &core.Identifier{ func TestTaskHappyCase(t *testing.T) { ctx := context.Background() - mockTaskManager := mocks.MockTaskManager{} - mockTaskManager.SetCreateCallback( + mockTaskManager := mocks.TaskInterface{} + mockTaskManager.EXPECT().CreateTask(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskCreateRequest) (*admin.TaskCreateResponse, error) { return &admin.TaskCreateResponse{}, nil @@ -45,8 +46,8 @@ func TestTaskHappyCase(t *testing.T) { func TestTaskError(t *testing.T) { ctx := context.Background() - mockTaskManager := mocks.MockTaskManager{} - mockTaskManager.SetCreateCallback( + mockTaskManager := mocks.TaskInterface{} + mockTaskManager.EXPECT().CreateTask(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.TaskCreateRequest) (*admin.TaskCreateResponse, error) { return nil, errors.GetMissingEntityError(core.ResourceType_TASK.String(), request.GetId()) @@ -73,8 +74,8 @@ func TestTaskError(t *testing.T) { func TestListUniqueTaskIds(t *testing.T) { ctx := context.Background() - mockTaskManager := mocks.MockTaskManager{} - mockTaskManager.SetListUniqueIdsFunc(func(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) ( + mockTaskManager := mocks.TaskInterface{} + mockTaskManager.EXPECT().ListUniqueTaskIdentifiers(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request *admin.NamedEntityIdentifierListRequest) ( *admin.NamedEntityIdentifierList, error) { assert.Equal(t, "staging", request.GetDomain()) diff --git a/flyteadmin/pkg/rpc/adminservice/tests/util.go b/flyteadmin/pkg/rpc/adminservice/tests/util.go index 97a939a124..ba14824612 100644 --- a/flyteadmin/pkg/rpc/adminservice/tests/util.go +++ b/flyteadmin/pkg/rpc/adminservice/tests/util.go @@ -7,14 +7,14 @@ import ( ) type NewMockAdminServerInput struct { - executionManager *mocks.MockExecutionManager - launchPlanManager *mocks.MockLaunchPlanManager - nodeExecutionManager *mocks.MockNodeExecutionManager - projectManager *mocks.MockProjectManager - resourceManager *mocks.MockResourceManager - taskManager *mocks.MockTaskManager - workflowManager *mocks.MockWorkflowManager - taskExecutionManager *mocks.MockTaskExecutionManager + executionManager *mocks.ExecutionInterface + launchPlanManager *mocks.LaunchPlanInterface + nodeExecutionManager *mocks.NodeExecutionInterface + projectManager *mocks.ProjectInterface + resourceManager *mocks.ResourceInterface + taskManager *mocks.TaskInterface + workflowManager *mocks.WorkflowInterface + taskExecutionManager *mocks.TaskExecutionInterface } func NewMockAdminServer(input NewMockAdminServerInput) *adminservice.AdminService { diff --git a/flyteadmin/pkg/rpc/adminservice/tests/workflow_test.go b/flyteadmin/pkg/rpc/adminservice/tests/workflow_test.go index 5799b32519..8e11519d97 100644 --- a/flyteadmin/pkg/rpc/adminservice/tests/workflow_test.go +++ b/flyteadmin/pkg/rpc/adminservice/tests/workflow_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/flyteorg/flyte/flyteadmin/pkg/manager/mocks" "github.com/flyteorg/flyte/flyteadmin/pkg/repositories/errors" @@ -24,8 +25,8 @@ var workflowIdentifier = core.Identifier{ func TestCreateWorkflowHappyCase(t *testing.T) { ctx := context.Background() - mockWorkflowManager := mocks.MockWorkflowManager{} - mockWorkflowManager.SetCreateCallback( + mockWorkflowManager := mocks.WorkflowInterface{} + mockWorkflowManager.EXPECT().CreateWorkflow(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error) { return &admin.WorkflowCreateResponse{}, nil @@ -45,8 +46,8 @@ func TestCreateWorkflowHappyCase(t *testing.T) { func TestCreateWorkflowError(t *testing.T) { ctx := context.Background() - mockWorkflowManager := mocks.MockWorkflowManager{} - mockWorkflowManager.SetCreateCallback( + mockWorkflowManager := mocks.WorkflowInterface{} + mockWorkflowManager.EXPECT().CreateWorkflow(mock.Anything, mock.Anything).RunAndReturn( func(ctx context.Context, request *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error) { return nil, errors.GetMissingEntityError(core.ResourceType_WORKFLOW.String(), request.GetId()) From 3f86dca7a7fa22513c3ba51e114e7ef11d8ec061 Mon Sep 17 00:00:00 2001 From: Alex Wu Date: Tue, 28 Jan 2025 12:28:49 +0800 Subject: [PATCH 2/4] add more mocks Signed-off-by: Alex Wu --- .../pkg/manager/mocks/metrics_interface.go | 72 ++++++++++++++----- .../pkg/manager/mocks/version_interface.go | 72 ++++++++++++++----- 2 files changed, 112 insertions(+), 32 deletions(-) diff --git a/flyteadmin/pkg/manager/mocks/metrics_interface.go b/flyteadmin/pkg/manager/mocks/metrics_interface.go index fd5ae8f34c..a098a1e062 100644 --- a/flyteadmin/pkg/manager/mocks/metrics_interface.go +++ b/flyteadmin/pkg/manager/mocks/metrics_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.1. DO NOT EDIT. +// Code generated by mockery v2.40.3. DO NOT EDIT. package mocks @@ -15,29 +15,27 @@ type MetricsInterface struct { mock.Mock } -type MetricsInterface_GetExecutionMetrics struct { - *mock.Call -} - -func (_m MetricsInterface_GetExecutionMetrics) Return(_a0 *admin.WorkflowExecutionGetMetricsResponse, _a1 error) *MetricsInterface_GetExecutionMetrics { - return &MetricsInterface_GetExecutionMetrics{Call: _m.Call.Return(_a0, _a1)} +type MetricsInterface_Expecter struct { + mock *mock.Mock } -func (_m *MetricsInterface) OnGetExecutionMetrics(ctx context.Context, request *admin.WorkflowExecutionGetMetricsRequest) *MetricsInterface_GetExecutionMetrics { - c_call := _m.On("GetExecutionMetrics", ctx, request) - return &MetricsInterface_GetExecutionMetrics{Call: c_call} -} - -func (_m *MetricsInterface) OnGetExecutionMetricsMatch(matchers ...interface{}) *MetricsInterface_GetExecutionMetrics { - c_call := _m.On("GetExecutionMetrics", matchers...) - return &MetricsInterface_GetExecutionMetrics{Call: c_call} +func (_m *MetricsInterface) EXPECT() *MetricsInterface_Expecter { + return &MetricsInterface_Expecter{mock: &_m.Mock} } // GetExecutionMetrics provides a mock function with given fields: ctx, request func (_m *MetricsInterface) GetExecutionMetrics(ctx context.Context, request *admin.WorkflowExecutionGetMetricsRequest) (*admin.WorkflowExecutionGetMetricsResponse, error) { ret := _m.Called(ctx, request) + if len(ret) == 0 { + panic("no return value specified for GetExecutionMetrics") + } + var r0 *admin.WorkflowExecutionGetMetricsResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowExecutionGetMetricsRequest) (*admin.WorkflowExecutionGetMetricsResponse, error)); ok { + return rf(ctx, request) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowExecutionGetMetricsRequest) *admin.WorkflowExecutionGetMetricsResponse); ok { r0 = rf(ctx, request) } else { @@ -46,7 +44,6 @@ func (_m *MetricsInterface) GetExecutionMetrics(ctx context.Context, request *ad } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.WorkflowExecutionGetMetricsRequest) error); ok { r1 = rf(ctx, request) } else { @@ -55,3 +52,46 @@ func (_m *MetricsInterface) GetExecutionMetrics(ctx context.Context, request *ad return r0, r1 } + +// MetricsInterface_GetExecutionMetrics_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetExecutionMetrics' +type MetricsInterface_GetExecutionMetrics_Call struct { + *mock.Call +} + +// GetExecutionMetrics is a helper method to define mock.On call +// - ctx context.Context +// - request *admin.WorkflowExecutionGetMetricsRequest +func (_e *MetricsInterface_Expecter) GetExecutionMetrics(ctx interface{}, request interface{}) *MetricsInterface_GetExecutionMetrics_Call { + return &MetricsInterface_GetExecutionMetrics_Call{Call: _e.mock.On("GetExecutionMetrics", ctx, request)} +} + +func (_c *MetricsInterface_GetExecutionMetrics_Call) Run(run func(ctx context.Context, request *admin.WorkflowExecutionGetMetricsRequest)) *MetricsInterface_GetExecutionMetrics_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.WorkflowExecutionGetMetricsRequest)) + }) + return _c +} + +func (_c *MetricsInterface_GetExecutionMetrics_Call) Return(_a0 *admin.WorkflowExecutionGetMetricsResponse, _a1 error) *MetricsInterface_GetExecutionMetrics_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MetricsInterface_GetExecutionMetrics_Call) RunAndReturn(run func(context.Context, *admin.WorkflowExecutionGetMetricsRequest) (*admin.WorkflowExecutionGetMetricsResponse, error)) *MetricsInterface_GetExecutionMetrics_Call { + _c.Call.Return(run) + return _c +} + +// NewMetricsInterface creates a new instance of MetricsInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMetricsInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *MetricsInterface { + mock := &MetricsInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/flyteadmin/pkg/manager/mocks/version_interface.go b/flyteadmin/pkg/manager/mocks/version_interface.go index 99de16b6ca..cfde799196 100644 --- a/flyteadmin/pkg/manager/mocks/version_interface.go +++ b/flyteadmin/pkg/manager/mocks/version_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v1.0.1. DO NOT EDIT. +// Code generated by mockery v2.40.3. DO NOT EDIT. package mocks @@ -15,29 +15,27 @@ type VersionInterface struct { mock.Mock } -type VersionInterface_GetVersion struct { - *mock.Call -} - -func (_m VersionInterface_GetVersion) Return(_a0 *admin.GetVersionResponse, _a1 error) *VersionInterface_GetVersion { - return &VersionInterface_GetVersion{Call: _m.Call.Return(_a0, _a1)} +type VersionInterface_Expecter struct { + mock *mock.Mock } -func (_m *VersionInterface) OnGetVersion(ctx context.Context, r *admin.GetVersionRequest) *VersionInterface_GetVersion { - c_call := _m.On("GetVersion", ctx, r) - return &VersionInterface_GetVersion{Call: c_call} -} - -func (_m *VersionInterface) OnGetVersionMatch(matchers ...interface{}) *VersionInterface_GetVersion { - c_call := _m.On("GetVersion", matchers...) - return &VersionInterface_GetVersion{Call: c_call} +func (_m *VersionInterface) EXPECT() *VersionInterface_Expecter { + return &VersionInterface_Expecter{mock: &_m.Mock} } // GetVersion provides a mock function with given fields: ctx, r func (_m *VersionInterface) GetVersion(ctx context.Context, r *admin.GetVersionRequest) (*admin.GetVersionResponse, error) { ret := _m.Called(ctx, r) + if len(ret) == 0 { + panic("no return value specified for GetVersion") + } + var r0 *admin.GetVersionResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *admin.GetVersionRequest) (*admin.GetVersionResponse, error)); ok { + return rf(ctx, r) + } if rf, ok := ret.Get(0).(func(context.Context, *admin.GetVersionRequest) *admin.GetVersionResponse); ok { r0 = rf(ctx, r) } else { @@ -46,7 +44,6 @@ func (_m *VersionInterface) GetVersion(ctx context.Context, r *admin.GetVersionR } } - var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.GetVersionRequest) error); ok { r1 = rf(ctx, r) } else { @@ -55,3 +52,46 @@ func (_m *VersionInterface) GetVersion(ctx context.Context, r *admin.GetVersionR return r0, r1 } + +// VersionInterface_GetVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetVersion' +type VersionInterface_GetVersion_Call struct { + *mock.Call +} + +// GetVersion is a helper method to define mock.On call +// - ctx context.Context +// - r *admin.GetVersionRequest +func (_e *VersionInterface_Expecter) GetVersion(ctx interface{}, r interface{}) *VersionInterface_GetVersion_Call { + return &VersionInterface_GetVersion_Call{Call: _e.mock.On("GetVersion", ctx, r)} +} + +func (_c *VersionInterface_GetVersion_Call) Run(run func(ctx context.Context, r *admin.GetVersionRequest)) *VersionInterface_GetVersion_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*admin.GetVersionRequest)) + }) + return _c +} + +func (_c *VersionInterface_GetVersion_Call) Return(_a0 *admin.GetVersionResponse, _a1 error) *VersionInterface_GetVersion_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *VersionInterface_GetVersion_Call) RunAndReturn(run func(context.Context, *admin.GetVersionRequest) (*admin.GetVersionResponse, error)) *VersionInterface_GetVersion_Call { + _c.Call.Return(run) + return _c +} + +// NewVersionInterface creates a new instance of VersionInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewVersionInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *VersionInterface { + mock := &VersionInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} From 0e69dd2315c8dfbd3300a8aeedaa90fec779199d Mon Sep 17 00:00:00 2001 From: Alex Wu Date: Tue, 28 Jan 2025 16:42:43 +0800 Subject: [PATCH 3/4] fix go generate command in interface files Signed-off-by: Alex Wu --- .../pkg/manager/interfaces/execution.go | 2 + .../pkg/manager/interfaces/launch_plan.go | 2 + .../pkg/manager/interfaces/named_entity.go | 2 + .../pkg/manager/interfaces/node_execution.go | 2 + flyteadmin/pkg/manager/interfaces/project.go | 2 + flyteadmin/pkg/manager/interfaces/resource.go | 2 +- flyteadmin/pkg/manager/interfaces/task.go | 2 + .../pkg/manager/interfaces/task_execution.go | 2 + flyteadmin/pkg/manager/interfaces/version.go | 2 +- flyteadmin/pkg/manager/interfaces/workflow.go | 2 + .../pkg/manager/mocks/metrics_interface.go | 72 +++++-------------- 11 files changed, 34 insertions(+), 58 deletions(-) diff --git a/flyteadmin/pkg/manager/interfaces/execution.go b/flyteadmin/pkg/manager/interfaces/execution.go index 9175d4a009..ad7329dff8 100644 --- a/flyteadmin/pkg/manager/interfaces/execution.go +++ b/flyteadmin/pkg/manager/interfaces/execution.go @@ -7,6 +7,8 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" ) +//go:generate mockery-v2 --name=ExecutionInterface --output=../mocks --case=underscore --with-expecter + // Interface for managing Flyte Workflow Executions type ExecutionInterface interface { CreateExecution(ctx context.Context, request *admin.ExecutionCreateRequest, requestedAt time.Time) ( diff --git a/flyteadmin/pkg/manager/interfaces/launch_plan.go b/flyteadmin/pkg/manager/interfaces/launch_plan.go index cf20a5c21d..2ad2eb4ae3 100644 --- a/flyteadmin/pkg/manager/interfaces/launch_plan.go +++ b/flyteadmin/pkg/manager/interfaces/launch_plan.go @@ -6,6 +6,8 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" ) +//go:generate mockery-v2 --name=LaunchPlanInterface --output=../mocks --case=underscore --with-expecter + // Interface for managing Flyte Launch Plans type LaunchPlanInterface interface { // Interface to create Launch Plans based on the request. diff --git a/flyteadmin/pkg/manager/interfaces/named_entity.go b/flyteadmin/pkg/manager/interfaces/named_entity.go index ae6b6bd204..1cd8085484 100644 --- a/flyteadmin/pkg/manager/interfaces/named_entity.go +++ b/flyteadmin/pkg/manager/interfaces/named_entity.go @@ -6,6 +6,8 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" ) +//go:generate mockery-v2 --name=NamedEntityInterface --output=../mocks --case=underscore --with-expecter + // Interface for managing metadata associated with NamedEntityIdentifiers type NamedEntityInterface interface { GetNamedEntity(ctx context.Context, request *admin.NamedEntityGetRequest) (*admin.NamedEntity, error) diff --git a/flyteadmin/pkg/manager/interfaces/node_execution.go b/flyteadmin/pkg/manager/interfaces/node_execution.go index ad1385709c..1c6582633f 100644 --- a/flyteadmin/pkg/manager/interfaces/node_execution.go +++ b/flyteadmin/pkg/manager/interfaces/node_execution.go @@ -6,6 +6,8 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" ) +//go:generate mockery-v2 --name=NodeExecutionInterface --output=../mocks --case=underscore --with-expecter + // Interface for managing Flyte Workflow NodeExecutions type NodeExecutionInterface interface { CreateNodeEvent(ctx context.Context, request *admin.NodeExecutionEventRequest) ( diff --git a/flyteadmin/pkg/manager/interfaces/project.go b/flyteadmin/pkg/manager/interfaces/project.go index e5f4a3cea4..6a1ac4650e 100644 --- a/flyteadmin/pkg/manager/interfaces/project.go +++ b/flyteadmin/pkg/manager/interfaces/project.go @@ -6,6 +6,8 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" ) +//go:generate mockery-v2 --name=ProjectInterface --output=../mocks --case=underscore --with-expecter + // Interface for managing projects (and domains). type ProjectInterface interface { CreateProject(ctx context.Context, request *admin.ProjectRegisterRequest) (*admin.ProjectRegisterResponse, error) diff --git a/flyteadmin/pkg/manager/interfaces/resource.go b/flyteadmin/pkg/manager/interfaces/resource.go index 3d586a59c9..a8d3598f05 100644 --- a/flyteadmin/pkg/manager/interfaces/resource.go +++ b/flyteadmin/pkg/manager/interfaces/resource.go @@ -6,7 +6,7 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" ) -//go:generate mockery -name ResourceInterface -output=../mocks -case=underscore +//go:generate mockery-v2 --name=ResourceInterface --output=../mocks --case=underscore --with-expecter // ResourceInterface manages project, domain and workflow -specific attributes. type ResourceInterface interface { diff --git a/flyteadmin/pkg/manager/interfaces/task.go b/flyteadmin/pkg/manager/interfaces/task.go index 5143a29c42..4a975faf6a 100644 --- a/flyteadmin/pkg/manager/interfaces/task.go +++ b/flyteadmin/pkg/manager/interfaces/task.go @@ -6,6 +6,8 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" ) +//go:generate mockery-v2 --name=TaskInterface --output=../mocks --case=underscore --with-expecter + // Interface for managing Flyte Tasks type TaskInterface interface { CreateTask(ctx context.Context, request *admin.TaskCreateRequest) (*admin.TaskCreateResponse, error) diff --git a/flyteadmin/pkg/manager/interfaces/task_execution.go b/flyteadmin/pkg/manager/interfaces/task_execution.go index 091189ba65..a6145d2156 100644 --- a/flyteadmin/pkg/manager/interfaces/task_execution.go +++ b/flyteadmin/pkg/manager/interfaces/task_execution.go @@ -6,6 +6,8 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" ) +//go:generate mockery-v2 --name=TaskExecutionInterface --output=../mocks --case=underscore --with-expecter + // Interface for managing Flyte Workflow TaskExecutions type TaskExecutionInterface interface { CreateTaskExecutionEvent(ctx context.Context, request *admin.TaskExecutionEventRequest) ( diff --git a/flyteadmin/pkg/manager/interfaces/version.go b/flyteadmin/pkg/manager/interfaces/version.go index e4652c29f8..5c3955a763 100644 --- a/flyteadmin/pkg/manager/interfaces/version.go +++ b/flyteadmin/pkg/manager/interfaces/version.go @@ -6,7 +6,7 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" ) -//go:generate mockery -name VersionInterface -output=../mocks -case=underscore +//go:generate mockery-v2 --name=VersionInterface --output=../mocks --case=underscore --with-expecter // Interface for managing Flyte admin version type VersionInterface interface { diff --git a/flyteadmin/pkg/manager/interfaces/workflow.go b/flyteadmin/pkg/manager/interfaces/workflow.go index 66382bd667..0a97aed820 100644 --- a/flyteadmin/pkg/manager/interfaces/workflow.go +++ b/flyteadmin/pkg/manager/interfaces/workflow.go @@ -6,6 +6,8 @@ import ( "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin" ) +//go:generate mockery-v2 --name=WorkflowInterface --output=../mocks --case=underscore --with-expecter + // Interface for managing Flyte Workflows type WorkflowInterface interface { CreateWorkflow(ctx context.Context, request *admin.WorkflowCreateRequest) (*admin.WorkflowCreateResponse, error) diff --git a/flyteadmin/pkg/manager/mocks/metrics_interface.go b/flyteadmin/pkg/manager/mocks/metrics_interface.go index a098a1e062..fd5ae8f34c 100644 --- a/flyteadmin/pkg/manager/mocks/metrics_interface.go +++ b/flyteadmin/pkg/manager/mocks/metrics_interface.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.40.3. DO NOT EDIT. +// Code generated by mockery v1.0.1. DO NOT EDIT. package mocks @@ -15,27 +15,29 @@ type MetricsInterface struct { mock.Mock } -type MetricsInterface_Expecter struct { - mock *mock.Mock +type MetricsInterface_GetExecutionMetrics struct { + *mock.Call +} + +func (_m MetricsInterface_GetExecutionMetrics) Return(_a0 *admin.WorkflowExecutionGetMetricsResponse, _a1 error) *MetricsInterface_GetExecutionMetrics { + return &MetricsInterface_GetExecutionMetrics{Call: _m.Call.Return(_a0, _a1)} } -func (_m *MetricsInterface) EXPECT() *MetricsInterface_Expecter { - return &MetricsInterface_Expecter{mock: &_m.Mock} +func (_m *MetricsInterface) OnGetExecutionMetrics(ctx context.Context, request *admin.WorkflowExecutionGetMetricsRequest) *MetricsInterface_GetExecutionMetrics { + c_call := _m.On("GetExecutionMetrics", ctx, request) + return &MetricsInterface_GetExecutionMetrics{Call: c_call} +} + +func (_m *MetricsInterface) OnGetExecutionMetricsMatch(matchers ...interface{}) *MetricsInterface_GetExecutionMetrics { + c_call := _m.On("GetExecutionMetrics", matchers...) + return &MetricsInterface_GetExecutionMetrics{Call: c_call} } // GetExecutionMetrics provides a mock function with given fields: ctx, request func (_m *MetricsInterface) GetExecutionMetrics(ctx context.Context, request *admin.WorkflowExecutionGetMetricsRequest) (*admin.WorkflowExecutionGetMetricsResponse, error) { ret := _m.Called(ctx, request) - if len(ret) == 0 { - panic("no return value specified for GetExecutionMetrics") - } - var r0 *admin.WorkflowExecutionGetMetricsResponse - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowExecutionGetMetricsRequest) (*admin.WorkflowExecutionGetMetricsResponse, error)); ok { - return rf(ctx, request) - } if rf, ok := ret.Get(0).(func(context.Context, *admin.WorkflowExecutionGetMetricsRequest) *admin.WorkflowExecutionGetMetricsResponse); ok { r0 = rf(ctx, request) } else { @@ -44,6 +46,7 @@ func (_m *MetricsInterface) GetExecutionMetrics(ctx context.Context, request *ad } } + var r1 error if rf, ok := ret.Get(1).(func(context.Context, *admin.WorkflowExecutionGetMetricsRequest) error); ok { r1 = rf(ctx, request) } else { @@ -52,46 +55,3 @@ func (_m *MetricsInterface) GetExecutionMetrics(ctx context.Context, request *ad return r0, r1 } - -// MetricsInterface_GetExecutionMetrics_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetExecutionMetrics' -type MetricsInterface_GetExecutionMetrics_Call struct { - *mock.Call -} - -// GetExecutionMetrics is a helper method to define mock.On call -// - ctx context.Context -// - request *admin.WorkflowExecutionGetMetricsRequest -func (_e *MetricsInterface_Expecter) GetExecutionMetrics(ctx interface{}, request interface{}) *MetricsInterface_GetExecutionMetrics_Call { - return &MetricsInterface_GetExecutionMetrics_Call{Call: _e.mock.On("GetExecutionMetrics", ctx, request)} -} - -func (_c *MetricsInterface_GetExecutionMetrics_Call) Run(run func(ctx context.Context, request *admin.WorkflowExecutionGetMetricsRequest)) *MetricsInterface_GetExecutionMetrics_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*admin.WorkflowExecutionGetMetricsRequest)) - }) - return _c -} - -func (_c *MetricsInterface_GetExecutionMetrics_Call) Return(_a0 *admin.WorkflowExecutionGetMetricsResponse, _a1 error) *MetricsInterface_GetExecutionMetrics_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MetricsInterface_GetExecutionMetrics_Call) RunAndReturn(run func(context.Context, *admin.WorkflowExecutionGetMetricsRequest) (*admin.WorkflowExecutionGetMetricsResponse, error)) *MetricsInterface_GetExecutionMetrics_Call { - _c.Call.Return(run) - return _c -} - -// NewMetricsInterface creates a new instance of MetricsInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewMetricsInterface(t interface { - mock.TestingT - Cleanup(func()) -}) *MetricsInterface { - mock := &MetricsInterface{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} From db6e5cfbeccf070fcd8e616946a2bd17694fb16e Mon Sep 17 00:00:00 2001 From: Alex Wu Date: Tue, 28 Jan 2025 17:16:46 +0800 Subject: [PATCH 4/4] minor fix Signed-off-by: Alex Wu --- flyteadmin/pkg/manager/impl/execution_manager_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/flyteadmin/pkg/manager/impl/execution_manager_test.go b/flyteadmin/pkg/manager/impl/execution_manager_test.go index aba22839db..0414e9e9c8 100644 --- a/flyteadmin/pkg/manager/impl/execution_manager_test.go +++ b/flyteadmin/pkg/manager/impl/execution_manager_test.go @@ -5024,10 +5024,6 @@ func TestGetExecutionConfigOverrides(t *testing.T) { }) t.Run("matchable resource failure", func(t *testing.T) { resourceManager.ExpectedCalls = nil - executionManager := ExecutionManager{ - resourceManager: &resourceManager, - config: applicationConfig, - } resourceManager.EXPECT().GetResource(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, request managerInterfaces.ResourceRequest) (*managerInterfaces.ResourceResponse, error) { assert.Contains(t, []managerInterfaces.ResourceRequest{{