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_compiler.go
62 lines (53 loc) · 2.28 KB
/
mock_compiler.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
56
57
58
59
60
61
62
package mocks
import (
"github.com/flyteorg/flyteadmin/pkg/workflowengine/interfaces"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"github.com/flyteorg/flytepropeller/pkg/compiler"
"github.com/flyteorg/flytepropeller/pkg/compiler/common"
)
type MockCompiler struct {
compileTaskCallback func(task *core.TaskTemplate) (*core.CompiledTask, error)
getRequirementsCallback func(fg *core.WorkflowTemplate, subWfs []*core.WorkflowTemplate) (
reqs compiler.WorkflowExecutionRequirements, err error)
compileWorkflowCallback func(
primaryWf *core.WorkflowTemplate, subworkflows []*core.WorkflowTemplate, tasks []*core.CompiledTask,
launchPlans []common.InterfaceProvider) (*core.CompiledWorkflowClosure, error)
}
func (c *MockCompiler) CompileTask(task *core.TaskTemplate) (*core.CompiledTask, error) {
if c.compileTaskCallback != nil {
return c.compileTaskCallback(task)
}
return nil, nil
}
func (c *MockCompiler) AddCompileTaskCallback(
callback func(task *core.TaskTemplate) (*core.CompiledTask, error)) {
c.compileTaskCallback = callback
}
func (c *MockCompiler) GetRequirements(fg *core.WorkflowTemplate, subWfs []*core.WorkflowTemplate) (
reqs compiler.WorkflowExecutionRequirements, err error) {
if c.getRequirementsCallback != nil {
return c.getRequirementsCallback(fg, subWfs)
}
return compiler.WorkflowExecutionRequirements{}, nil
}
func (c *MockCompiler) AddGetRequirementCallback(
callback func(fg *core.WorkflowTemplate, subWfs []*core.WorkflowTemplate) (
reqs compiler.WorkflowExecutionRequirements, err error)) {
c.getRequirementsCallback = callback
}
func (c *MockCompiler) CompileWorkflow(
primaryWf *core.WorkflowTemplate, subworkflows []*core.WorkflowTemplate, tasks []*core.CompiledTask,
launchPlans []common.InterfaceProvider) (*core.CompiledWorkflowClosure, error) {
if c.compileWorkflowCallback != nil {
return c.compileWorkflowCallback(primaryWf, subworkflows, tasks, launchPlans)
}
return nil, nil
}
func (c *MockCompiler) AddCompileWorkflowCallback(callback func(
primaryWf *core.WorkflowTemplate, subworkflows []*core.WorkflowTemplate, tasks []*core.CompiledTask,
launchPlans []common.InterfaceProvider) (*core.CompiledWorkflowClosure, error)) {
c.compileWorkflowCallback = callback
}
func NewMockCompiler() interfaces.Compiler {
return &MockCompiler{}
}