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

refactor example_test.go

parent 378c7013
No related branches found
No related tags found
No related merge requests found
package zap
import (
"context"
"reflect"
"slices"
"testing"
"git.perx.ru/perxis/perxis-go/pkg/auth"
"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"
......@@ -18,22 +20,20 @@ func TestExample(t *testing.T) {
wantEntries := []*log.Entry{
{
LogLevel: log.Level(zapcore.InfoLevel),
Message: "создан элемент коллекции",
Category: "create",
Component: "Items.Service",
Event: "Items.Create",
Message: "Successfully created",
Component: "Items",
Event: items.EventCreateItem,
Object: "/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl",
Caller: "/users/PHVz",
Caller: "/users/anonymous",
Tags: []string{"tag1", "tag2", "tag3"},
},
{
LogLevel: log.Level(zapcore.WarnLevel),
Message: "изменен элемент коллекции",
Category: "update",
Component: "Items.Service",
Event: "Items.Update",
Object: "/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl/revs/cmV2cw",
Caller: "/users/PHVz",
Message: "Successfully updated",
Component: "Items",
Event: items.EventUpdateItem,
Object: "/spaces/WPNN/envs/9VGP/cols/GxNv/items/cmV2cw",
Caller: "/users/anonymous",
Attr: map[string]map[string]any{"title": {"old": "old title", "new": "new title"}},
},
}
......@@ -56,22 +56,25 @@ func TestExample(t *testing.T) {
ws := &BufferedWriteSyncer{Service: service}
logger := zap.New(NewCore(ws))
logger.Info("создан элемент коллекции",
Category("create"),
Component("Items.Service"),
Event("Items.Create"),
Object(items.NewItem("WPNN", "9VGP", "GxNv", "cmV2cw", nil, nil)),
Caller("/users/PHVz"),
{
logger := logger.With(Component("Items"))
ctx := auth.WithPrincipal(context.Background(), &auth.Anonymous{})
logger.Info("Successfully created",
Event(items.EventCreateItem),
Object(items.NewItem("WPNN", "9VGP", "GxNv", "W0fl", nil, nil)),
CallerFromContext(ctx),
Tags("tag1", "tag2", "tag3"),
)
logger.Warn("изменен элемент коллекции",
Category("update"),
Component("Items.Service"),
Event("Items.Update"),
Object("/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl/revs/cmV2cw"),
Caller("/users/PHVz"),
logger.Warn("Successfully updated",
Event(items.EventUpdateItem),
Object(items.NewItem("WPNN", "9VGP", "GxNv", "cmV2cw", nil, nil)),
CallerFromContext(ctx),
Attr(map[string]map[string]any{"title": {"old": "old title", "new": "new title"}}),
)
}
err := ws.Stop()
require.NoError(t, err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment