mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-12 03:05:14 +00:00
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package handler_test
|
|
|
|
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"
|
|
)
|
|
|
|
func TestToken(t *testing.T) {
|
|
h := testHandler(t)
|
|
|
|
t.Run("WithoutTopic", func(t *testing.T) {
|
|
var rsp pb.TokenResponse
|
|
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
|
|
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)
|
|
})
|
|
}
|