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
/
Copy pathnamed_entity_metadata_repo.go
67 lines (56 loc) · 1.99 KB
/
named_entity_metadata_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
// 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 GetNamedEntityFunc func(input interfaces.GetNamedEntityInput) (models.NamedEntity, error)
type ListNamedEntityFunc func(input interfaces.ListNamedEntityInput) (interfaces.NamedEntityCollectionOutput, error)
type UpdateNamedEntityFunc func(input models.NamedEntity) error
type MockNamedEntityRepo struct {
getFunction GetNamedEntityFunc
listFunction ListNamedEntityFunc
updateFunction UpdateNamedEntityFunc
}
func (r *MockNamedEntityRepo) Update(ctx context.Context, NamedEntity models.NamedEntity) error {
if r.updateFunction != nil {
return r.updateFunction(NamedEntity)
}
return nil
}
func (r *MockNamedEntityRepo) Get(
ctx context.Context, input interfaces.GetNamedEntityInput) (models.NamedEntity, error) {
if r.getFunction != nil {
return r.getFunction(input)
}
return models.NamedEntity{
NamedEntityKey: models.NamedEntityKey{
ResourceType: input.ResourceType,
Project: input.Project,
Domain: input.Domain,
Name: input.Name,
},
NamedEntityMetadataFields: models.NamedEntityMetadataFields{
Description: "",
},
}, nil
}
func (r *MockNamedEntityRepo) List(ctx context.Context, input interfaces.ListNamedEntityInput) (interfaces.NamedEntityCollectionOutput, error) {
if r.listFunction != nil {
return r.listFunction(input)
}
return interfaces.NamedEntityCollectionOutput{}, nil
}
func (r *MockNamedEntityRepo) SetGetCallback(getFunction GetNamedEntityFunc) {
r.getFunction = getFunction
}
func (r *MockNamedEntityRepo) SetListCallback(listFunction ListNamedEntityFunc) {
r.listFunction = listFunction
}
func (r *MockNamedEntityRepo) SetUpdateCallback(updateFunction UpdateNamedEntityFunc) {
r.updateFunction = updateFunction
}
func NewMockNamedEntityRepo() interfaces.NamedEntityRepoInterface {
return &MockNamedEntityRepo{}
}