2024-06-12 23:11:35 -05:00
|
|
|
package identity_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRequesterFromContext(t *testing.T) {
|
|
|
|
t.Run("User should error when context is missing user", func(t *testing.T) {
|
|
|
|
usr, err := identity.GetRequester(context.Background())
|
|
|
|
require.Nil(t, usr)
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("should return user set by ContextWithUser", func(t *testing.T) {
|
2024-06-14 01:04:06 -05:00
|
|
|
expected := &identity.StaticRequester{UserUID: "AAA"}
|
2024-06-12 23:11:35 -05:00
|
|
|
ctx := identity.WithRequester(context.Background(), expected)
|
|
|
|
actual, err := identity.GetRequester(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, expected.GetUID(), actual.GetUID())
|
|
|
|
})
|
|
|
|
}
|