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 62
/
description_entity_repo.go
66 lines (55 loc) · 2.17 KB
/
description_entity_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
// 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 CreateDescriptionEntityFunc func(input models.DescriptionEntity) error
type GetDescriptionEntityFunc func(input interfaces.GetDescriptionEntityInput) (models.DescriptionEntity, error)
type ListDescriptionEntityFunc func(input interfaces.ListResourceInput) (interfaces.DescriptionEntityCollectionOutput, error)
type MockDescriptionEntityRepo struct {
createFunction CreateDescriptionEntityFunc
getFunction GetDescriptionEntityFunc
listFunction ListDescriptionEntityFunc
}
func (r *MockDescriptionEntityRepo) Create(ctx context.Context, DescriptionEntity models.DescriptionEntity) (uint, error) {
if r.createFunction != nil {
return 1, r.createFunction(DescriptionEntity)
}
return 1, nil
}
func (r *MockDescriptionEntityRepo) Get(
ctx context.Context, input interfaces.GetDescriptionEntityInput) (models.DescriptionEntity, error) {
if r.getFunction != nil {
return r.getFunction(input)
}
return models.DescriptionEntity{
DescriptionEntityKey: models.DescriptionEntityKey{
ResourceType: input.ResourceType,
Project: input.Project,
Domain: input.Domain,
Name: input.Name,
Version: input.Version,
},
ShortDescription: "hello world",
}, nil
}
func (r *MockDescriptionEntityRepo) List(ctx context.Context, input interfaces.ListResourceInput) (interfaces.DescriptionEntityCollectionOutput, error) {
if r.listFunction != nil {
return r.listFunction(input)
}
return interfaces.DescriptionEntityCollectionOutput{}, nil
}
func (r *MockDescriptionEntityRepo) SetCreateCallback(createFunction CreateDescriptionEntityFunc) {
r.createFunction = createFunction
}
func (r *MockDescriptionEntityRepo) SetGetCallback(getFunction GetDescriptionEntityFunc) {
r.getFunction = getFunction
}
func (r *MockDescriptionEntityRepo) SetListCallback(listFunction ListDescriptionEntityFunc) {
r.listFunction = listFunction
}
func NewMockDescriptionEntityRepo() interfaces.DescriptionEntityRepoInterface {
return &MockDescriptionEntityRepo{}
}