mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-16 13:04:34 +00:00
Multitenant streams api (#72)
This commit is contained in:
@@ -2,9 +2,11 @@ package handler_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/micro/v3/service/auth"
|
||||
"github.com/micro/services/streams/handler"
|
||||
pb "github.com/micro/services/streams/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -12,30 +14,34 @@ import (
|
||||
|
||||
func TestPublish(t *testing.T) {
|
||||
msg := "{\"foo\":\"bar\"}"
|
||||
topic := uuid.New().String()
|
||||
topic := strings.ReplaceAll(uuid.New().String(), "-", "")
|
||||
|
||||
t.Run("MissingTopic", func(t *testing.T) {
|
||||
h := testHandler(t)
|
||||
err := h.Publish(context.TODO(), &pb.Message{Message: msg}, &pb.PublishResponse{})
|
||||
ctx := auth.ContextWithAccount(context.TODO(), &auth.Account{Issuer: "foo"})
|
||||
err := h.Publish(ctx, &pb.Message{Message: msg}, &pb.PublishResponse{})
|
||||
assert.Equal(t, handler.ErrMissingTopic, err)
|
||||
assert.Zero(t, h.Events.(*eventsMock).PublishCount)
|
||||
})
|
||||
|
||||
t.Run("MissingMessage", func(t *testing.T) {
|
||||
h := testHandler(t)
|
||||
err := h.Publish(context.TODO(), &pb.Message{Topic: topic}, &pb.PublishResponse{})
|
||||
ctx := auth.ContextWithAccount(context.TODO(), &auth.Account{Issuer: "foo"})
|
||||
err := h.Publish(ctx, &pb.Message{Topic: topic}, &pb.PublishResponse{})
|
||||
assert.Equal(t, handler.ErrMissingMessage, err)
|
||||
assert.Zero(t, h.Events.(*eventsMock).PublishCount)
|
||||
})
|
||||
|
||||
t.Run("ValidMessage", func(t *testing.T) {
|
||||
h := testHandler(t)
|
||||
err := h.Publish(context.TODO(), &pb.Message{
|
||||
ctx := auth.ContextWithAccount(context.TODO(), &auth.Account{Issuer: "foo"})
|
||||
err := h.Publish(ctx, &pb.Message{
|
||||
Topic: topic, Message: msg,
|
||||
}, &pb.PublishResponse{})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 1, h.Events.(*eventsMock).PublishCount)
|
||||
assert.Equal(t, msg, h.Events.(*eventsMock).PublishMessage)
|
||||
assert.Equal(t, topic, h.Events.(*eventsMock).PublishTopic)
|
||||
// topic is prefixed with acc issuer to implement multitenancy
|
||||
assert.Equal(t, "foo."+topic, h.Events.(*eventsMock).PublishTopic)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user