mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-14 12:04:41 +00:00
Multitenant streams api (#72)
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"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"
|
||||
)
|
||||
@@ -13,15 +15,24 @@ func TestToken(t *testing.T) {
|
||||
|
||||
t.Run("WithoutTopic", func(t *testing.T) {
|
||||
var rsp pb.TokenResponse
|
||||
err := h.Token(context.TODO(), &pb.TokenRequest{}, &rsp)
|
||||
ctx := auth.ContextWithAccount(context.TODO(), &auth.Account{Issuer: "foo"})
|
||||
err := h.Token(ctx, &pb.TokenRequest{}, &rsp)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, rsp.Token)
|
||||
})
|
||||
|
||||
t.Run("WithTopic", func(t *testing.T) {
|
||||
var rsp pb.TokenResponse
|
||||
err := h.Token(context.TODO(), &pb.TokenRequest{Topic: "helloworld"}, &rsp)
|
||||
ctx := auth.ContextWithAccount(context.TODO(), &auth.Account{Issuer: "foo"})
|
||||
err := h.Token(ctx, &pb.TokenRequest{Topic: "helloworld"}, &rsp)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, rsp.Token)
|
||||
})
|
||||
|
||||
t.Run("WithBadTopic", func(t *testing.T) {
|
||||
var rsp pb.TokenResponse
|
||||
ctx := auth.ContextWithAccount(context.TODO(), &auth.Account{Issuer: "foo"})
|
||||
err := h.Token(ctx, &pb.TokenRequest{Topic: "helloworld-1"}, &rsp)
|
||||
assert.Equal(t, handler.ErrInvalidTopic, err)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user