Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3c655b32
Commit
3c655b32
authored
Aug 12, 2020
by
Jonathan Schafer
Committed by
Michael Kozono
Aug 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for Vulnerabilities::FindingsPreloader
Also fixed the preloading for finding identifiers
parent
5b4dc684
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
0 deletions
+74
-0
ee/spec/lib/gitlab/vulnerabilities/findings_preloader_spec.rb
...pec/lib/gitlab/vulnerabilities/findings_preloader_spec.rb
+74
-0
No files found.
ee/spec/lib/gitlab/vulnerabilities/findings_preloader_spec.rb
0 → 100644
View file @
3c655b32
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Vulnerabilities
::
FindingsPreloader
do
describe
'.preload!'
do
def
preloaded_findings
Gitlab
::
Vulnerabilities
::
FindingsPreloader
.
preload!
(
Vulnerabilities
::
Finding
.
all
)
end
it
'does not preload data if not called'
do
create
(
:vulnerabilities_finding
,
scanner:
create
(
:vulnerabilities_scanner
))
control
=
ActiveRecord
::
QueryRecorder
.
new
{
Vulnerabilities
::
Finding
.
all
.
map
(
&
:scanner
)
}.
count
create_list
(
:vulnerabilities_finding
,
2
,
scanner:
create
(
:vulnerabilities_scanner
))
expect
{
Vulnerabilities
::
Finding
.
all
.
map
(
&
:scanner
)
}.
to
exceed_query_limit
(
control
)
end
it
'preloads scanner data'
do
create
(
:vulnerabilities_finding
,
scanner:
create
(
:vulnerabilities_scanner
))
control
=
ActiveRecord
::
QueryRecorder
.
new
{
preloaded_findings
.
map
(
&
:scanner
)
}.
count
create_list
(
:vulnerabilities_finding
,
2
,
scanner:
create
(
:vulnerabilities_scanner
))
expect
{
preloaded_findings
.
map
(
&
:scanner
)
}.
not_to
exceed_query_limit
(
control
)
end
it
'preloads identifier data'
do
create
(
:vulnerabilities_finding
,
identifiers:
[
create
(
:vulnerabilities_identifier
)])
control
=
ActiveRecord
::
QueryRecorder
.
new
{
preloaded_findings
.
map
(
&
:identifiers
)
}.
count
create_list
(
:vulnerabilities_finding
,
2
,
identifiers:
[
create
(
:vulnerabilities_identifier
)])
expect
{
preloaded_findings
.
map
(
&
:identifiers
)
}.
not_to
exceed_query_limit
(
control
)
end
it
'preloads project data'
do
create
(
:vulnerabilities_finding
,
project:
create
(
:project
))
control
=
ActiveRecord
::
QueryRecorder
.
new
{
preloaded_findings
.
map
(
&
:project
)
}.
count
create_list
(
:vulnerabilities_finding
,
2
,
project:
create
(
:project
))
expect
{
preloaded_findings
.
map
(
&
:project
)
}.
not_to
exceed_query_limit
(
control
)
end
it
'calls .preload_feedback!'
do
create_list
(
:vulnerabilities_finding
,
2
,
project:
create
(
:project
))
expect
(
Gitlab
::
Vulnerabilities
::
FindingsPreloader
).
to
receive
(
:preload_feedback!
)
preloaded_findings
end
end
describe
'.preload_feedback!'
do
let
(
:project
)
{
create
(
:project
)
}
def
preloaded_feedback
findings
=
Vulnerabilities
::
Finding
.
all
Gitlab
::
Vulnerabilities
::
FindingsPreloader
.
preload_feedback!
(
findings
)
findings
end
it
'preloads project data'
do
feedback_type
=
'dismissal'
create
(
:vulnerabilities_finding
,
project:
project
)
create
(
:vulnerability_feedback
,
project:
project
,
feedback_type:
feedback_type
)
control
=
ActiveRecord
::
QueryRecorder
.
new
do
preloaded_feedback
.
map
{
|
f
|
f
.
feedback
(
feedback_type:
feedback_type
)
}
end
.
count
create_list
(
:vulnerabilities_finding
,
2
,
project:
project
)
create_list
(
:vulnerability_feedback
,
2
,
project:
project
,
feedback_type:
feedback_type
)
expect
do
preloaded_feedback
.
map
{
|
f
|
f
.
feedback
(
feedback_type:
feedback_type
)
}
end
.
not_to
exceed_query_limit
(
control
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment