Skip to content
Snippets Groups Projects
Commit 657f8c26 authored by ensiouel's avatar ensiouel
Browse files

fix test

parent a20f70cf
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,8 @@ package zap ...@@ -2,6 +2,8 @@ package zap
import ( import (
"context" "context"
"reflect"
"slices"
"testing" "testing"
"git.perx.ru/perxis/perxis-go/pkg/log" "git.perx.ru/perxis/perxis-go/pkg/log"
...@@ -9,6 +11,7 @@ import ( ...@@ -9,6 +11,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore"
) )
func TestExample(t *testing.T) { func TestExample(t *testing.T) {
...@@ -39,7 +42,34 @@ func TestExample(t *testing.T) { ...@@ -39,7 +42,34 @@ func TestExample(t *testing.T) {
err := ws.Stop() err := ws.Stop()
assert.NoError(t, err) assert.NoError(t, err)
wantEntries := []*log.Entry{
{
LogLevel: log.Level(zapcore.InfoLevel),
Message: "создан элемент коллекции",
Category: "create",
Component: "Items.Service",
Event: "Items.Create",
Object: "/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl",
Caller: "/users/PHVz",
Attr: "any",
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",
},
}
service.AssertCalled(t, "Log", mock.Anything, mock.MatchedBy(func(entries []*log.Entry) bool { service.AssertCalled(t, "Log", mock.Anything, mock.MatchedBy(func(entries []*log.Entry) bool {
return len(entries) == 2 return len(entries) == 2 && slices.EqualFunc(entries, wantEntries, func(entryA, entryB *log.Entry) bool {
entryA.ID = entryB.ID // игнорируем ID
entryA.Timestamp = entryB.Timestamp // игнорируем Timestamp
return reflect.DeepEqual(entryA, entryB)
})
})) }))
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment