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
/
task_repo.go
79 lines (65 loc) · 2.25 KB
/
task_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
// Mock implementation of a task 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 CreateTaskFunc func(input models.Task) error
type GetTaskFunc func(input interfaces.Identifier) (models.Task, error)
type ListTaskFunc func(input interfaces.ListResourceInput) (interfaces.TaskCollectionOutput, error)
type ListTaskIdentifiersFunc func(input interfaces.ListResourceInput) (interfaces.TaskCollectionOutput, error)
type MockTaskRepo struct {
createFunction CreateTaskFunc
getFunction GetTaskFunc
listFunction ListTaskFunc
listUniqueTaskIdsFunction ListTaskIdentifiersFunc
}
func (r *MockTaskRepo) Create(ctx context.Context, input models.Task) error {
if r.createFunction != nil {
return r.createFunction(input)
}
return nil
}
func (r *MockTaskRepo) SetCreateCallback(createFunction CreateTaskFunc) {
r.createFunction = createFunction
}
func (r *MockTaskRepo) Get(ctx context.Context, input interfaces.Identifier) (models.Task, error) {
if r.getFunction != nil {
return r.getFunction(input)
}
return models.Task{
TaskKey: models.TaskKey{
Project: input.Project,
Domain: input.Domain,
Name: input.Name,
Version: input.Version,
},
}, nil
}
func (r *MockTaskRepo) SetGetCallback(getFunction GetTaskFunc) {
r.getFunction = getFunction
}
func (r *MockTaskRepo) List(
ctx context.Context, input interfaces.ListResourceInput) (interfaces.TaskCollectionOutput, error) {
if r.listFunction != nil {
return r.listFunction(input)
}
return interfaces.TaskCollectionOutput{}, nil
}
func (r *MockTaskRepo) SetListCallback(listFunction ListTaskFunc) {
r.listFunction = listFunction
}
func (r *MockTaskRepo) ListTaskIdentifiers(ctx context.Context, input interfaces.ListResourceInput) (
interfaces.TaskCollectionOutput, error) {
if r.listUniqueTaskIdsFunction != nil {
return r.listUniqueTaskIdsFunction(input)
}
return interfaces.TaskCollectionOutput{}, nil
}
func (r *MockTaskRepo) SetListTaskIdentifiersCallback(listFunction ListTaskIdentifiersFunc) {
r.listUniqueTaskIdsFunction = listFunction
}
func NewMockTaskRepo() interfaces.TaskRepoInterface {
return &MockTaskRepo{}
}