This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
mock_executor.go
55 lines (44 loc) · 1.77 KB
/
mock_executor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package mocks
import (
"context"
"github.com/flyteorg/flyteadmin/pkg/workflowengine/interfaces"
)
type ExecuteWorkflowFunc func(input interfaces.ExecuteWorkflowInput) (*interfaces.ExecutionInfo, error)
type ExecuteTaskFunc func(ctx context.Context, input interfaces.ExecuteTaskInput) (*interfaces.ExecutionInfo, error)
type TerminateWorkflowExecutionFunc func(ctx context.Context, input interfaces.TerminateWorkflowInput) error
type MockExecutor struct {
executeWorkflowCallback ExecuteWorkflowFunc
executeTaskCallback ExecuteTaskFunc
terminateExecutionCallback TerminateWorkflowExecutionFunc
}
func (c *MockExecutor) SetExecuteWorkflowCallback(callback ExecuteWorkflowFunc) {
c.executeWorkflowCallback = callback
}
func (c *MockExecutor) ExecuteWorkflow(
ctx context.Context, inputs interfaces.ExecuteWorkflowInput) (*interfaces.ExecutionInfo, error) {
if c.executeWorkflowCallback != nil {
return c.executeWorkflowCallback(inputs)
}
return &interfaces.ExecutionInfo{}, nil
}
func (c *MockExecutor) SetExecuteTaskCallback(callback ExecuteTaskFunc) {
c.executeTaskCallback = callback
}
func (c *MockExecutor) ExecuteTask(ctx context.Context, input interfaces.ExecuteTaskInput) (*interfaces.ExecutionInfo, error) {
if c.executeTaskCallback != nil {
return c.executeTaskCallback(ctx, input)
}
return &interfaces.ExecutionInfo{}, nil
}
func (c *MockExecutor) SetTerminateExecutionCallback(callback TerminateWorkflowExecutionFunc) {
c.terminateExecutionCallback = callback
}
func (c *MockExecutor) TerminateWorkflowExecution(ctx context.Context, input interfaces.TerminateWorkflowInput) error {
if c.terminateExecutionCallback != nil {
return c.terminateExecutionCallback(ctx, input)
}
return nil
}
func NewMockExecutor() interfaces.Executor {
return &MockExecutor{}
}