Restore mock files and adjust failing tests

This commit is contained in:
Juan Pablo Villafáñez
2022-01-13 09:33:49 +01:00
parent 7bfb6c7d3e
commit b62c9044af
6 changed files with 323 additions and 44 deletions
@@ -0,0 +1,90 @@
package v1
import (
context "context"
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
client "go-micro.dev/v4/client"
empty "google.golang.org/protobuf/types/known/emptypb"
)
// MockAccountsService can be used to write tests
/*
To create a mock overwrite the functions of an instance like this:
```go
func mockAccSvc(retErr bool) proto.AccountsService {
if retErr {
return &proto.MockAccountsService{
ListFunc: func(ctx context.Context, in *proto.ListAccountsRequest, opts ...client.CallOption) (out *proto.ListAccountsResponse, err error) {
return nil, fmt.Errorf("error returned by mockAccountsService LIST")
},
}
}
return &proto.MockAccountsService{
ListFunc: func(ctx context.Context, in *proto.ListAccountsRequest, opts ...client.CallOption) (out *proto.ListAccountsResponse, err error) {
return &proto.ListAccountsResponse{
Accounts: []*proto.Account{
{
Id: "yay",
},
},
}, nil
},
}
}
```
*/
type MockAccountsService struct {
ListFunc func(ctx context.Context, in *ListAccountsRequest, opts ...client.CallOption) (*ListAccountsResponse, error)
GetFunc func(ctx context.Context, in *GetAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error)
CreateFunc func(ctx context.Context, in *CreateAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error)
UpdateFunc func(ctx context.Context, in *UpdateAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error)
DeleteFunc func(ctx context.Context, in *DeleteAccountRequest, opts ...client.CallOption) (*empty.Empty, error)
}
// ListAccounts will panic if the function has been called, but not mocked
func (m MockAccountsService) ListAccounts(ctx context.Context, in *ListAccountsRequest, opts ...client.CallOption) (*ListAccountsResponse, error) {
if m.ListFunc != nil {
return m.ListFunc(ctx, in, opts...)
}
panic("ListFunc was called in test but not mocked")
}
// GetAccount will panic if the function has been called, but not mocked
func (m MockAccountsService) GetAccount(ctx context.Context, in *GetAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error) {
if m.GetFunc != nil {
return m.GetFunc(ctx, in, opts...)
}
panic("GetFunc was called in test but not mocked")
}
// CreateAccount will panic if the function has been called, but not mocked
func (m MockAccountsService) CreateAccount(ctx context.Context, in *CreateAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error) {
if m.CreateFunc != nil {
return m.CreateFunc(ctx, in, opts...)
}
panic("CreateFunc was called in test but not mocked")
}
// UpdateAccount will panic if the function has been called, but not mocked
func (m MockAccountsService) UpdateAccount(ctx context.Context, in *UpdateAccountRequest, opts ...client.CallOption) (*accountsmsg.Account, error) {
if m.UpdateFunc != nil {
return m.UpdateFunc(ctx, in, opts...)
}
panic("UpdateFunc was called in test but not mocked")
}
// DeleteAccount will panic if the function has been called, but not mocked
func (m MockAccountsService) DeleteAccount(ctx context.Context, in *DeleteAccountRequest, opts ...client.CallOption) (*empty.Empty, error) {
if m.DeleteFunc != nil {
return m.DeleteFunc(ctx, in, opts...)
}
panic("DeleteFunc was called in test but not mocked")
}
@@ -0,0 +1,186 @@
package v1
import (
"context"
"go-micro.dev/v4/client"
"google.golang.org/protobuf/types/known/emptypb"
)
// MockBundleService can be used to write tests against the bundle service.
/*
To create a mock overwrite the functions of an instance like this:
```go
func mockBundleSvc(returnErr bool) proto.BundleService {
if returnErr {
return &proto.MockBundleService{
ListBundlesFunc: func(ctx context.Context, in *proto.ListBundlesRequest, opts ...client.CallOption) (out *proto.ListBundlesResponse, err error) {
return nil, fmt.Errorf("error returned by mockBundleSvc LIST")
},
}
}
return &proto.MockBundleService{
ListBundlesFunc: func(ctx context.Context, in *proto.ListBundlesRequest, opts ...client.CallOption) (out *proto.ListBundlesResponse, err error) {
return &proto.ListBundlesResponse{
Bundles: []*proto.Bundle{
{
Id: "hello-there",
},
},
}, nil
},
}
}
```
*/
type MockBundleService struct {
ListBundlesFunc func(ctx context.Context, req *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error)
GetBundleFunc func(ctx context.Context, req *GetBundleRequest, opts ...client.CallOption) (*GetBundleResponse, error)
SaveBundleFunc func(ctx context.Context, req *SaveBundleRequest, opts ...client.CallOption) (*SaveBundleResponse, error)
AddSettingToBundleFunc func(ctx context.Context, req *AddSettingToBundleRequest, opts ...client.CallOption) (*AddSettingToBundleResponse, error)
RemoveSettingFromBundleFunc func(ctx context.Context, req *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*emptypb.Empty, error)
}
// ListBundles will panic if the function has been called, but not mocked
func (m MockBundleService) ListBundles(ctx context.Context, req *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error) {
if m.ListBundlesFunc != nil {
return m.ListBundlesFunc(ctx, req, opts...)
}
panic("ListBundlesFunc was called in test but not mocked")
}
// GetBundle will panic if the function has been called, but not mocked
func (m MockBundleService) GetBundle(ctx context.Context, req *GetBundleRequest, opts ...client.CallOption) (*GetBundleResponse, error) {
if m.GetBundleFunc != nil {
return m.GetBundleFunc(ctx, req, opts...)
}
panic("GetBundleFunc was called in test but not mocked")
}
// SaveBundle will panic if the function has been called, but not mocked
func (m MockBundleService) SaveBundle(ctx context.Context, req *SaveBundleRequest, opts ...client.CallOption) (*SaveBundleResponse, error) {
if m.SaveBundleFunc != nil {
return m.SaveBundleFunc(ctx, req, opts...)
}
panic("SaveBundleFunc was called in test but not mocked")
}
// AddSettingToBundle will panic if the function has been called, but not mocked
func (m MockBundleService) AddSettingToBundle(ctx context.Context, req *AddSettingToBundleRequest, opts ...client.CallOption) (*AddSettingToBundleResponse, error) {
if m.AddSettingToBundleFunc != nil {
return m.AddSettingToBundleFunc(ctx, req, opts...)
}
panic("AddSettingToBundleFunc was called in test but not mocked")
}
// RemoveSettingFromBundle will panic if the function has been called, but not mocked
func (m MockBundleService) RemoveSettingFromBundle(ctx context.Context, req *RemoveSettingFromBundleRequest, opts ...client.CallOption) (*emptypb.Empty, error) {
if m.RemoveSettingFromBundleFunc != nil {
return m.RemoveSettingFromBundleFunc(ctx, req, opts...)
}
panic("RemoveSettingFromBundleFunc was called in test but not mocked")
}
// MockValueService can be used to write tests against the value service.
type MockValueService struct {
ListValuesFunc func(ctx context.Context, req *ListValuesRequest, opts ...client.CallOption) (*ListValuesResponse, error)
GetValueFunc func(ctx context.Context, req *GetValueRequest, opts ...client.CallOption) (*GetValueResponse, error)
GetValueByUniqueIdentifiersFunc func(ctx context.Context, req *GetValueByUniqueIdentifiersRequest, opts ...client.CallOption) (*GetValueResponse, error)
SaveValueFunc func(ctx context.Context, req *SaveValueRequest, opts ...client.CallOption) (*SaveValueResponse, error)
}
// ListValues will panic if the function has been called, but not mocked
func (m MockValueService) ListValues(ctx context.Context, req *ListValuesRequest, opts ...client.CallOption) (*ListValuesResponse, error) {
if m.ListValuesFunc != nil {
return m.ListValuesFunc(ctx, req, opts...)
}
panic("ListValuesFunc was called in test but not mocked")
}
// GetValue will panic if the function has been called, but not mocked
func (m MockValueService) GetValue(ctx context.Context, req *GetValueRequest, opts ...client.CallOption) (*GetValueResponse, error) {
if m.GetValueFunc != nil {
return m.GetValueFunc(ctx, req, opts...)
}
panic("GetValueFunc was called in test but not mocked")
}
// GetValueByUniqueIdentifiers will panic if the function has been called, but not mocked
func (m MockValueService) GetValueByUniqueIdentifiers(ctx context.Context, req *GetValueByUniqueIdentifiersRequest, opts ...client.CallOption) (*GetValueResponse, error) {
if m.GetValueByUniqueIdentifiersFunc != nil {
return m.GetValueByUniqueIdentifiersFunc(ctx, req, opts...)
}
panic("GetValueByUniqueIdentifiersFunc was called in test but not mocked")
}
// SaveValue will panic if the function has been called, but not mocked
func (m MockValueService) SaveValue(ctx context.Context, req *SaveValueRequest, opts ...client.CallOption) (*SaveValueResponse, error) {
if m.SaveValueFunc != nil {
return m.SaveValueFunc(ctx, req, opts...)
}
panic("SaveValueFunc was called in test but not mocked")
}
// MockRoleService will panic if the function has been called, but not mocked
type MockRoleService struct {
ListRolesFunc func(ctx context.Context, req *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error)
ListRoleAssignmentsFunc func(ctx context.Context, req *ListRoleAssignmentsRequest, opts ...client.CallOption) (*ListRoleAssignmentsResponse, error)
AssignRoleToUserFunc func(ctx context.Context, req *AssignRoleToUserRequest, opts ...client.CallOption) (*AssignRoleToUserResponse, error)
RemoveRoleFromUserFunc func(ctx context.Context, req *RemoveRoleFromUserRequest, opts ...client.CallOption) (*emptypb.Empty, error)
}
// ListRoles will panic if the function has been called, but not mocked
func (m MockRoleService) ListRoles(ctx context.Context, req *ListBundlesRequest, opts ...client.CallOption) (*ListBundlesResponse, error) {
if m.ListRolesFunc != nil {
return m.ListRolesFunc(ctx, req, opts...)
}
panic("ListRolesFunc was called in test but not mocked")
}
// ListRoleAssignments will panic if the function has been called, but not mocked
func (m MockRoleService) ListRoleAssignments(ctx context.Context, req *ListRoleAssignmentsRequest, opts ...client.CallOption) (*ListRoleAssignmentsResponse, error) {
if m.ListRoleAssignmentsFunc != nil {
return m.ListRoleAssignmentsFunc(ctx, req, opts...)
}
panic("ListRoleAssignmentsFunc was called in test but not mocked")
}
// AssignRoleToUser will panic if the function has been called, but not mocked
func (m MockRoleService) AssignRoleToUser(ctx context.Context, req *AssignRoleToUserRequest, opts ...client.CallOption) (*AssignRoleToUserResponse, error) {
if m.AssignRoleToUserFunc != nil {
return m.AssignRoleToUserFunc(ctx, req, opts...)
}
panic("AssignRoleToUserFunc was called in test but not mocked")
}
// RemoveRoleFromUser will panic if the function has been called, but not mocked
func (m MockRoleService) RemoveRoleFromUser(ctx context.Context, req *RemoveRoleFromUserRequest, opts ...client.CallOption) (*emptypb.Empty, error) {
if m.RemoveRoleFromUserFunc != nil {
return m.RemoveRoleFromUserFunc(ctx, req, opts...)
}
panic("RemoveRoleFromUserFunc was called in test but not mocked")
}
// MockPermissionService will panic if the function has been called, but not mocked
type MockPermissionService struct {
ListPermissionsByResourceFunc func(ctx context.Context, req *ListPermissionsByResourceRequest, opts ...client.CallOption) (*ListPermissionsByResourceResponse, error)
GetPermissionByIDFunc func(ctx context.Context, req *GetPermissionByIDRequest, opts ...client.CallOption) (*GetPermissionByIDResponse, error)
}
// ListPermissionsByResource will panic if the function has been called, but not mocked
func (m MockPermissionService) ListPermissionsByResource(ctx context.Context, req *ListPermissionsByResourceRequest, opts ...client.CallOption) (*ListPermissionsByResourceResponse, error) {
if m.ListPermissionsByResourceFunc != nil {
return m.ListPermissionsByResourceFunc(ctx, req, opts...)
}
panic("ListPermissionsByResourceFunc was called in test but not mocked")
}
// GetPermissionByID will panic if the function has been called, but not mocked
func (m MockPermissionService) GetPermissionByID(ctx context.Context, req *GetPermissionByIDRequest, opts ...client.CallOption) (*GetPermissionByIDResponse, error) {
if m.GetPermissionByIDFunc != nil {
return m.GetPermissionByIDFunc(ctx, req, opts...)
}
panic("GetPermissionByIDFunc was called in test but not mocked")
}