Skip to content
Snippets Groups Projects
Commit b781db9c authored by Semyon Krestyaninov's avatar Semyon Krestyaninov
Browse files

refactor example_test.go, replace anonymous principal to user

parent 7f258488
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,8 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/items"
"git.perx.ru/perxis/perxis-go/pkg/log"
logmocks "git.perx.ru/perxis/perxis-go/pkg/log/mocks"
"git.perx.ru/perxis/perxis-go/pkg/users"
usersmocks "git.perx.ru/perxis/perxis-go/pkg/users/mocks"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
......@@ -24,7 +26,7 @@ func TestExample(t *testing.T) {
Component: "Items",
Event: items.EventCreateItem,
Object: "/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl",
Caller: "/users/anonymous",
Caller: "/users/294de355",
Tags: []string{"tag1", "tag2", "tag3"},
},
{
......@@ -33,7 +35,7 @@ func TestExample(t *testing.T) {
Component: "Items",
Event: items.EventUpdateItem,
Object: "/spaces/WPNN/envs/9VGP/cols/GxNv/items/cmV2cw",
Caller: "/users/anonymous",
Caller: "/users/294de355",
Attr: map[string]map[string]any{"title": {"old": "old title", "new": "new title"}},
},
}
......@@ -53,13 +55,18 @@ func TestExample(t *testing.T) {
}).
Once()
usersService := &usersmocks.Users{}
usersService.On("GetByIdentity", mock.Anything, "74d90aaf").Return(&users.User{ID: "294de355"}, nil).Once()
factory := auth.PrincipalFactory{Users: usersService}
ws := &BufferedWriteSyncer{Service: service}
logger := zap.New(NewCore(ws))
// Пример отправки логов для сервиса Items
{
logger := logger.With(Component("Items"))
ctx := auth.WithPrincipal(context.Background(), &auth.Anonymous{})
ctx := auth.WithPrincipal(context.Background(), factory.User("74d90aaf"))
// Отправка лога при создании item
logger.Info("Successfully created",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment