add mocks for valueservice

Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
Christian Richter
2023-11-14 14:56:28 +01:00
parent aea129b658
commit 3e203fe751
2 changed files with 182 additions and 0 deletions

View File

@@ -0,0 +1,164 @@
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
package mocks
import (
context "context"
client "go-micro.dev/v4/client"
mock "github.com/stretchr/testify/mock"
v0 "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
)
// ValueService is an autogenerated mock type for the ValueService type
type ValueService struct {
mock.Mock
}
// GetValue provides a mock function with given fields: ctx, in, opts
func (_m *ValueService) GetValue(ctx context.Context, in *v0.GetValueRequest, opts ...client.CallOption) (*v0.GetValueResponse, error) {
_va := make([]interface{}, len(opts))
for _i := range opts {
_va[_i] = opts[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, in)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 *v0.GetValueResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v0.GetValueRequest, ...client.CallOption) (*v0.GetValueResponse, error)); ok {
return rf(ctx, in, opts...)
}
if rf, ok := ret.Get(0).(func(context.Context, *v0.GetValueRequest, ...client.CallOption) *v0.GetValueResponse); ok {
r0 = rf(ctx, in, opts...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v0.GetValueResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v0.GetValueRequest, ...client.CallOption) error); ok {
r1 = rf(ctx, in, opts...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetValueByUniqueIdentifiers provides a mock function with given fields: ctx, in, opts
func (_m *ValueService) GetValueByUniqueIdentifiers(ctx context.Context, in *v0.GetValueByUniqueIdentifiersRequest, opts ...client.CallOption) (*v0.GetValueResponse, error) {
_va := make([]interface{}, len(opts))
for _i := range opts {
_va[_i] = opts[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, in)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 *v0.GetValueResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v0.GetValueByUniqueIdentifiersRequest, ...client.CallOption) (*v0.GetValueResponse, error)); ok {
return rf(ctx, in, opts...)
}
if rf, ok := ret.Get(0).(func(context.Context, *v0.GetValueByUniqueIdentifiersRequest, ...client.CallOption) *v0.GetValueResponse); ok {
r0 = rf(ctx, in, opts...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v0.GetValueResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v0.GetValueByUniqueIdentifiersRequest, ...client.CallOption) error); ok {
r1 = rf(ctx, in, opts...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// ListValues provides a mock function with given fields: ctx, in, opts
func (_m *ValueService) ListValues(ctx context.Context, in *v0.ListValuesRequest, opts ...client.CallOption) (*v0.ListValuesResponse, error) {
_va := make([]interface{}, len(opts))
for _i := range opts {
_va[_i] = opts[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, in)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 *v0.ListValuesResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v0.ListValuesRequest, ...client.CallOption) (*v0.ListValuesResponse, error)); ok {
return rf(ctx, in, opts...)
}
if rf, ok := ret.Get(0).(func(context.Context, *v0.ListValuesRequest, ...client.CallOption) *v0.ListValuesResponse); ok {
r0 = rf(ctx, in, opts...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v0.ListValuesResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v0.ListValuesRequest, ...client.CallOption) error); ok {
r1 = rf(ctx, in, opts...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// SaveValue provides a mock function with given fields: ctx, in, opts
func (_m *ValueService) SaveValue(ctx context.Context, in *v0.SaveValueRequest, opts ...client.CallOption) (*v0.SaveValueResponse, error) {
_va := make([]interface{}, len(opts))
for _i := range opts {
_va[_i] = opts[_i]
}
var _ca []interface{}
_ca = append(_ca, ctx, in)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
var r0 *v0.SaveValueResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, *v0.SaveValueRequest, ...client.CallOption) (*v0.SaveValueResponse, error)); ok {
return rf(ctx, in, opts...)
}
if rf, ok := ret.Get(0).(func(context.Context, *v0.SaveValueRequest, ...client.CallOption) *v0.SaveValueResponse); ok {
r0 = rf(ctx, in, opts...)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*v0.SaveValueResponse)
}
}
if rf, ok := ret.Get(1).(func(context.Context, *v0.SaveValueRequest, ...client.CallOption) error); ok {
r1 = rf(ctx, in, opts...)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// NewValueService creates a new instance of ValueService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewValueService(t interface {
mock.TestingT
Cleanup(func())
}) *ValueService {
mock := &ValueService{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}

View File

@@ -47,6 +47,7 @@ var _ = Describe("Users", func() {
gatewaySelector pool.Selectable[gateway.GatewayAPIClient]
eventsPublisher mocks.Publisher
roleService *mocks.RoleService
valueService *mocks.ValueService
identityBackend *identitymocks.Backend
rr *httptest.ResponseRecorder
@@ -73,6 +74,7 @@ var _ = Describe("Users", func() {
identityBackend = &identitymocks.Backend{}
roleService = &mocks.RoleService{}
valueService = &mocks.ValueService{}
rr = httptest.NewRecorder()
ctx = context.Background()
@@ -90,6 +92,7 @@ var _ = Describe("Users", func() {
service.EventsPublisher(&eventsPublisher),
service.WithIdentityBackend(identityBackend),
service.WithRoleService(roleService),
service.WithValueService(valueService),
)
})
@@ -102,6 +105,14 @@ var _ = Describe("Users", func() {
})
It("gets the information", func() {
valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{
Value: &settingsmsg.ValueWithIdentifier{
Value: &settingsmsg.Value{
: &settingsmsg.ListOptionValue{},
}
},
}, nil)
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me", nil)
r = r.WithContext(revactx.ContextSetUser(ctx, currentUser))
svc.GetMe(rr, r)
@@ -117,6 +128,7 @@ var _ = Describe("Users", func() {
},
}
identityBackend.On("GetUser", mock.Anything, mock.Anything, mock.Anything).Return(user, nil)
valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil)
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me?$expand=memberOf", nil)
r = r.WithContext(revactx.ContextSetUser(ctx, currentUser))
@@ -145,6 +157,7 @@ var _ = Describe("Users", func() {
},
}
roleService.On("ListRoleAssignments", mock.Anything, mock.Anything, mock.Anything).Return(&settings.ListRoleAssignmentsResponse{Assignments: assignments}, nil)
valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil)
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me?$expand=appRoleAssignments", nil)
r = r.WithContext(revactx.ContextSetUser(ctx, currentUser))
@@ -413,6 +426,8 @@ var _ = Describe("Users", func() {
user.SetId("user1")
identityBackend.On("GetUser", mock.Anything, mock.Anything, mock.Anything).Return(user, nil)
valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil)
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/users", nil)
rctx := chi.NewRouteContext()
rctx.URLParams.Add("userID", *user.Id)
@@ -455,6 +470,7 @@ var _ = Describe("Users", func() {
},
},
}, nil)
valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil)
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/users?$expand=drive", nil)
rctx := chi.NewRouteContext()
@@ -490,6 +506,7 @@ var _ = Describe("Users", func() {
},
},
}, nil)
valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil)
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/users?$expand=drives", nil)
rctx := chi.NewRouteContext()
@@ -521,6 +538,7 @@ var _ = Describe("Users", func() {
},
}
roleService.On("ListRoleAssignments", mock.Anything, mock.Anything, mock.Anything).Return(&settings.ListRoleAssignmentsResponse{Assignments: assignments}, nil)
valueService.On("GetValueByUniqueIdentifiers", mock.Anything, mock.Anything, mock.Anything).Return(&settings.GetValueResponse{}, nil)
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/users/user1?$expand=appRoleAssignments", nil)
rctx := chi.NewRouteContext()