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
/
resource.go
70 lines (59 loc) · 2.03 KB
/
resource.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
package mocks
import (
"context"
"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
"github.com/flyteorg/flyteadmin/pkg/repositories/models"
)
type CreateOrUpdateResourceFunction func(ctx context.Context, input models.Resource) error
type GetResourceFunction func(ctx context.Context, ID interfaces.ResourceID) (
models.Resource, error)
type ListAllResourcesFunction func(ctx context.Context, resourceType string) ([]models.Resource, error)
type DeleteResourceFunction func(ctx context.Context, ID interfaces.ResourceID) error
type MockResourceRepo struct {
CreateOrUpdateFunction CreateOrUpdateResourceFunction
GetFunction GetResourceFunction
DeleteFunction DeleteResourceFunction
ListAllFunction ListAllResourcesFunction
}
func (r *MockResourceRepo) CreateOrUpdate(ctx context.Context, input models.Resource) error {
if r.CreateOrUpdateFunction != nil {
return r.CreateOrUpdateFunction(ctx, input)
}
return nil
}
func (r *MockResourceRepo) Get(ctx context.Context, ID interfaces.ResourceID) (
models.Resource, error) {
if r.GetFunction != nil {
return r.GetFunction(ctx, ID)
}
return models.Resource{}, nil
}
func (r *MockResourceRepo) GetRaw(ctx context.Context, ID interfaces.ResourceID) (
models.Resource, error) {
if r.GetFunction != nil {
return r.GetFunction(ctx, ID)
}
return models.Resource{}, nil
}
func (r *MockResourceRepo) GetProjectLevel(ctx context.Context, ID interfaces.ResourceID) (
models.Resource, error) {
if r.GetFunction != nil {
return r.GetFunction(ctx, ID)
}
return models.Resource{}, nil
}
func (r *MockResourceRepo) ListAll(ctx context.Context, resourceType string) ([]models.Resource, error) {
if r.ListAllFunction != nil {
return r.ListAllFunction(ctx, resourceType)
}
return []models.Resource{}, nil
}
func (r *MockResourceRepo) Delete(ctx context.Context, ID interfaces.ResourceID) error {
if r.DeleteFunction != nil {
return r.DeleteFunction(ctx, ID)
}
return nil
}
func NewMockResourceRepo() interfaces.ResourceRepoInterface {
return &MockResourceRepo{}
}