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
e8a751a7
Commit
e8a751a7
authored
1 year ago
by
Danis Kirasirov
Browse files
Options
Downloads
Patches
Plain Diff
Добавлен тест для BatchProcessor
parent
ce608c18
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/items/dummy.go
+9
-0
9 additions, 0 deletions
pkg/items/dummy.go
pkg/items/pagination_test.go
+18
-7
18 additions, 7 deletions
pkg/items/pagination_test.go
with
27 additions
and
7 deletions
pkg/items/dummy.go
+
9
−
0
View file @
e8a751a7
...
@@ -31,3 +31,12 @@ func (d *DummyWithOptions) Find(_ context.Context, _, _, _ string, _ *Filter, op
...
@@ -31,3 +31,12 @@ func (d *DummyWithOptions) Find(_ context.Context, _, _, _ string, _ *Filter, op
}
}
return
make
([]
*
Item
,
limit
),
d
.
Total
,
nil
return
make
([]
*
Item
,
limit
),
d
.
Total
,
nil
}
}
func
(
d
*
DummyWithOptions
)
FindPublished
(
_
context
.
Context
,
_
,
_
,
_
string
,
_
*
Filter
,
opts
...*
FindPublishedOptions
)
([]
*
Item
,
int
,
error
)
{
fo
:=
MergeFindPublishedOptions
(
opts
...
)
limit
:=
fo
.
Limit
if
limit
==
0
{
limit
=
fo
.
PageSize
}
return
make
([]
*
Item
,
limit
),
d
.
Total
,
nil
}
This diff is collapsed.
Click to expand it.
pkg/items/pagination_test.go
+
18
−
7
View file @
e8a751a7
...
@@ -34,19 +34,14 @@ func TestBatchProcessor(t *testing.T) {
...
@@ -34,19 +34,14 @@ func TestBatchProcessor(t *testing.T) {
assert
.
Equal
(
t
,
0
,
counter
)
assert
.
Equal
(
t
,
0
,
counter
)
})
})
t
.
Run
(
"
Succes
s"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"
With FindOption
s"
,
func
(
t
*
testing
.
T
)
{
itemssvc
:=
&
DummyWithOptions
{
Items
:
nil
,
Total
:
1000
}
itemssvc
:=
&
DummyWithOptions
{
Items
:
nil
,
Total
:
1000
}
b
:=
&
BatchProcessor
{
b
:=
&
BatchProcessor
{
Items
:
itemssvc
,
Items
:
itemssvc
,
SpaceID
:
"sp"
,
SpaceID
:
"sp"
,
EnvID
:
environments
.
DefaultEnvironment
,
EnvID
:
environments
.
DefaultEnvironment
,
CollectionID
:
"col"
,
CollectionID
:
"col"
,
FindOptions
:
&
FindOptions
{
FindOptions
:
&
FindOptions
{
FindOptions
:
*
options
.
New
(
0
,
25
)},
Regular
:
true
,
Hidden
:
true
,
Templates
:
true
,
FindOptions
:
*
options
.
New
(
0
,
25
),
},
}
}
var
counter
int
var
counter
int
...
@@ -54,4 +49,20 @@ func TestBatchProcessor(t *testing.T) {
...
@@ -54,4 +49,20 @@ func TestBatchProcessor(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
1000
/
25
,
counter
)
assert
.
Equal
(
t
,
1000
/
25
,
counter
)
})
})
t
.
Run
(
"With FindPublishedOptions"
,
func
(
t
*
testing
.
T
)
{
itemssvc
:=
&
DummyWithOptions
{
Items
:
nil
,
Total
:
60
}
b
:=
&
BatchProcessor
{
Items
:
itemssvc
,
SpaceID
:
"sp"
,
EnvID
:
environments
.
DefaultEnvironment
,
CollectionID
:
"col"
,
FindPublishedOptions
:
&
FindPublishedOptions
{
FindOptions
:
*
options
.
New
(
0
,
20
)},
}
var
counter
int
_
,
err
:=
b
.
Do
(
context
.
Background
(),
func
(
batch
[]
*
Item
)
error
{
counter
++
;
return
nil
})
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
60
/
20
,
counter
)
})
}
}
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