mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-09-21 11:35:32 -04:00
userlog: consumer tests: use shared TestBus implementation from internal/eventstest
* instead of defining our own testBus struct in services/userlog, use
the one that was recently put into internal/eventstest with
e8cf677353 for exactly such purposes, just to reduce code
duplication
This commit is contained in:
1 parent
28db2dbf31
commit
ee3b7b2fc8
2 files changed
+11
-41
No files matched your search
@@ -16,6 +16,8 @@ func NewTestBus() TestBus {
|
||||
|
||||
type TestBus chan rev.Event
|
||||
|
||||
var _ rev.Stream = NewTestBus()
|
||||
|
||||
func (tb TestBus) Consume(_ string, _ ...microevents.ConsumeOption) (<-chan microevents.Event, error) {
|
||||
ch := make(chan microevents.Event)
|
||||
go func() {
|
||||
@@ -33,7 +35,11 @@ func (tb TestBus) Consume(_ string, _ ...microevents.ConsumeOption) (<-chan micr
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (tb TestBus) Publish(e any) string {
|
||||
func (tb TestBus) Publish(_ string, _ any, _ ...microevents.PublishOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tb TestBus) Push(e any) string {
|
||||
ev := rev.Event{
|
||||
ID: uuid.New().String(),
|
||||
Type: reflect.TypeOf(e).String(),
|
||||
|
||||
@@ -3,14 +3,12 @@ package consumer_test
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/google/uuid"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/events"
|
||||
@@ -19,11 +17,11 @@ import (
|
||||
"github.com/opencloud-eu/reva/v2/pkg/utils"
|
||||
cs3mocks "github.com/opencloud-eu/reva/v2/tests/cs3mocks/mocks"
|
||||
"github.com/stretchr/testify/mock"
|
||||
microevents "go-micro.dev/v4/events"
|
||||
microstore "go-micro.dev/v4/store"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/opencloud-eu/opencloud/internal/eventstest"
|
||||
"github.com/opencloud-eu/opencloud/pkg/log"
|
||||
settingsmsg "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/messages/settings/v0"
|
||||
settingssvc "github.com/opencloud-eu/opencloud/protogen/gen/opencloud/services/settings/v0"
|
||||
@@ -44,7 +42,7 @@ var _ = Describe("Userlog consumer", func() {
|
||||
}
|
||||
|
||||
cs *consumersvc.Service
|
||||
bus testBus
|
||||
bus eventstest.TestBus
|
||||
sto microstore.Store
|
||||
|
||||
gatewayClient *cs3mocks.GatewayAPIClient
|
||||
@@ -56,7 +54,7 @@ var _ = Describe("Userlog consumer", func() {
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
sto = store.Create()
|
||||
bus = testBus(make(chan events.Event))
|
||||
bus = eventstest.NewTestBus()
|
||||
|
||||
pool.RemoveSelector("GatewaySelector" + "eu.opencloud.api.gateway")
|
||||
gatewayClient = &cs3mocks.GatewayAPIClient{}
|
||||
@@ -122,7 +120,7 @@ var _ = Describe("Userlog consumer", func() {
|
||||
}()
|
||||
|
||||
ids := make(map[string]struct{})
|
||||
ids[bus.publish(events.SpaceDisabled{Executant: &user.UserId{OpaqueId: "executinguserid"}, ID: &provider.StorageSpaceId{OpaqueId: "spaceid"}})] = struct{}{}
|
||||
ids[bus.Push(events.SpaceDisabled{Executant: &user.UserId{OpaqueId: "executinguserid"}, ID: &provider.StorageSpaceId{OpaqueId: "spaceid"}})] = struct{}{}
|
||||
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
@@ -144,37 +142,3 @@ var _ = Describe("Userlog consumer", func() {
|
||||
close(bus)
|
||||
})
|
||||
})
|
||||
|
||||
type testBus chan events.Event
|
||||
|
||||
func (tb testBus) Consume(_ string, _ ...microevents.ConsumeOption) (<-chan microevents.Event, error) {
|
||||
ch := make(chan microevents.Event)
|
||||
go func() {
|
||||
for ev := range tb {
|
||||
b, _ := json.Marshal(ev.Event)
|
||||
ch <- microevents.Event{
|
||||
Payload: b,
|
||||
Metadata: map[string]string{
|
||||
events.MetadatakeyEventID: ev.ID,
|
||||
events.MetadatakeyEventType: ev.Type,
|
||||
},
|
||||
}
|
||||
}
|
||||
}()
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (tb testBus) Publish(_ string, _ any, _ ...microevents.PublishOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tb testBus) publish(e any) string {
|
||||
ev := events.Event{
|
||||
ID: uuid.New().String(),
|
||||
Type: reflect.TypeOf(e).String(),
|
||||
Event: e,
|
||||
}
|
||||
|
||||
tb <- ev
|
||||
return ev.ID
|
||||
}
|
||||
Reference in new issue
Block a user