39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package diagram
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"modelRT/common"
|
|
"modelRT/constants"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestClientTokenFromContext(t *testing.T) {
|
|
ctx := context.WithValue(context.Background(), constants.CtxKeyClientToken, "test-token")
|
|
token, err := clientTokenFromContext(ctx)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "test-token", token)
|
|
}
|
|
|
|
func TestClientTokenFromContextReturnsErrorWhenMissing(t *testing.T) {
|
|
for _, ctx := range []context.Context{nil, context.Background()} {
|
|
_, err := clientTokenFromContext(ctx)
|
|
require.Error(t, err)
|
|
assert.ErrorIs(t, err, common.ErrGetClientToken)
|
|
}
|
|
}
|
|
|
|
func TestRedisConstructorsReturnErrorInsteadOfPanickingWithoutToken(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
_, err := NewRedisZSet(ctx, "zset", 0, false)
|
|
assert.ErrorIs(t, err, common.ErrGetClientToken)
|
|
_, err = NewRedisSet(ctx, "set", 0, false)
|
|
assert.ErrorIs(t, err, common.ErrGetClientToken)
|
|
_, err = NewRedisHash(ctx, "hash", 0, false)
|
|
assert.ErrorIs(t, err, common.ErrGetClientToken)
|
|
}
|