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
/
project_repo.go
57 lines (48 loc) · 1.77 KB
/
project_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
package mocks
import (
"context"
"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
"github.com/flyteorg/flyteadmin/pkg/repositories/models"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
)
type CreateProjectFunction func(ctx context.Context, project models.Project) error
type GetProjectFunction func(ctx context.Context, projectID string) (models.Project, error)
type ListProjectsFunction func(ctx context.Context, input interfaces.ListResourceInput) ([]models.Project, error)
type UpdateProjectFunction func(ctx context.Context, projectUpdate models.Project) error
type MockProjectRepo struct {
CreateFunction CreateProjectFunction
GetFunction GetProjectFunction
ListProjectsFunction ListProjectsFunction
UpdateProjectFunction UpdateProjectFunction
}
func (r *MockProjectRepo) Create(ctx context.Context, project models.Project) error {
if r.CreateFunction != nil {
return r.CreateFunction(ctx, project)
}
return nil
}
func (r *MockProjectRepo) Get(ctx context.Context, projectID string) (models.Project, error) {
if r.GetFunction != nil {
return r.GetFunction(ctx, projectID)
}
activeState := int32(admin.Project_ACTIVE)
return models.Project{
Identifier: projectID,
State: &activeState,
}, nil
}
func (r *MockProjectRepo) List(ctx context.Context, input interfaces.ListResourceInput) ([]models.Project, error) {
if r.ListProjectsFunction != nil {
return r.ListProjectsFunction(ctx, input)
}
return make([]models.Project, 0), nil
}
func (r *MockProjectRepo) UpdateProject(ctx context.Context, projectUpdate models.Project) error {
if r.UpdateProjectFunction != nil {
return r.UpdateProjectFunction(ctx, projectUpdate)
}
return nil
}
func NewMockProjectRepo() interfaces.ProjectRepoInterface {
return &MockProjectRepo{}
}