/
custom_db_roles.go
75 lines (53 loc) · 2.67 KB
/
custom_db_roles.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
package atlas
import (
"context"
"fmt"
"go.mongodb.org/atlas/mongodbatlas"
)
type CustomRolesClientMock struct {
ListFunc func(projectID string) (*[]mongodbatlas.CustomDBRole, *mongodbatlas.Response, error)
ListRequests map[string]struct{}
GetFunc func(projectID string, customRoleID string) (*mongodbatlas.CustomDBRole, *mongodbatlas.Response, error)
GetRequests map[string]struct{}
CreateFunc func(projectID string, customRole *mongodbatlas.CustomDBRole) (*mongodbatlas.CustomDBRole, *mongodbatlas.Response, error)
CreateRequests map[string]*mongodbatlas.CustomDBRole
UpdateFunc func(projectID string, customRoleID string, customRole *mongodbatlas.CustomDBRole) (*mongodbatlas.CustomDBRole, *mongodbatlas.Response, error)
UpdateRequests map[string]*mongodbatlas.CustomDBRole
DeleteFunc func(projectID string, customRoleID string) (*mongodbatlas.Response, error)
DeleteRequests map[string]struct{}
}
func (c *CustomRolesClientMock) List(_ context.Context, projectID string, _ *mongodbatlas.ListOptions) (*[]mongodbatlas.CustomDBRole, *mongodbatlas.Response, error) {
if c.ListRequests == nil {
c.ListRequests = map[string]struct{}{}
}
c.ListRequests[projectID] = struct{}{}
return c.ListFunc(projectID)
}
func (c *CustomRolesClientMock) Get(_ context.Context, projectID string, customRoleID string) (*mongodbatlas.CustomDBRole, *mongodbatlas.Response, error) {
if c.GetRequests == nil {
c.GetRequests = map[string]struct{}{}
}
c.GetRequests[fmt.Sprintf("%s.%s", projectID, customRoleID)] = struct{}{}
return c.GetFunc(projectID, customRoleID)
}
func (c *CustomRolesClientMock) Create(_ context.Context, projectID string, customRole *mongodbatlas.CustomDBRole) (*mongodbatlas.CustomDBRole, *mongodbatlas.Response, error) {
if c.CreateRequests == nil {
c.CreateRequests = map[string]*mongodbatlas.CustomDBRole{}
}
c.CreateRequests[projectID] = customRole
return c.CreateFunc(projectID, customRole)
}
func (c *CustomRolesClientMock) Update(_ context.Context, projectID string, customRoleID string, customRole *mongodbatlas.CustomDBRole) (*mongodbatlas.CustomDBRole, *mongodbatlas.Response, error) {
if c.UpdateRequests == nil {
c.UpdateRequests = map[string]*mongodbatlas.CustomDBRole{}
}
c.UpdateRequests[fmt.Sprintf("%s.%s", projectID, customRoleID)] = customRole
return c.UpdateFunc(projectID, customRoleID, customRole)
}
func (c *CustomRolesClientMock) Delete(_ context.Context, projectID string, customRoleID string) (*mongodbatlas.Response, error) {
if c.DeleteRequests == nil {
c.DeleteRequests = map[string]struct{}{}
}
c.DeleteRequests[fmt.Sprintf("%s.%s", projectID, customRoleID)] = struct{}{}
return c.DeleteFunc(projectID, customRoleID)
}