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
/
workflow_repo.go
80 lines (65 loc) · 2.3 KB
/
workflow_repo.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Mock implementation of a workflow repo to be used for tests.
package mocks
import (
"context"
"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
"github.com/flyteorg/flyteadmin/pkg/repositories/models"
)
type CreateWorkflowFunc func(input models.Workflow) error
type GetWorkflowFunc func(input interfaces.Identifier) (models.Workflow, error)
type ListWorkflowFunc func(input interfaces.ListResourceInput) (interfaces.WorkflowCollectionOutput, error)
type ListIdentifiersFunc func(input interfaces.ListResourceInput) (interfaces.WorkflowCollectionOutput, error)
type MockWorkflowRepo struct {
createFunction CreateWorkflowFunc
getFunction GetWorkflowFunc
listFunction ListWorkflowFunc
listIdentifiersFunc ListIdentifiersFunc
}
func (r *MockWorkflowRepo) Create(ctx context.Context, input models.Workflow) error {
if r.createFunction != nil {
return r.createFunction(input)
}
return nil
}
func (r *MockWorkflowRepo) SetCreateCallback(createFunction CreateWorkflowFunc) {
r.createFunction = createFunction
}
func (r *MockWorkflowRepo) Get(ctx context.Context, input interfaces.Identifier) (models.Workflow, error) {
if r.getFunction != nil {
return r.getFunction(input)
}
return models.Workflow{
WorkflowKey: models.WorkflowKey{
Project: input.Project,
Domain: input.Domain,
Name: input.Name,
Version: input.Version,
},
}, nil
}
func (r *MockWorkflowRepo) SetGetCallback(getFunction GetWorkflowFunc) {
r.getFunction = getFunction
}
func (r *MockWorkflowRepo) List(
ctx context.Context, input interfaces.ListResourceInput) (interfaces.WorkflowCollectionOutput, error) {
if r.listFunction != nil {
return r.listFunction(input)
}
return interfaces.WorkflowCollectionOutput{}, nil
}
func (r *MockWorkflowRepo) SetListCallback(listFunction ListWorkflowFunc) {
r.listFunction = listFunction
}
func (r *MockWorkflowRepo) SetListIdentifiersFunc(fn ListIdentifiersFunc) {
r.listIdentifiersFunc = fn
}
func (r *MockWorkflowRepo) ListIdentifiers(ctx context.Context, input interfaces.ListResourceInput) (
interfaces.WorkflowCollectionOutput, error) {
if r.listIdentifiersFunc != nil {
return r.listIdentifiersFunc(input)
}
return interfaces.WorkflowCollectionOutput{}, nil
}
func NewMockWorkflowRepo() interfaces.WorkflowRepoInterface {
return &MockWorkflowRepo{}
}