Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
0f4952c3
Commit
0f4952c3
authored
1 year ago
by
Semyon Krestyaninov
Browse files
Options
Downloads
Patches
Plain Diff
Revert "refactor tests and fix events"
This reverts commit
ac5b5d39
.
parent
707c4f4d
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
log/zap/buffered_write_syncer_test.go
+21
-9
21 additions, 9 deletions
log/zap/buffered_write_syncer_test.go
log/zap/core_test.go
+8
-8
8 additions, 8 deletions
log/zap/core_test.go
log/zap/example_test.go
+12
-12
12 additions, 12 deletions
log/zap/example_test.go
with
41 additions
and
29 deletions
log/zap/buffered_write_syncer_test.go
+
21
−
9
View file @
0f4952c3
...
...
@@ -53,12 +53,16 @@ func TestBufferedWriteSyncer_Write_Concurrent(t *testing.T) {
wg
.
Add
(
1
)
go
func
(
wg
*
sync
.
WaitGroup
)
{
defer
wg
.
Done
()
require
.
NoError
(
t
,
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
}))
err
:=
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
})
require
.
NoError
(
t
,
err
)
}(
&
wg
)
}
wg
.
Wait
()
require
.
NoError
(
t
,
ws
.
Stop
())
err
:=
ws
.
Stop
()
require
.
NoError
(
t
,
err
)
service
.
AssertExpectations
(
t
)
}
...
...
@@ -77,12 +81,15 @@ func TestBufferedWriteSyncer_Flush(t *testing.T) {
for
i
:=
0
;
i
<
10
;
i
++
{
for
j
:=
0
;
j
<
10
;
j
++
{
require
.
NoError
(
t
,
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
}))
err
:=
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
})
require
.
NoError
(
t
,
err
)
}
require
.
NoError
(
t
,
ws
.
Sync
())
err
:=
ws
.
Sync
()
require
.
NoError
(
t
,
err
)
}
require
.
NoError
(
t
,
ws
.
Stop
())
err
:=
ws
.
Stop
()
require
.
NoError
(
t
,
err
)
service
.
AssertExpectations
(
t
)
}
...
...
@@ -100,10 +107,12 @@ func TestBufferedWriteSyncer_MaxBufferSize(t *testing.T) {
ws
:=
&
BufferedWriteSyncer
{
Service
:
service
,
MaxBufferSize
:
10
}
for
i
:=
0
;
i
<
100
;
i
++
{
require
.
NoError
(
t
,
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
}))
err
:=
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
})
require
.
NoError
(
t
,
err
)
}
require
.
NoError
(
t
,
ws
.
Stop
())
err
:=
ws
.
Stop
()
require
.
NoError
(
t
,
err
)
service
.
AssertExpectations
(
t
)
}
...
...
@@ -121,11 +130,14 @@ func TestBufferedWriteSyncer_FlushInterval(t *testing.T) {
ws
:=
&
BufferedWriteSyncer
{
Service
:
service
,
FlushInterval
:
time
.
Second
}
for
j
:=
0
;
j
<
10
;
j
++
{
require
.
NoError
(
t
,
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
}))
err
:=
ws
.
Write
(
&
log
.
Entry
{
Message
:
"log message"
})
require
.
NoError
(
t
,
err
)
}
time
.
Sleep
(
3
*
time
.
Second
)
// ждем, пока сработает интервал
require
.
NoError
(
t
,
ws
.
Stop
())
err
:=
ws
.
Stop
()
require
.
NoError
(
t
,
err
)
service
.
AssertExpectations
(
t
)
}
This diff is collapsed.
Click to expand it.
log/zap/core_test.go
+
8
−
8
View file @
0f4952c3
...
...
@@ -5,7 +5,7 @@ import (
"git.perx.ru/perxis/perxis-go/id"
"git.perx.ru/perxis/perxis-go/log"
log
zap
"git.perx.ru/perxis/perxis-go/zap"
zap
2
"git.perx.ru/perxis/perxis-go/zap"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
...
...
@@ -31,13 +31,13 @@ func TestCore_getEntry(t *testing.T) {
entry
:
zapcore
.
Entry
{
Level
:
zapcore
.
InfoLevel
,
Message
:
"создан элемент коллекции"
},
fields
:
[]
zapcore
.
Field
{
zap
.
String
(
"key"
,
"val"
),
// будет проигнорировано
log
zap
.
Category
(
"create"
),
log
zap
.
Component
(
"Items.Service"
),
log
zap
.
Event
(
"Items.Create"
),
log
zap
.
Object
(
"/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl"
),
log
zap
.
Caller
(
"/users/PHVz"
),
log
zap
.
Attr
(
"any"
),
log
zap
.
Tags
(
"tag1"
,
"tag2"
,
"tag3"
),
zap
2
.
Category
(
"create"
),
zap
2
.
Component
(
"Items.Service"
),
zap
2
.
Event
(
"Items.Create"
),
zap
2
.
Object
(
"/spaces/WPNN/envs/9VGP/cols/GxNv/items/W0fl"
),
zap
2
.
Caller
(
"/users/PHVz"
),
zap
2
.
Attr
(
"any"
),
zap
2
.
Tags
(
"tag1"
,
"tag2"
,
"tag3"
),
},
},
want
:
&
log
.
Entry
{
...
...
This diff is collapsed.
Click to expand it.
log/zap/example_test.go
+
12
−
12
View file @
0f4952c3
...
...
@@ -13,7 +13,7 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/items"
"git.perx.ru/perxis/perxis-go/pkg/users"
usersmocks
"git.perx.ru/perxis/perxis-go/pkg/users/mocks"
log
zap
"git.perx.ru/perxis/perxis-go/zap"
zap
2
"git.perx.ru/perxis/perxis-go/zap"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
...
...
@@ -29,7 +29,7 @@ func TestExample(t *testing.T) {
LogLevel
:
log
.
Level
(
zapcore
.
InfoLevel
),
Message
:
"Successfully created"
,
Component
:
"Items"
,
Event
:
items
.
Event
Item
Create
,
Event
:
items
.
EventCreate
Item
,
ObjectID
:
id
.
MustObjectId
(
item
),
CallerID
:
id
.
MustObjectId
(
user
),
Tags
:
[]
string
{
"tag1"
,
"tag2"
,
"tag3"
},
...
...
@@ -38,7 +38,7 @@ func TestExample(t *testing.T) {
LogLevel
:
log
.
Level
(
zapcore
.
WarnLevel
),
Message
:
"Successfully updated"
,
Component
:
"Items"
,
Event
:
items
.
Event
Item
Update
,
Event
:
items
.
EventUpdate
Item
,
ObjectID
:
id
.
MustObjectId
(
item
),
CallerID
:
id
.
MustObjectId
(
user
),
Attr
:
map
[
string
]
map
[
string
]
any
{
"title"
:
{
"old"
:
"old title"
,
"new"
:
"new title"
}},
...
...
@@ -70,23 +70,23 @@ func TestExample(t *testing.T) {
// Пример отправки логов для сервиса Items
{
logger
:=
logger
.
With
(
log
zap
.
Component
(
"Items"
))
logger
:=
logger
.
With
(
zap
2
.
Component
(
"Items"
))
ctx
:=
auth
.
WithPrincipal
(
context
.
Background
(),
factory
.
User
(
"74d90aaf"
))
// Отправка лога при создании item
logger
.
Info
(
"Successfully created"
,
log
zap
.
Event
(
items
.
Event
Item
Create
),
log
zap
.
Object
(
item
),
log
zap
.
CallerFromContext
(
ctx
),
log
zap
.
Tags
(
"tag1"
,
"tag2"
,
"tag3"
),
zap
2
.
Event
(
items
.
EventCreate
Item
),
zap
2
.
Object
(
item
),
zap
2
.
CallerFromContext
(
ctx
),
zap
2
.
Tags
(
"tag1"
,
"tag2"
,
"tag3"
),
)
// Отправка лога при обновлении item
logger
.
Warn
(
"Successfully updated"
,
log
zap
.
Event
(
items
.
Event
Item
Update
),
log
zap
.
Object
(
item
),
log
zap
.
CallerFromContext
(
ctx
),
log
zap
.
Attr
(
map
[
string
]
map
[
string
]
any
{
"title"
:
{
"old"
:
"old title"
,
"new"
:
"new title"
}}),
zap
2
.
Event
(
items
.
EventUpdate
Item
),
zap
2
.
Object
(
item
),
zap
2
.
CallerFromContext
(
ctx
),
zap
2
.
Attr
(
map
[
string
]
map
[
string
]
any
{
"title"
:
{
"old"
:
"old title"
,
"new"
:
"new title"
}}),
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment