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
bd6dcbff
Commit
bd6dcbff
authored
1 year ago
by
Danis Kirasirov
Browse files
Options
Downloads
Patches
Plain Diff
Использование Stub вместо Dummy
parent
1791c2bc
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
pkg/items/dummy.go
+0
-38
0 additions, 38 deletions
pkg/items/dummy.go
pkg/items/pagination_test.go
+11
-18
11 additions, 18 deletions
pkg/items/pagination_test.go
pkg/items/stub.go
+35
-0
35 additions, 0 deletions
pkg/items/stub.go
with
46 additions
and
56 deletions
pkg/items/dummy.go
deleted
100644 → 0
+
0
−
38
View file @
1791c2bc
package
items
import
(
"context"
)
type
FindResultDummy
struct
{
Items
[]
*
Item
Total
int
Error
error
}
type
Dummy
struct
{
Items
FindResult
*
FindResultDummy
}
func
(
d
*
Dummy
)
Find
(
_
context
.
Context
,
_
,
_
,
_
string
,
_
*
Filter
,
_
...*
FindOptions
)
([]
*
Item
,
int
,
error
)
{
return
d
.
FindResult
.
Items
,
d
.
FindResult
.
Total
,
d
.
FindResult
.
Error
}
type
StubFindResult
struct
{
Total
int
}
type
Stub
struct
{
Items
FindResult
*
StubFindResult
}
func
(
d
*
Stub
)
Find
(
_
context
.
Context
,
_
,
_
,
_
string
,
_
*
Filter
,
opts
...*
FindOptions
)
([]
*
Item
,
int
,
error
)
{
fo
:=
MergeFindOptions
(
opts
...
)
return
make
([]
*
Item
,
fo
.
Limit
),
d
.
FindResult
.
Total
,
nil
}
func
(
d
*
Stub
)
FindPublished
(
_
context
.
Context
,
_
,
_
,
_
string
,
_
*
Filter
,
opts
...*
FindPublishedOptions
)
([]
*
Item
,
int
,
error
)
{
fo
:=
MergeFindPublishedOptions
(
opts
...
)
return
make
([]
*
Item
,
fo
.
Limit
),
d
.
FindResult
.
Total
,
nil
}
This diff is collapsed.
Click to expand it.
pkg/items/pagination_test.go
+
11
−
18
View file @
bd6dcbff
...
...
@@ -12,7 +12,11 @@ import (
func
TestBatchProcessor
(
t
*
testing
.
T
)
{
t
.
Run
(
"EmptyResults"
,
func
(
t
*
testing
.
T
)
{
itemssvc
:=
&
Dummy
{
FindResult
:
&
FindResultDummy
{
Items
:
nil
,
Total
:
0
,
Error
:
nil
}}
itemssvc
:=
&
Stub
{
FindResult
:
func
(
req
StubFindRequest
)
StubFindResult
{
return
StubFindResult
{
Items
:
nil
,
Total
:
0
,
Error
:
nil
}
},
}
b
:=
&
BatchProcessor
{
Items
:
itemssvc
,
...
...
@@ -35,7 +39,12 @@ func TestBatchProcessor(t *testing.T) {
})
t
.
Run
(
"With FindOptions"
,
func
(
t
*
testing
.
T
)
{
itemssvc
:=
&
Stub
{
FindResult
:
&
StubFindResult
{
Total
:
1000
}}
itemssvc
:=
&
Stub
{
FindResult
:
func
(
req
StubFindRequest
)
StubFindResult
{
fo
:=
MergeFindOptions
(
req
.
Options
...
)
return
StubFindResult
{
Items
:
make
([]
*
Item
,
fo
.
Limit
),
Total
:
1000
,
Error
:
nil
}
},
}
b
:=
&
BatchProcessor
{
Items
:
itemssvc
,
SpaceID
:
"sp"
,
...
...
@@ -49,20 +58,4 @@ func TestBatchProcessor(t *testing.T) {
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
1000
/
25
,
counter
)
})
t
.
Run
(
"With FindPublishedOptions"
,
func
(
t
*
testing
.
T
)
{
itemssvc
:=
&
Stub
{
FindResult
:
&
StubFindResult
{
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.
pkg/items/stub.go
0 → 100644
+
35
−
0
View file @
bd6dcbff
package
items
import
(
"context"
)
type
StubFindRequest
struct
{
Context
context
.
Context
SpaceID
,
EnvID
,
CollID
string
Filter
*
Filter
Options
[]
*
FindOptions
}
type
StubFindResult
struct
{
Items
[]
*
Item
Total
int
Error
error
}
type
Stub
struct
{
Items
FindResult
func
(
req
StubFindRequest
)
StubFindResult
}
func
(
d
*
Stub
)
Find
(
ctx
context
.
Context
,
spaceID
,
envID
,
collID
string
,
filter
*
Filter
,
opts
...*
FindOptions
)
([]
*
Item
,
int
,
error
)
{
res
:=
d
.
FindResult
(
StubFindRequest
{
Context
:
ctx
,
SpaceID
:
spaceID
,
EnvID
:
envID
,
CollID
:
collID
,
Filter
:
filter
,
Options
:
opts
,
})
return
res
.
Items
,
res
.
Total
,
res
.
Error
}
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