test: Add tests for grouped emails
This commit is contained in:
8 files changed
+1666
-19
No files matched your search
@@ -0,0 +1,3 @@
|
||||
Enhancement: Add tests for grouped emails
|
||||
|
||||
https://github.com/owncloud/ocis/pull/10885
|
||||
@@ -348,7 +348,7 @@ replace github.com/unrolled/secure => github.com/DeepDiver1975/secure v0.0.0-202
|
||||
|
||||
replace github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20240807130109-f62bb67e8c90
|
||||
|
||||
replace go-micro.dev/v4 => github.com/kobergj/go-micro/v4 v4.0.0-20250116171647-71d591d05282
|
||||
replace go-micro.dev/v4 => github.com/kobergj/go-micro/v4 v4.0.0-20250117084952-d07d30666b7c
|
||||
|
||||
// exclude the v2 line of go-sqlite3 which was released accidentally and prevents pulling in newer versions of go-sqlite3
|
||||
// see https://github.com/mattn/go-sqlite3/issues/965 for more details
|
||||
|
||||
@@ -698,8 +698,8 @@ github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90
|
||||
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
|
||||
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/kobergj/go-micro/v4 v4.0.0-20250116171647-71d591d05282 h1:c6jxxbWNgqsW751HJooaRBJV/6xaVoajbXJknrBmyWE=
|
||||
github.com/kobergj/go-micro/v4 v4.0.0-20250116171647-71d591d05282/go.mod h1:eE/tD53n3KbVrzrWxKLxdkGw45Fg1qaNLWjpJMvIUF4=
|
||||
github.com/kobergj/go-micro/v4 v4.0.0-20250117084952-d07d30666b7c h1:21N6rhk5dzUxYhJYiBsyqoRrIowpetooAS5mDwHayeE=
|
||||
github.com/kobergj/go-micro/v4 v4.0.0-20250117084952-d07d30666b7c/go.mod h1:eE/tD53n3KbVrzrWxKLxdkGw45Fg1qaNLWjpJMvIUF4=
|
||||
github.com/kobergj/gowebdav v0.0.0-20250102091030-aa65266db202 h1:A1xJ2NKgiYFiaHiLl9B5yw/gUBACSs9crDykTS3GuQI=
|
||||
github.com/kobergj/gowebdav v0.0.0-20250102091030-aa65266db202/go.mod h1:bHA7t77X/QFExdeAnDzK6vKM34kEZAcE1OX4MfiwjkE=
|
||||
github.com/kobergj/icap-client v0.0.0-20250116172800-8eaa5022532b h1:NBKEgFtIukCreWOEvtrgNQusqosGyhlxzyiHbba1zEI=
|
||||
|
||||
@@ -0,0 +1,416 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
|
||||
"github.com/cs3org/reva/v2/pkg/events"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
event "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/eventhistory/v0"
|
||||
ehsvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/eventhistory/v0"
|
||||
"github.com/owncloud/ocis/v2/protogen/gen/ocis/services/eventhistory/v0/mocks"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"reflect"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go-micro.dev/v4/store"
|
||||
storemocks "go-micro.dev/v4/store/mocks"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_userEventStore_persist(t *testing.T) {
|
||||
tEventId := "event id"
|
||||
tUser := &user.User{Id: &user.UserId{OpaqueId: "userid"}}
|
||||
tInterval := "interval"
|
||||
tKey := tInterval + "_" + tUser.Id.OpaqueId
|
||||
tErr := errors.New("some error")
|
||||
tValueSingleEventId, err := json.Marshal(userEventIds{
|
||||
User: tUser,
|
||||
EventIds: []string{tEventId},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
type fields struct {
|
||||
log log.Logger
|
||||
store store.Store
|
||||
historyClient ehsvc.EventHistoryService
|
||||
}
|
||||
type args struct {
|
||||
interval string
|
||||
eventId string
|
||||
users []*user.User
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []*user.User
|
||||
}{
|
||||
{
|
||||
name: "new record",
|
||||
fields: fields{
|
||||
log: testLogger,
|
||||
store: func() store.Store {
|
||||
s := storemocks.NewStore(t)
|
||||
|
||||
s.EXPECT().Read(tKey).Return([]*store.Record{}, nil).Once()
|
||||
|
||||
s.EXPECT().Write(&store.Record{Key: tKey, Value: tValueSingleEventId}).Return(nil).Once()
|
||||
|
||||
return s
|
||||
}(),
|
||||
historyClient: nil,
|
||||
},
|
||||
args: args{
|
||||
interval: tInterval,
|
||||
eventId: tEventId,
|
||||
users: []*user.User{tUser},
|
||||
},
|
||||
want: []*user.User(nil),
|
||||
},
|
||||
{
|
||||
name: "append to record",
|
||||
fields: fields{
|
||||
log: testLogger,
|
||||
store: func() store.Store {
|
||||
s := storemocks.NewStore(t)
|
||||
|
||||
s.EXPECT().Read(tKey).Return([]*store.Record{{Key: tKey, Value: tValueSingleEventId}}, nil).Once()
|
||||
|
||||
b, err := json.Marshal(userEventIds{
|
||||
User: tUser,
|
||||
EventIds: []string{tEventId, tEventId},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.EXPECT().Write(&store.Record{Key: tKey, Value: b}).Return(nil).Once()
|
||||
|
||||
return s
|
||||
}(),
|
||||
historyClient: nil,
|
||||
},
|
||||
args: args{
|
||||
interval: tInterval,
|
||||
eventId: tEventId,
|
||||
users: []*user.User{tUser},
|
||||
},
|
||||
want: []*user.User(nil),
|
||||
},
|
||||
{
|
||||
name: "error on read",
|
||||
fields: fields{
|
||||
log: testLogger,
|
||||
store: func() store.Store {
|
||||
s := storemocks.NewStore(t)
|
||||
|
||||
s.EXPECT().Read(tKey).Return(nil, tErr).Once()
|
||||
|
||||
return s
|
||||
}(),
|
||||
historyClient: nil,
|
||||
},
|
||||
args: args{
|
||||
interval: tInterval,
|
||||
eventId: tEventId,
|
||||
users: []*user.User{tUser},
|
||||
},
|
||||
want: []*user.User{tUser},
|
||||
},
|
||||
{
|
||||
name: "error on write",
|
||||
fields: fields{
|
||||
log: testLogger,
|
||||
store: func() store.Store {
|
||||
s := storemocks.NewStore(t)
|
||||
|
||||
s.EXPECT().Read(tKey).Return([]*store.Record{}, nil).Once()
|
||||
|
||||
b, err := json.Marshal(userEventIds{
|
||||
User: tUser,
|
||||
EventIds: []string{tEventId},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.EXPECT().Write(&store.Record{Key: tKey, Value: b}).Return(tErr).Once()
|
||||
|
||||
return s
|
||||
}(),
|
||||
historyClient: nil,
|
||||
},
|
||||
args: args{
|
||||
interval: tInterval,
|
||||
eventId: tEventId,
|
||||
users: []*user.User{tUser},
|
||||
},
|
||||
want: []*user.User{tUser},
|
||||
},
|
||||
{
|
||||
name: "multiple users",
|
||||
fields: fields{
|
||||
log: testLogger,
|
||||
store: func() store.Store {
|
||||
s := storemocks.NewStore(t)
|
||||
|
||||
s.EXPECT().Read(tKey).Return([]*store.Record{}, nil).Once()
|
||||
s.EXPECT().Write(&store.Record{Key: tKey, Value: tValueSingleEventId}).Return(nil).Once()
|
||||
|
||||
tUser2 := &user.User{Id: &user.UserId{OpaqueId: "userid2"}}
|
||||
tKey2 := tInterval + "_" + tUser2.Id.OpaqueId
|
||||
tValueSingleEventId2, err := json.Marshal(userEventIds{
|
||||
User: tUser2,
|
||||
EventIds: []string{tEventId},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.EXPECT().Read(tKey2).Return([]*store.Record{}, nil).Once()
|
||||
s.EXPECT().Write(&store.Record{Key: tKey2, Value: tValueSingleEventId2}).Return(nil).Once()
|
||||
|
||||
return s
|
||||
}(),
|
||||
historyClient: nil,
|
||||
},
|
||||
args: args{
|
||||
interval: tInterval,
|
||||
eventId: tEventId,
|
||||
users: []*user.User{tUser, {Id: &user.UserId{OpaqueId: "userid2"}}},
|
||||
},
|
||||
want: []*user.User(nil),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &userEventStore{
|
||||
log: tt.fields.log,
|
||||
store: tt.fields.store,
|
||||
historyClient: tt.fields.historyClient,
|
||||
}
|
||||
assert.Equalf(t, tt.want, s.persist(tt.args.interval, tt.args.eventId, tt.args.users), "persist(%v, %v, %v)", tt.args.interval, tt.args.eventId, tt.args.users)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_userEventStore_pop(t *testing.T) {
|
||||
tCtx := context.TODO()
|
||||
tUser := &user.User{Id: &user.UserId{OpaqueId: "userid"}}
|
||||
tInterval := "interval"
|
||||
tKey := tInterval + "_" + tUser.Id.OpaqueId
|
||||
tErr := errors.New("some error")
|
||||
|
||||
// event 1
|
||||
tEventId := "event id"
|
||||
tValueSingleEventId, err := json.Marshal(userEventIds{
|
||||
User: tUser,
|
||||
EventIds: []string{tEventId},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b, err := json.Marshal(events.ShareCreated{
|
||||
ShareID: &collaboration.ShareId{OpaqueId: "shareid"},
|
||||
})
|
||||
tEvent := &event.Event{
|
||||
Type: reflect.TypeOf(&events.ShareCreated{}).String(),
|
||||
Id: tEventId,
|
||||
Event: b,
|
||||
}
|
||||
tUserEvents := &userEvents{
|
||||
User: tUser,
|
||||
Events: []*event.Event{tEvent},
|
||||
}
|
||||
|
||||
// event 2
|
||||
tEventId2 := "event id2"
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err = json.Marshal(events.ShareRemoved{
|
||||
ShareID: &collaboration.ShareId{OpaqueId: "shareid"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tEvent2 := &event.Event{
|
||||
Type: reflect.TypeOf(&events.ShareRemoved{}).String(),
|
||||
Id: tEventId,
|
||||
Event: b,
|
||||
}
|
||||
|
||||
tValueMultipleEventIds, err := json.Marshal(userEventIds{
|
||||
User: tUser,
|
||||
EventIds: []string{tEventId, tEventId2},
|
||||
})
|
||||
tUserMultipleEvents := &userEvents{
|
||||
User: tUser,
|
||||
Events: []*event.Event{tEvent, tEvent2},
|
||||
}
|
||||
|
||||
type fields struct {
|
||||
log log.Logger
|
||||
store store.Store
|
||||
historyClient ehsvc.EventHistoryService
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
key string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want *userEvents
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "single event",
|
||||
fields: fields{
|
||||
log: testLogger,
|
||||
store: func() store.Store {
|
||||
s := storemocks.NewStore(t)
|
||||
|
||||
s.EXPECT().Read(tKey).Return([]*store.Record{{Key: tKey, Value: tValueSingleEventId}}, nil).Once()
|
||||
|
||||
s.EXPECT().Delete(tKey).Return(nil).Once()
|
||||
|
||||
return s
|
||||
}(),
|
||||
historyClient: func() ehsvc.EventHistoryService {
|
||||
hc := mocks.NewEventHistoryService(t)
|
||||
|
||||
hc.EXPECT().GetEvents(mock.Anything, &ehsvc.GetEventsRequest{Ids: []string{tEventId}}).
|
||||
Return(&ehsvc.GetEventsResponse{Events: []*event.Event{tEvent}}, nil).Once()
|
||||
|
||||
return hc
|
||||
}(),
|
||||
},
|
||||
args: args{
|
||||
ctx: tCtx,
|
||||
key: tKey,
|
||||
},
|
||||
want: tUserEvents,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "multiple events",
|
||||
fields: fields{
|
||||
log: testLogger,
|
||||
store: func() store.Store {
|
||||
s := storemocks.NewStore(t)
|
||||
s.EXPECT().Read(tKey).Return([]*store.Record{{Key: tKey, Value: tValueMultipleEventIds}}, nil).Once()
|
||||
|
||||
s.EXPECT().Delete(tKey).Return(nil).Once()
|
||||
|
||||
return s
|
||||
}(),
|
||||
historyClient: func() ehsvc.EventHistoryService {
|
||||
hc := mocks.NewEventHistoryService(t)
|
||||
|
||||
hc.EXPECT().GetEvents(tCtx, &ehsvc.GetEventsRequest{Ids: []string{tEventId, tEventId2}}).
|
||||
Return(&ehsvc.GetEventsResponse{Events: []*event.Event{tEvent, tEvent2}}, nil).Once()
|
||||
|
||||
return hc
|
||||
}(),
|
||||
},
|
||||
args: args{
|
||||
ctx: tCtx,
|
||||
key: tKey,
|
||||
},
|
||||
want: tUserMultipleEvents,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "error on read",
|
||||
fields: fields{
|
||||
log: testLogger,
|
||||
store: func() store.Store {
|
||||
s := storemocks.NewStore(t)
|
||||
s.EXPECT().Read(tKey).Return(nil, tErr).Once()
|
||||
|
||||
return s
|
||||
}(),
|
||||
historyClient: nil,
|
||||
},
|
||||
args: args{
|
||||
ctx: tCtx,
|
||||
key: tKey,
|
||||
},
|
||||
want: nil,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "error on get events",
|
||||
fields: fields{
|
||||
log: testLogger,
|
||||
store: func() store.Store {
|
||||
s := storemocks.NewStore(t)
|
||||
s.EXPECT().Read(tKey).Return([]*store.Record{{Key: tKey, Value: tValueSingleEventId}}, nil).Once()
|
||||
return s
|
||||
}(),
|
||||
historyClient: func() ehsvc.EventHistoryService {
|
||||
hc := mocks.NewEventHistoryService(t)
|
||||
|
||||
hc.EXPECT().GetEvents(mock.Anything, &ehsvc.GetEventsRequest{Ids: []string{tEventId}}).
|
||||
Return(nil, tErr).Once()
|
||||
|
||||
return hc
|
||||
}(),
|
||||
},
|
||||
args: args{
|
||||
ctx: tCtx,
|
||||
key: tKey,
|
||||
},
|
||||
want: nil,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "error on delete",
|
||||
fields: fields{
|
||||
log: testLogger,
|
||||
store: func() store.Store {
|
||||
s := storemocks.NewStore(t)
|
||||
|
||||
s.EXPECT().Read(tKey).Return([]*store.Record{{Key: tKey, Value: tValueSingleEventId}}, nil).Once()
|
||||
|
||||
s.EXPECT().Delete(tKey).Return(tErr).Once()
|
||||
|
||||
return s
|
||||
}(),
|
||||
historyClient: func() ehsvc.EventHistoryService {
|
||||
hc := mocks.NewEventHistoryService(t)
|
||||
|
||||
hc.EXPECT().GetEvents(mock.Anything, &ehsvc.GetEventsRequest{Ids: []string{tEventId}}).
|
||||
Return(&ehsvc.GetEventsResponse{Events: []*event.Event{tEvent}}, nil).Once()
|
||||
|
||||
return hc
|
||||
}(),
|
||||
},
|
||||
args: args{
|
||||
ctx: tCtx,
|
||||
key: tKey,
|
||||
},
|
||||
want: nil,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &userEventStore{
|
||||
log: tt.fields.log,
|
||||
store: tt.fields.store,
|
||||
historyClient: tt.fields.historyClient,
|
||||
}
|
||||
got, err := s.pop(tt.args.ctx, tt.args.key)
|
||||
if tt.wantErr {
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
assert.Equalf(t, tt.want, got, "pop(%v, %v)", tt.args.ctx, tt.args.key)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,22 @@
|
||||
package service_test
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
|
||||
"github.com/cs3org/reva/v2/pkg/store"
|
||||
ehmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/eventhistory/v0"
|
||||
settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
|
||||
v0 "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/eventhistory/v0"
|
||||
ehmocks "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/eventhistory/v0/mocks"
|
||||
settingsmocks "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0/mocks"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
microstore "go-micro.dev/v4/store"
|
||||
|
||||
storemocks "go-micro.dev/v4/store/mocks"
|
||||
"time"
|
||||
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
@@ -17,11 +30,8 @@ import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
||||
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
|
||||
"github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults"
|
||||
"github.com/owncloud/ocis/v2/services/notifications/pkg/channels"
|
||||
"github.com/owncloud/ocis/v2/services/notifications/pkg/service"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"go-micro.dev/v4/client"
|
||||
"google.golang.org/grpc"
|
||||
@@ -89,12 +99,10 @@ var _ = Describe("Notifications", func() {
|
||||
}
|
||||
})
|
||||
|
||||
DescribeTable("Sending userEventIds",
|
||||
DescribeTable("Sending notifications",
|
||||
func(tc testChannel, ev events.Event) {
|
||||
cfg := defaults.FullDefaultConfig()
|
||||
cfg.GRPCClientTLS = &shared.GRPCClientTLS{}
|
||||
ch := make(chan events.Event)
|
||||
evts := service.NewEventsNotifier(ch, tc, log.NewLogger(), gatewaySelector, vs, "",
|
||||
evts := NewEventsNotifier(ch, tc, log.NewLogger(), gatewaySelector, vs, "",
|
||||
"", "", "", "", "", "",
|
||||
store.Create(), nil, nil)
|
||||
go evts.Run()
|
||||
@@ -304,12 +312,10 @@ var _ = Describe("Notifications X-Site Scripting", func() {
|
||||
}
|
||||
})
|
||||
|
||||
DescribeTable("Sending userEventIds",
|
||||
DescribeTable("Sending notifications",
|
||||
func(tc testChannel, ev events.Event) {
|
||||
cfg := defaults.FullDefaultConfig()
|
||||
cfg.GRPCClientTLS = &shared.GRPCClientTLS{}
|
||||
ch := make(chan events.Event)
|
||||
evts := service.NewEventsNotifier(ch, tc, log.NewLogger(), gatewaySelector, vs, "",
|
||||
evts := NewEventsNotifier(ch, tc, log.NewLogger(), gatewaySelector, vs, "",
|
||||
"", "", "", "", "", "",
|
||||
store.Create(), nil, nil)
|
||||
go evts.Run()
|
||||
@@ -460,7 +466,713 @@ https://owncloud.com
|
||||
)
|
||||
})
|
||||
|
||||
// NOTE: This is explictitly not testing the message itself. Should we?
|
||||
var _ = Describe("Notifications grouped store", func() {
|
||||
var (
|
||||
gatewayClient *cs3mocks.GatewayAPIClient
|
||||
gatewaySelector pool.Selectable[gateway.GatewayAPIClient]
|
||||
valueService *settingsmocks.ValueService
|
||||
store *storemocks.Store
|
||||
executant = &user.User{
|
||||
Id: &user.UserId{
|
||||
OpaqueId: "executantId",
|
||||
},
|
||||
Mail: "executant@owncloud.com",
|
||||
DisplayName: "executant",
|
||||
}
|
||||
receiverGrouped = &user.User{
|
||||
Id: &user.UserId{
|
||||
OpaqueId: "receiverGroupedId",
|
||||
},
|
||||
Mail: "receiverGrouped@owncloud.com",
|
||||
DisplayName: "receiverGrouped",
|
||||
}
|
||||
// receiverInstant is used to trigger tc.done
|
||||
receiverInstant = &user.User{
|
||||
Id: &user.UserId{
|
||||
OpaqueId: "receiverInstantId",
|
||||
},
|
||||
Mail: "receiverInstant@owncloud.com",
|
||||
DisplayName: "receiverInstant",
|
||||
}
|
||||
resourceid = &provider.ResourceId{
|
||||
StorageId: "storageid",
|
||||
SpaceId: "spaceid",
|
||||
OpaqueId: "itemid",
|
||||
}
|
||||
)
|
||||
|
||||
DescribeTable("Sending notifications",
|
||||
func(tc testChannelGroupedStore, ev events.Event, interval string) {
|
||||
// setup mocks
|
||||
// Note: This is done here and not inside a BeforeEach, because some mocks need variables from entries.
|
||||
|
||||
pool.RemoveSelector("GatewaySelector" + "com.owncloud.api.gateway")
|
||||
gatewayClient = &cs3mocks.GatewayAPIClient{}
|
||||
gatewaySelector = pool.GetSelector[gateway.GatewayAPIClient](
|
||||
"GatewaySelector",
|
||||
"com.owncloud.api.gateway",
|
||||
func(cc grpc.ClientConnInterface) gateway.GatewayAPIClient {
|
||||
return gatewayClient
|
||||
},
|
||||
)
|
||||
|
||||
gatewayClient.EXPECT().Authenticate(mock.Anything, mock.Anything).Return(&gateway.AuthenticateResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}, User: executant}, nil)
|
||||
gatewayClient.EXPECT().Stat(mock.Anything, mock.Anything).Return(&provider.StatResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}, Info: &provider.ResourceInfo{Name: "secrets of the board", Space: &provider.StorageSpace{Name: "secret space"}}}, nil)
|
||||
|
||||
gatewayClient.EXPECT().GetGroup(mock.Anything, mock.Anything).
|
||||
Return(&group.GetGroupResponse{
|
||||
Status: &rpc.Status{Code: rpc.Code_CODE_OK},
|
||||
Group: &group.Group{
|
||||
Members: []*user.UserId{receiverGrouped.GetId(), receiverInstant.GetId()},
|
||||
},
|
||||
}, nil)
|
||||
gatewayClient.EXPECT().GetUser(mock.Anything, mock.Anything).
|
||||
Return(&user.GetUserResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}, User: executant}, nil).Once()
|
||||
gatewayClient.EXPECT().GetUser(mock.Anything, mock.Anything).
|
||||
Return(&user.GetUserResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}, User: receiverGrouped}, nil).Once()
|
||||
gatewayClient.EXPECT().GetUser(mock.Anything, mock.Anything).
|
||||
Return(&user.GetUserResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}, User: receiverInstant}, nil).Once()
|
||||
|
||||
valueService = settingsmocks.NewValueService(GinkgoT())
|
||||
|
||||
// disabled email
|
||||
valueService.EXPECT().GetValueByUniqueIdentifiers(mock.Anything, mock.Anything).
|
||||
Return(&settingssvc.GetValueResponse{Value: &settingsmsg.ValueWithIdentifier{
|
||||
Value: &settingsmsg.Value{
|
||||
Value: &settingsmsg.Value_BoolValue{
|
||||
BoolValue: false,
|
||||
},
|
||||
},
|
||||
}}, nil).Twice()
|
||||
|
||||
// filtering
|
||||
valueService.EXPECT().GetValueByUniqueIdentifiers(mock.Anything, mock.Anything).Return(&settingssvc.GetValueResponse{
|
||||
Value: &settingsmsg.ValueWithIdentifier{
|
||||
Value: &settingsmsg.Value{
|
||||
Value: &settingsmsg.Value_CollectionValue{
|
||||
CollectionValue: &settingsmsg.CollectionValue{
|
||||
Values: []*settingsmsg.CollectionOption{
|
||||
{
|
||||
Key: "mail",
|
||||
Option: &settingsmsg.CollectionOption_BoolValue{BoolValue: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil).Twice()
|
||||
|
||||
// interval
|
||||
valueService.EXPECT().GetValueByUniqueIdentifiers(mock.Anything, mock.Anything).
|
||||
Return(&settingssvc.GetValueResponse{Value: &settingsmsg.ValueWithIdentifier{
|
||||
Value: &settingsmsg.Value{
|
||||
Value: &settingsmsg.Value_StringValue{
|
||||
StringValue: interval,
|
||||
},
|
||||
},
|
||||
}}, nil).Once()
|
||||
valueService.EXPECT().GetValueByUniqueIdentifiers(mock.Anything, mock.Anything).
|
||||
Return(&settingssvc.GetValueResponse{Value: &settingsmsg.ValueWithIdentifier{
|
||||
Value: &settingsmsg.Value{
|
||||
Value: &settingsmsg.Value_StringValue{
|
||||
StringValue: "instant",
|
||||
},
|
||||
},
|
||||
}}, nil).Once()
|
||||
|
||||
// locale
|
||||
valueService.EXPECT().GetValueByUniqueIdentifiers(mock.Anything, mock.Anything).Return(&settingssvc.GetValueResponse{
|
||||
Value: &settingsmsg.ValueWithIdentifier{
|
||||
Value: &settingsmsg.Value{
|
||||
Value: &settingsmsg.Value_ListValue{
|
||||
ListValue: &settingsmsg.ListValue{
|
||||
Values: []*settingsmsg.ListOptionValue{
|
||||
{
|
||||
Option: &settingsmsg.ListOptionValue_StringValue{StringValue: "en"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil).Once()
|
||||
|
||||
// fail if mocked functions are not called
|
||||
store = storemocks.NewStore(GinkgoT())
|
||||
store.EXPECT().Read(mock.Anything).Return([]*microstore.Record{}, nil).Once()
|
||||
store.EXPECT().Write(mock.Anything).Return(nil).Once()
|
||||
|
||||
// setup EventsNotifier
|
||||
ch := make(chan events.Event)
|
||||
evts := NewEventsNotifier(ch, tc, log.NewLogger(), gatewaySelector, valueService, "",
|
||||
"", "", "", "", "", "",
|
||||
store, nil, nil)
|
||||
go evts.Run()
|
||||
|
||||
// test
|
||||
ch <- ev
|
||||
select {
|
||||
case <-tc.done:
|
||||
case <-time.Tick(3 * time.Second):
|
||||
Fail("timeout waiting for notification")
|
||||
}
|
||||
},
|
||||
|
||||
Entry("Share Created daily", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.ShareCreated{
|
||||
Sharer: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
CTime: utils.TimeToTS(time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC)),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
},
|
||||
"daily"),
|
||||
|
||||
Entry("Share Expired daily", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.ShareExpired{
|
||||
ShareOwner: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
},
|
||||
"daily"),
|
||||
|
||||
Entry("Added to Space daily", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.SpaceShared{
|
||||
Executant: executant.GetId(),
|
||||
Creator: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
},
|
||||
"daily"),
|
||||
|
||||
Entry("Removed from Space daily", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.SpaceUnshared{
|
||||
Executant: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
},
|
||||
"daily"),
|
||||
|
||||
Entry("Space Expired daily", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.SpaceMembershipExpired{
|
||||
SpaceOwner: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
SpaceID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
SpaceName: "secret space",
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
},
|
||||
},
|
||||
"daily"),
|
||||
|
||||
Entry("Share Created weekly", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.ShareCreated{
|
||||
Sharer: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
CTime: utils.TimeToTS(time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC)),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
},
|
||||
"weekly"),
|
||||
|
||||
Entry("Share Expired weekly", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.ShareExpired{
|
||||
ShareOwner: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
},
|
||||
"weekly"),
|
||||
|
||||
Entry("Added to Space weekly", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.SpaceShared{
|
||||
Executant: executant.GetId(),
|
||||
Creator: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
},
|
||||
"weekly"),
|
||||
|
||||
Entry("Removed from Space weekly", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.SpaceUnshared{
|
||||
Executant: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
},
|
||||
"weekly"),
|
||||
|
||||
Entry("Space Expired weekly", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.SpaceMembershipExpired{
|
||||
SpaceOwner: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
SpaceID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
SpaceName: "secret space",
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
},
|
||||
},
|
||||
"weekly"),
|
||||
)
|
||||
})
|
||||
|
||||
var _ = Describe("Notifications grouped send", func() {
|
||||
const sender = "foo@bar.com"
|
||||
const subject = "Report"
|
||||
var (
|
||||
gatewayClient *cs3mocks.GatewayAPIClient
|
||||
gatewaySelector pool.Selectable[gateway.GatewayAPIClient]
|
||||
valueService *settingsmocks.ValueService
|
||||
store *storemocks.Store
|
||||
historyClient *ehmocks.EventHistoryService
|
||||
|
||||
executant = &user.User{
|
||||
Id: &user.UserId{
|
||||
OpaqueId: "executantId",
|
||||
},
|
||||
Mail: "executant@owncloud.com",
|
||||
DisplayName: "executant",
|
||||
}
|
||||
receiver = &user.User{
|
||||
Id: &user.UserId{
|
||||
OpaqueId: "receiver",
|
||||
},
|
||||
Mail: "receiver@owncloud.com",
|
||||
DisplayName: "receiver",
|
||||
}
|
||||
|
||||
resourceid = &provider.ResourceId{
|
||||
StorageId: "storageid",
|
||||
SpaceId: "spaceid",
|
||||
OpaqueId: "itemid",
|
||||
}
|
||||
)
|
||||
|
||||
DescribeTable("Sending notifications",
|
||||
func(tc testChannel, storedEvents []events.Event, interval string) {
|
||||
// setup mocks
|
||||
// Note: This is done here and not inside a BeforeEach, because some mocks need variables from entries.
|
||||
|
||||
b, err := json.Marshal(userEventIds{
|
||||
User: receiver,
|
||||
EventIds: []string{"event id"},
|
||||
})
|
||||
if err != nil {
|
||||
Fail(err.Error())
|
||||
}
|
||||
|
||||
store = &storemocks.Store{}
|
||||
store.EXPECT().List(mock.Anything).Return([]string{"key"}, nil)
|
||||
store.EXPECT().Read(mock.Anything).Return([]*microstore.Record{{Value: b}}, nil).Once()
|
||||
store.EXPECT().Delete(mock.Anything).Return(nil).Once()
|
||||
|
||||
var hcEvs []*ehmsg.Event
|
||||
for _, e := range storedEvents {
|
||||
b, err = json.Marshal(e.Event)
|
||||
if err != nil {
|
||||
Fail(err.Error())
|
||||
}
|
||||
hcEvs = append(hcEvs, &ehmsg.Event{Type: e.Type, Event: b})
|
||||
}
|
||||
|
||||
historyClient = &ehmocks.EventHistoryService{}
|
||||
historyClient.EXPECT().GetEvents(mock.Anything, mock.Anything).Return(&v0.GetEventsResponse{Events: hcEvs}, nil)
|
||||
|
||||
// locale
|
||||
valueService = &settingsmocks.ValueService{}
|
||||
valueService.EXPECT().GetValueByUniqueIdentifiers(mock.Anything, mock.Anything).Return(&settingssvc.GetValueResponse{
|
||||
Value: &settingsmsg.ValueWithIdentifier{
|
||||
Value: &settingsmsg.Value{
|
||||
Value: &settingsmsg.Value_ListValue{
|
||||
ListValue: &settingsmsg.ListValue{
|
||||
Values: []*settingsmsg.ListOptionValue{
|
||||
{
|
||||
Option: &settingsmsg.ListOptionValue_StringValue{StringValue: "en"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, nil).Once()
|
||||
|
||||
pool.RemoveSelector("GatewaySelector" + "com.owncloud.api.gateway")
|
||||
gatewayClient = &cs3mocks.GatewayAPIClient{}
|
||||
gatewaySelector = pool.GetSelector[gateway.GatewayAPIClient](
|
||||
"GatewaySelector",
|
||||
"com.owncloud.api.gateway",
|
||||
func(cc grpc.ClientConnInterface) gateway.GatewayAPIClient {
|
||||
return gatewayClient
|
||||
},
|
||||
)
|
||||
|
||||
gatewayClient.EXPECT().Authenticate(mock.Anything, mock.Anything).Return(&gateway.AuthenticateResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}, User: executant}, nil)
|
||||
gatewayClient.EXPECT().Stat(mock.Anything, mock.Anything).Return(&provider.StatResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}, Info: &provider.ResourceInfo{Name: "secrets of the board", Space: &provider.StorageSpace{Name: "secret space"}}}, nil)
|
||||
gatewayClient.EXPECT().GetUser(mock.Anything, mock.Anything).
|
||||
Return(&user.GetUserResponse{Status: &rpc.Status{Code: rpc.Code_CODE_OK}, User: executant}, nil).Once()
|
||||
|
||||
// setup EventsNotifier
|
||||
evs := []events.Unmarshaller{
|
||||
events.ShareCreated{},
|
||||
events.ShareExpired{},
|
||||
events.SpaceShared{},
|
||||
events.SpaceUnshared{},
|
||||
events.SpaceMembershipExpired{},
|
||||
events.SendEmailsEvent{},
|
||||
}
|
||||
registeredEvents := make(map[string]events.Unmarshaller)
|
||||
for _, e := range evs {
|
||||
typ := reflect.TypeOf(e)
|
||||
registeredEvents[typ.String()] = e
|
||||
}
|
||||
ch := make(chan events.Event)
|
||||
evts := NewEventsNotifier(ch, tc, log.NewLogger(), gatewaySelector, valueService, "",
|
||||
"", "", "", "", "",
|
||||
sender, store, historyClient, registeredEvents)
|
||||
go evts.Run()
|
||||
|
||||
// trigger sending
|
||||
ch <- events.Event{
|
||||
Event: events.SendEmailsEvent{
|
||||
Interval: interval,
|
||||
},
|
||||
}
|
||||
select {
|
||||
case <-tc.done:
|
||||
case <-time.Tick(3 * time.Second):
|
||||
Fail("timeout waiting for notification")
|
||||
}
|
||||
},
|
||||
|
||||
// daily
|
||||
Entry("Share Created daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`executant has shared "secrets of the board" with you.`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`executant has shared "secrets of the board" with you.`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.ShareCreated{}).String(),
|
||||
Event: events.ShareCreated{
|
||||
Sharer: executant.GetId(),
|
||||
GranteeUserID: receiver.GetId(),
|
||||
CTime: utils.TimeToTS(time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC)),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}}, "daily"),
|
||||
Entry("Share Expired daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`Your share to secrets of the board has expired at 2023-04-17 16:42:00
|
||||
|
||||
Even though this share has been revoked you still might have access through other shares and/or space memberships.`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`Your share to secrets of the board has expired at 2023-04-17 16:42:00<br><br>Even though this share has been revoked you still might have access through other shares and/or space memberships.`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.ShareExpired{}).String(),
|
||||
Event: events.ShareExpired{
|
||||
ShareOwner: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}}, "daily"),
|
||||
Entry("Added to Space daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`executant has invited you to join "secret space".`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`executant has invited you to join "secret space".`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.SpaceShared{}).String(),
|
||||
Event: events.SpaceShared{
|
||||
Executant: executant.GetId(),
|
||||
Creator: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
}}, "daily"),
|
||||
Entry("Removed from Space daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`executant has removed you from "secret space".
|
||||
|
||||
You might still have access through your other groups or direct membership.`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`executant has removed you from "secret space".<br><br>You might still have access through your other groups or direct membership.`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.SpaceUnshared{}).String(),
|
||||
Event: events.SpaceUnshared{
|
||||
Executant: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
}}, "daily"),
|
||||
Entry("Space Expired daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`Your membership of space secret space has expired at 2023-04-17 16:42:00
|
||||
|
||||
Even though this membership has expired you still might have access through other shares and/or space memberships`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`Your membership of space secret space has expired at 2023-04-17 16:42:00<br><br>Even though this membership has expired you still might have access through other shares and/or space memberships`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.SpaceMembershipExpired{}).String(),
|
||||
Event: events.SpaceMembershipExpired{
|
||||
SpaceOwner: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
SpaceID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
SpaceName: "secret space",
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
},
|
||||
}}, "daily"),
|
||||
Entry("Share Created and Space Expired grouped daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`executant has shared "secrets of the board" with you.
|
||||
|
||||
|
||||
Your membership of space secret space has expired at 2023-04-17 16:42:00
|
||||
|
||||
Even though this membership has expired you still might have access through other shares and/or space memberships`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`executant has shared "secrets of the board" with you.<br><br><br>Your membership of space secret space has expired at 2023-04-17 16:42:00<br><br>Even though this membership has expired you still might have access through other shares and/or space memberships`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{
|
||||
{
|
||||
Type: reflect.TypeOf(events.ShareCreated{}).String(),
|
||||
Event: events.ShareCreated{
|
||||
Sharer: executant.GetId(),
|
||||
GranteeUserID: receiver.GetId(),
|
||||
CTime: utils.TimeToTS(time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC)),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: reflect.TypeOf(events.SpaceMembershipExpired{}).String(),
|
||||
Event: events.SpaceMembershipExpired{
|
||||
SpaceOwner: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
SpaceID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
SpaceName: "secret space",
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
},
|
||||
},
|
||||
}, "daily"),
|
||||
|
||||
// weekly
|
||||
Entry("Share Created weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`executant has shared "secrets of the board" with you.`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`executant has shared "secrets of the board" with you.`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.ShareCreated{}).String(),
|
||||
Event: events.ShareCreated{
|
||||
Sharer: executant.GetId(),
|
||||
GranteeUserID: receiver.GetId(),
|
||||
CTime: utils.TimeToTS(time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC)),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}}, "weekly"),
|
||||
Entry("Share Expired weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`Your share to secrets of the board has expired at 2023-04-17 16:42:00
|
||||
|
||||
Even though this share has been revoked you still might have access through other shares and/or space memberships.`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`Your share to secrets of the board has expired at 2023-04-17 16:42:00<br><br>Even though this share has been revoked you still might have access through other shares and/or space memberships.`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.ShareExpired{}).String(),
|
||||
Event: events.ShareExpired{
|
||||
ShareOwner: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}}, "weekly"),
|
||||
Entry("Added to Space weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`executant has invited you to join "secret space".`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`executant has invited you to join "secret space".`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.SpaceShared{}).String(),
|
||||
Event: events.SpaceShared{
|
||||
Executant: executant.GetId(),
|
||||
Creator: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
}}, "weekly"),
|
||||
Entry("Removed from Space weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`executant has removed you from "secret space".
|
||||
|
||||
You might still have access through your other groups or direct membership.`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`executant has removed you from "secret space".<br><br>You might still have access through your other groups or direct membership.`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.SpaceUnshared{}).String(),
|
||||
Event: events.SpaceUnshared{
|
||||
Executant: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
}}, "weekly"),
|
||||
Entry("Space Expired weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`Your membership of space secret space has expired at 2023-04-17 16:42:00
|
||||
|
||||
Even though this membership has expired you still might have access through other shares and/or space memberships`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`Your membership of space secret space has expired at 2023-04-17 16:42:00<br><br>Even though this membership has expired you still might have access through other shares and/or space memberships`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.SpaceMembershipExpired{}).String(),
|
||||
Event: events.SpaceMembershipExpired{
|
||||
SpaceOwner: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
SpaceID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
SpaceName: "secret space",
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
},
|
||||
}}, "weekly"),
|
||||
Entry("Share Created and Space Expired grouped weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`executant has shared "secrets of the board" with you.
|
||||
|
||||
|
||||
Your membership of space secret space has expired at 2023-04-17 16:42:00
|
||||
|
||||
Even though this membership has expired you still might have access through other shares and/or space memberships`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`executant has shared "secrets of the board" with you.<br><br><br>Your membership of space secret space has expired at 2023-04-17 16:42:00<br><br>Even though this membership has expired you still might have access through other shares and/or space memberships`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{
|
||||
{
|
||||
Type: reflect.TypeOf(events.ShareCreated{}).String(),
|
||||
Event: events.ShareCreated{
|
||||
Sharer: executant.GetId(),
|
||||
GranteeUserID: receiver.GetId(),
|
||||
CTime: utils.TimeToTS(time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC)),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: reflect.TypeOf(events.SpaceMembershipExpired{}).String(),
|
||||
Event: events.SpaceMembershipExpired{
|
||||
SpaceOwner: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
SpaceID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
SpaceName: "secret space",
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
},
|
||||
},
|
||||
}, "weekly"),
|
||||
)
|
||||
})
|
||||
|
||||
func buildExpectedTextBodyGrouped(receiver string, events []string) string {
|
||||
body := strings.Join(events, "\n\n\n")
|
||||
return fmt.Sprintf(
|
||||
`Hi %s,
|
||||
|
||||
%s
|
||||
|
||||
|
||||
---
|
||||
ownCloud - Store. Share. Work.
|
||||
https://owncloud.com
|
||||
`, receiver, body)
|
||||
}
|
||||
|
||||
func buildExpectedHTMLBodyGrouped(receiver string, events []string) string {
|
||||
body := strings.Join(events, "<br><br><br>")
|
||||
return fmt.Sprintf(
|
||||
`<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<table cellspacing="0" cellpadding="0" border="0" width="100%%">
|
||||
<tr>
|
||||
<td>
|
||||
<table cellspacing="0" cellpadding="0" border="0" width="600px">
|
||||
<tr>
|
||||
<td width="20px"> </td>
|
||||
<td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">
|
||||
Hi %s,
|
||||
<br><br>
|
||||
%s
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20px"> </td>
|
||||
<td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">
|
||||
<footer>
|
||||
<br>
|
||||
<br>
|
||||
--- <br>
|
||||
ownCloud - Store. Share. Work.<br>
|
||||
<a href="https://owncloud.com">https://owncloud.com</a>
|
||||
</footer>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
`, receiver, body)
|
||||
}
|
||||
|
||||
// NOTE: This is explicitly not testing the message itself. Should we?
|
||||
type testChannel struct {
|
||||
expectedReceipients []string
|
||||
expectedSubject string
|
||||
@@ -470,7 +1182,7 @@ type testChannel struct {
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func (tc testChannel) SendMessage(ctx context.Context, m *channels.Message) error {
|
||||
func (tc testChannel) SendMessage(_ context.Context, m *channels.Message) error {
|
||||
defer GinkgoRecover()
|
||||
|
||||
Expect(tc.expectedReceipients).To(Equal(m.Recipient))
|
||||
@@ -483,3 +1195,14 @@ func (tc testChannel) SendMessage(ctx context.Context, m *channels.Message) erro
|
||||
tc.done <- struct{}{}
|
||||
return nil
|
||||
}
|
||||
|
||||
type testChannelGroupedStore struct {
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func (tc testChannelGroupedStore) SendMessage(_ context.Context, _ *channels.Message) error {
|
||||
defer GinkgoRecover()
|
||||
|
||||
tc.done <- struct{}{}
|
||||
return nil
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
with-expecter: true
|
||||
filename: "{{.InterfaceName | snakecase }}.go"
|
||||
dir: "{{.InterfaceDir}}/mocks"
|
||||
mockname: "{{.InterfaceName}}"
|
||||
outpkg: "mocks"
|
||||
packages:
|
||||
go-micro.dev/v4/store:
|
||||
interfaces:
|
||||
Store:
|
||||
+495
@@ -0,0 +1,495 @@
|
||||
// Code generated by mockery v2.50.4. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
store "go-micro.dev/v4/store"
|
||||
)
|
||||
|
||||
// Store is an autogenerated mock type for the Store type
|
||||
type Store struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
type Store_Expecter struct {
|
||||
mock *mock.Mock
|
||||
}
|
||||
|
||||
func (_m *Store) EXPECT() *Store_Expecter {
|
||||
return &Store_Expecter{mock: &_m.Mock}
|
||||
}
|
||||
|
||||
// Close provides a mock function with no fields
|
||||
func (_m *Store) Close() error {
|
||||
ret := _m.Called()
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Close")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func() error); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Store_Close_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Close'
|
||||
type Store_Close_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Close is a helper method to define mock.On call
|
||||
func (_e *Store_Expecter) Close() *Store_Close_Call {
|
||||
return &Store_Close_Call{Call: _e.mock.On("Close")}
|
||||
}
|
||||
|
||||
func (_c *Store_Close_Call) Run(run func()) *Store_Close_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run()
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Close_Call) Return(_a0 error) *Store_Close_Call {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Close_Call) RunAndReturn(run func() error) *Store_Close_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Delete provides a mock function with given fields: key, opts
|
||||
func (_m *Store) Delete(key string, opts ...store.DeleteOption) error {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, key)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Delete")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string, ...store.DeleteOption) error); ok {
|
||||
r0 = rf(key, opts...)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Store_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete'
|
||||
type Store_Delete_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Delete is a helper method to define mock.On call
|
||||
// - key string
|
||||
// - opts ...store.DeleteOption
|
||||
func (_e *Store_Expecter) Delete(key interface{}, opts ...interface{}) *Store_Delete_Call {
|
||||
return &Store_Delete_Call{Call: _e.mock.On("Delete",
|
||||
append([]interface{}{key}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *Store_Delete_Call) Run(run func(key string, opts ...store.DeleteOption)) *Store_Delete_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]store.DeleteOption, len(args)-1)
|
||||
for i, a := range args[1:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(store.DeleteOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(string), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Delete_Call) Return(_a0 error) *Store_Delete_Call {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Delete_Call) RunAndReturn(run func(string, ...store.DeleteOption) error) *Store_Delete_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Init provides a mock function with given fields: _a0
|
||||
func (_m *Store) Init(_a0 ...store.Option) error {
|
||||
_va := make([]interface{}, len(_a0))
|
||||
for _i := range _a0 {
|
||||
_va[_i] = _a0[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Init")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(...store.Option) error); ok {
|
||||
r0 = rf(_a0...)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Store_Init_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Init'
|
||||
type Store_Init_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Init is a helper method to define mock.On call
|
||||
// - _a0 ...store.Option
|
||||
func (_e *Store_Expecter) Init(_a0 ...interface{}) *Store_Init_Call {
|
||||
return &Store_Init_Call{Call: _e.mock.On("Init",
|
||||
append([]interface{}{}, _a0...)...)}
|
||||
}
|
||||
|
||||
func (_c *Store_Init_Call) Run(run func(_a0 ...store.Option)) *Store_Init_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]store.Option, len(args)-0)
|
||||
for i, a := range args[0:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(store.Option)
|
||||
}
|
||||
}
|
||||
run(variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Init_Call) Return(_a0 error) *Store_Init_Call {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Init_Call) RunAndReturn(run func(...store.Option) error) *Store_Init_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// List provides a mock function with given fields: opts
|
||||
func (_m *Store) List(opts ...store.ListOption) ([]string, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for List")
|
||||
}
|
||||
|
||||
var r0 []string
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(...store.ListOption) ([]string, error)); ok {
|
||||
return rf(opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(...store.ListOption) []string); ok {
|
||||
r0 = rf(opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]string)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(...store.ListOption) error); ok {
|
||||
r1 = rf(opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Store_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List'
|
||||
type Store_List_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// List is a helper method to define mock.On call
|
||||
// - opts ...store.ListOption
|
||||
func (_e *Store_Expecter) List(opts ...interface{}) *Store_List_Call {
|
||||
return &Store_List_Call{Call: _e.mock.On("List",
|
||||
append([]interface{}{}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *Store_List_Call) Run(run func(opts ...store.ListOption)) *Store_List_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]store.ListOption, len(args)-0)
|
||||
for i, a := range args[0:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(store.ListOption)
|
||||
}
|
||||
}
|
||||
run(variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_List_Call) Return(_a0 []string, _a1 error) *Store_List_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_List_Call) RunAndReturn(run func(...store.ListOption) ([]string, error)) *Store_List_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Options provides a mock function with no fields
|
||||
func (_m *Store) Options() store.Options {
|
||||
ret := _m.Called()
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Options")
|
||||
}
|
||||
|
||||
var r0 store.Options
|
||||
if rf, ok := ret.Get(0).(func() store.Options); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(store.Options)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Store_Options_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Options'
|
||||
type Store_Options_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Options is a helper method to define mock.On call
|
||||
func (_e *Store_Expecter) Options() *Store_Options_Call {
|
||||
return &Store_Options_Call{Call: _e.mock.On("Options")}
|
||||
}
|
||||
|
||||
func (_c *Store_Options_Call) Run(run func()) *Store_Options_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run()
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Options_Call) Return(_a0 store.Options) *Store_Options_Call {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Options_Call) RunAndReturn(run func() store.Options) *Store_Options_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Read provides a mock function with given fields: key, opts
|
||||
func (_m *Store) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, key)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Read")
|
||||
}
|
||||
|
||||
var r0 []*store.Record
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(string, ...store.ReadOption) ([]*store.Record, error)); ok {
|
||||
return rf(key, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(string, ...store.ReadOption) []*store.Record); ok {
|
||||
r0 = rf(key, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*store.Record)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(string, ...store.ReadOption) error); ok {
|
||||
r1 = rf(key, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Store_Read_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Read'
|
||||
type Store_Read_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Read is a helper method to define mock.On call
|
||||
// - key string
|
||||
// - opts ...store.ReadOption
|
||||
func (_e *Store_Expecter) Read(key interface{}, opts ...interface{}) *Store_Read_Call {
|
||||
return &Store_Read_Call{Call: _e.mock.On("Read",
|
||||
append([]interface{}{key}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *Store_Read_Call) Run(run func(key string, opts ...store.ReadOption)) *Store_Read_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]store.ReadOption, len(args)-1)
|
||||
for i, a := range args[1:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(store.ReadOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(string), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Read_Call) Return(_a0 []*store.Record, _a1 error) *Store_Read_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Read_Call) RunAndReturn(run func(string, ...store.ReadOption) ([]*store.Record, error)) *Store_Read_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// String provides a mock function with no fields
|
||||
func (_m *Store) String() string {
|
||||
ret := _m.Called()
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for String")
|
||||
}
|
||||
|
||||
var r0 string
|
||||
if rf, ok := ret.Get(0).(func() string); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Get(0).(string)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Store_String_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'String'
|
||||
type Store_String_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// String is a helper method to define mock.On call
|
||||
func (_e *Store_Expecter) String() *Store_String_Call {
|
||||
return &Store_String_Call{Call: _e.mock.On("String")}
|
||||
}
|
||||
|
||||
func (_c *Store_String_Call) Run(run func()) *Store_String_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run()
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_String_Call) Return(_a0 string) *Store_String_Call {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_String_Call) RunAndReturn(run func() string) *Store_String_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Write provides a mock function with given fields: r, opts
|
||||
func (_m *Store) Write(r *store.Record, opts ...store.WriteOption) error {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, r)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Write")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(*store.Record, ...store.WriteOption) error); ok {
|
||||
r0 = rf(r, opts...)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// Store_Write_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Write'
|
||||
type Store_Write_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Write is a helper method to define mock.On call
|
||||
// - r *store.Record
|
||||
// - opts ...store.WriteOption
|
||||
func (_e *Store_Expecter) Write(r interface{}, opts ...interface{}) *Store_Write_Call {
|
||||
return &Store_Write_Call{Call: _e.mock.On("Write",
|
||||
append([]interface{}{r}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *Store_Write_Call) Run(run func(r *store.Record, opts ...store.WriteOption)) *Store_Write_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]store.WriteOption, len(args)-1)
|
||||
for i, a := range args[1:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(store.WriteOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(*store.Record), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Write_Call) Return(_a0 error) *Store_Write_Call {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *Store_Write_Call) RunAndReturn(run func(*store.Record, ...store.WriteOption) error) *Store_Write_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// NewStore creates a new instance of Store. 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 NewStore(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *Store {
|
||||
mock := &Store{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
||||
Vendored
+3
-2
@@ -1880,7 +1880,7 @@ github.com/xrash/smetrics
|
||||
# github.com/yashtewari/glob-intersection v0.2.0
|
||||
## explicit; go 1.17
|
||||
github.com/yashtewari/glob-intersection
|
||||
# go-micro.dev/v4 v4.11.0 => github.com/kobergj/go-micro/v4 v4.0.0-20250116171647-71d591d05282
|
||||
# go-micro.dev/v4 v4.11.0 => github.com/kobergj/go-micro/v4 v4.0.0-20250117084952-d07d30666b7c
|
||||
## explicit; go 1.18
|
||||
go-micro.dev/v4
|
||||
go-micro.dev/v4/api
|
||||
@@ -1936,6 +1936,7 @@ go-micro.dev/v4/runtime/local/source
|
||||
go-micro.dev/v4/selector
|
||||
go-micro.dev/v4/server
|
||||
go-micro.dev/v4/store
|
||||
go-micro.dev/v4/store/mocks
|
||||
go-micro.dev/v4/transport
|
||||
go-micro.dev/v4/transport/headers
|
||||
go-micro.dev/v4/util/addr
|
||||
@@ -2402,4 +2403,4 @@ stash.kopano.io/kgol/rndm
|
||||
# github.com/egirna/icap-client => github.com/kobergj/icap-client v0.0.0-20250116172800-8eaa5022532b
|
||||
# github.com/unrolled/secure => github.com/DeepDiver1975/secure v0.0.0-20240611112133-abc838fb797c
|
||||
# github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20240807130109-f62bb67e8c90
|
||||
# go-micro.dev/v4 => github.com/kobergj/go-micro/v4 v4.0.0-20250116171647-71d591d05282
|
||||
# go-micro.dev/v4 => github.com/kobergj/go-micro/v4 v4.0.0-20250117084952-d07d30666b7c
|
||||
Reference in new issue
Block a user