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