This repository has been archived by the owner on Dec 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
test_helpers.go
113 lines (86 loc) · 3.05 KB
/
test_helpers.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package workspace
import (
"context"
"github.com/leg100/otf/internal"
"github.com/leg100/otf/internal/rbac"
"github.com/leg100/otf/internal/resource"
"github.com/leg100/otf/internal/team"
"github.com/leg100/otf/internal/vcs"
"github.com/leg100/otf/internal/vcsprovider"
)
type FakeService struct {
Workspaces []*Workspace
Policy internal.WorkspacePolicy
}
func (f *FakeService) ListConnectedWorkspaces(ctx context.Context, vcsProviderID, repoPath string) ([]*Workspace, error) {
return f.Workspaces, nil
}
func (f *FakeService) Create(context.Context, CreateOptions) (*Workspace, error) {
return f.Workspaces[0], nil
}
func (f *FakeService) Update(_ context.Context, _ string, opts UpdateOptions) (*Workspace, error) {
f.Workspaces[0].Update(opts)
return f.Workspaces[0], nil
}
func (f *FakeService) List(ctx context.Context, opts ListOptions) (*resource.Page[*Workspace], error) {
return resource.NewPage(f.Workspaces, opts.PageOptions, nil), nil
}
func (f *FakeService) Get(context.Context, string) (*Workspace, error) {
return f.Workspaces[0], nil
}
func (f *FakeService) GetByName(context.Context, string, string) (*Workspace, error) {
return f.Workspaces[0], nil
}
func (f *FakeService) Delete(context.Context, string) (*Workspace, error) {
return f.Workspaces[0], nil
}
func (f *FakeService) Lock(context.Context, string, *string) (*Workspace, error) {
return f.Workspaces[0], nil
}
func (f *FakeService) Unlock(context.Context, string, *string, bool) (*Workspace, error) {
return f.Workspaces[0], nil
}
func (f *FakeService) ListTags(context.Context, string, ListTagsOptions) (*resource.Page[*Tag], error) {
return nil, nil
}
func (f *FakeService) GetPolicy(context.Context, string) (internal.WorkspacePolicy, error) {
return f.Policy, nil
}
func (f *FakeService) AddTags(ctx context.Context, workspaceID string, tags []TagSpec) error {
return nil
}
func (f *FakeService) RemoveTags(ctx context.Context, workspaceID string, tags []TagSpec) error {
return nil
}
func (f *FakeService) SetPermission(ctx context.Context, workspaceID, teamID string, role rbac.Role) error {
return nil
}
func (f *FakeService) UnsetPermission(ctx context.Context, workspaceID, teamID string) error {
return nil
}
type fakeVCSProviderService struct {
providers []*vcsprovider.VCSProvider
repos []string
}
func (f *fakeVCSProviderService) Get(ctx context.Context, providerID string) (*vcsprovider.VCSProvider, error) {
return f.providers[0], nil
}
func (f *fakeVCSProviderService) List(context.Context, string) ([]*vcsprovider.VCSProvider, error) {
return f.providers, nil
}
func (f *fakeVCSProviderService) GetVCSClient(ctx context.Context, providerID string) (vcs.Client, error) {
return &fakeVCSClient{repos: f.repos}, nil
}
type fakeVCSClient struct {
repos []string
vcs.Client
}
func (f *fakeVCSClient) ListRepositories(ctx context.Context, opts vcs.ListRepositoriesOptions) ([]string, error) {
return f.repos, nil
}
type fakeTeamService struct {
teams []*team.Team
}
func (f *fakeTeamService) List(context.Context, string) ([]*team.Team, error) {
return f.teams, nil
}