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

refactor

parent ff905f68
Branches
Tags
No related merge requests found
...@@ -5,8 +5,8 @@ import ( ...@@ -5,8 +5,8 @@ import (
"testing" "testing"
"time" "time"
"git.perx.ru/perxis/perxis-go/pkg/log" "git.perx.ru/perxis/perxis-go/log"
logmocks "git.perx.ru/perxis/perxis-go/pkg/log/mocks" logmocks "git.perx.ru/perxis/perxis-go/log/mocks"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
......
...@@ -72,8 +72,8 @@ func (core *Core) getEntry(entry zapcore.Entry, fields []zapcore.Field) *log.Ent ...@@ -72,8 +72,8 @@ func (core *Core) getEntry(entry zapcore.Entry, fields []zapcore.Field) *log.Ent
ent.Category, _ = enc.Fields["category"].(string) ent.Category, _ = enc.Fields["category"].(string)
ent.Component, _ = enc.Fields["component"].(string) ent.Component, _ = enc.Fields["component"].(string)
ent.Event, _ = enc.Fields["event"].(string) ent.Event, _ = enc.Fields["event"].(string)
ent.ObjectID, _ = enc.Fields["object"].(*oid.ObjectId) ent.ObjectID, _ = enc.Fields["object_id"].(*oid.ObjectId)
ent.CallerID, _ = enc.Fields["caller"].(*oid.ObjectId) ent.CallerID, _ = enc.Fields["caller_id"].(*oid.ObjectId)
ent.Attr = enc.Fields["attr"] ent.Attr = enc.Fields["attr"]
if tags, ok := enc.Fields["tags"].([]any); ok { if tags, ok := enc.Fields["tags"].([]any); ok {
......
...@@ -3,6 +3,7 @@ package zap ...@@ -3,6 +3,7 @@ package zap
import ( import (
"testing" "testing"
"git.perx.ru/perxis/perxis-go/id"
"git.perx.ru/perxis/perxis-go/log" "git.perx.ru/perxis/perxis-go/log"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.uber.org/zap" "go.uber.org/zap"
...@@ -32,8 +33,8 @@ func TestCore_getEntry(t *testing.T) { ...@@ -32,8 +33,8 @@ func TestCore_getEntry(t *testing.T) {
Category("create"), Category("create"),
Component("Items.Service"), Component("Items.Service"),
Event("Items.Create"), Event("Items.Create"),
Object("/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl"), ObjectID("/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl"),
Caller("/users/PHVz"), CallerID("/users/PHVz"),
Attr("any"), Attr("any"),
Tags("tag1", "tag2", "tag3"), Tags("tag1", "tag2", "tag3"),
}, },
...@@ -44,8 +45,8 @@ func TestCore_getEntry(t *testing.T) { ...@@ -44,8 +45,8 @@ func TestCore_getEntry(t *testing.T) {
Category: "create", Category: "create",
Component: "Items.Service", Component: "Items.Service",
Event: "Items.Create", Event: "Items.Create",
ObjectID: "/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl", ObjectID: id.MustObjectId("/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl"),
CallerID: "/users/PHVz", CallerID: id.MustObjectId("/users/PHVz"),
Attr: "any", Attr: "any",
Tags: []string{"tag1", "tag2", "tag3"}, Tags: []string{"tag1", "tag2", "tag3"},
}, },
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"slices" "slices"
"testing" "testing"
"git.perx.ru/perxis/perxis-go/id"
"git.perx.ru/perxis/perxis-go/log" "git.perx.ru/perxis/perxis-go/log"
logmocks "git.perx.ru/perxis/perxis-go/log/mocks" logmocks "git.perx.ru/perxis/perxis-go/log/mocks"
"git.perx.ru/perxis/perxis-go/pkg/auth" "git.perx.ru/perxis/perxis-go/pkg/auth"
...@@ -19,14 +20,17 @@ import ( ...@@ -19,14 +20,17 @@ import (
) )
func TestExample(t *testing.T) { func TestExample(t *testing.T) {
item := items.NewItem("WPNN", "9VGP", "GxNv", "W0fl", nil, nil)
user := &users.User{ID: "294de355"}
wantEntries := []*log.Entry{ wantEntries := []*log.Entry{
{ {
LogLevel: log.Level(zapcore.InfoLevel), LogLevel: log.Level(zapcore.InfoLevel),
Message: "Successfully created", Message: "Successfully created",
Component: "Items", Component: "Items",
Event: items.EventCreateItem, Event: items.EventCreateItem,
ObjectID: "/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl", ObjectID: id.MustObjectId(item),
CallerID: "/users/294de355", CallerID: id.MustObjectId(user),
Tags: []string{"tag1", "tag2", "tag3"}, Tags: []string{"tag1", "tag2", "tag3"},
}, },
{ {
...@@ -34,8 +38,8 @@ func TestExample(t *testing.T) { ...@@ -34,8 +38,8 @@ func TestExample(t *testing.T) {
Message: "Successfully updated", Message: "Successfully updated",
Component: "Items", Component: "Items",
Event: items.EventUpdateItem, Event: items.EventUpdateItem,
ObjectID: "/spaces/WPNN/envs/9VGP/cols/GxNv/items/cmV2cw", ObjectID: id.MustObjectId(item),
CallerID: "/users/294de355", CallerID: id.MustObjectId(user),
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"}},
}, },
} }
...@@ -56,7 +60,7 @@ func TestExample(t *testing.T) { ...@@ -56,7 +60,7 @@ func TestExample(t *testing.T) {
Once() Once()
usersService := &usersmocks.Users{} usersService := &usersmocks.Users{}
usersService.On("GetByIdentity", mock.Anything, "74d90aaf").Return(&users.User{ID: "294de355"}, nil).Once() usersService.On("GetByIdentity", mock.Anything, "74d90aaf").Return(user, nil).Once()
factory := auth.PrincipalFactory{Users: usersService} factory := auth.PrincipalFactory{Users: usersService}
...@@ -71,16 +75,16 @@ func TestExample(t *testing.T) { ...@@ -71,16 +75,16 @@ func TestExample(t *testing.T) {
// Отправка лога при создании item // Отправка лога при создании item
logger.Info("Successfully created", logger.Info("Successfully created",
Event(items.EventCreateItem), Event(items.EventCreateItem),
Object(items.NewItem("WPNN", "9VGP", "GxNv", "W0fl", nil, nil)), ObjectID(item),
CallerFromContext(ctx), CallerIDFromContext(ctx),
Tags("tag1", "tag2", "tag3"), Tags("tag1", "tag2", "tag3"),
) )
// Отправка лога при обновлении item // Отправка лога при обновлении item
logger.Warn("Successfully updated", logger.Warn("Successfully updated",
Event(items.EventUpdateItem), Event(items.EventUpdateItem),
Object(items.NewItem("WPNN", "9VGP", "GxNv", "cmV2cw", nil, nil)), ObjectID(item),
CallerFromContext(ctx), CallerIDFromContext(ctx),
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"}}),
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment