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
b2695395
Commit
b2695395
authored
Nov 30, 2021
by
Albert Salim
Committed by
Aleksei Lipniagov
Nov 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test coverage and refactor existing tests on job artifacts
parent
cb74e49b
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
679 additions
and
624 deletions
+679
-624
spec/requests/api/ci/job_artifacts_spec.rb
spec/requests/api/ci/job_artifacts_spec.rb
+629
-0
spec/requests/api/ci/jobs_spec.rb
spec/requests/api/ci/jobs_spec.rb
+0
-589
spec/services/ci/job_artifacts/destroy_batch_service_spec.rb
spec/services/ci/job_artifacts/destroy_batch_service_spec.rb
+50
-35
No files found.
spec/requests/api/ci/job_artifacts_spec.rb
0 → 100644
View file @
b2695395
This diff is collapsed.
Click to expand it.
spec/requests/api/ci/jobs_spec.rb
View file @
b2695395
This diff is collapsed.
Click to expand it.
spec/services/ci/job_artifacts/destroy_batch_service_spec.rb
View file @
b2695395
...
@@ -3,33 +3,39 @@
...
@@ -3,33 +3,39 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
Ci
::
JobArtifacts
::
DestroyBatchService
do
RSpec
.
describe
Ci
::
JobArtifacts
::
DestroyBatchService
do
let
(
:artifacts
)
{
Ci
::
JobArtifact
.
all
}
let
(
:artifacts
)
{
Ci
::
JobArtifact
.
where
(
id:
[
artifact_with_file
.
id
,
artifact_without_file
.
id
])
}
let
(
:service
)
{
described_class
.
new
(
artifacts
,
pick_up_at:
Time
.
current
)
}
let
(
:service
)
{
described_class
.
new
(
artifacts
,
pick_up_at:
Time
.
current
)
}
describe
'.execute'
do
let_it_be
(
:artifact_with_file
,
refind:
true
)
do
subject
(
:execute
)
{
service
.
execute
}
create
(
:ci_job_artifact
,
:zip
)
end
let_it_be
(
:artifact
,
refind:
true
)
do
let_it_be
(
:artifact_without_file
,
refind:
true
)
do
create
(
:ci_job_artifact
)
create
(
:ci_job_artifact
)
end
end
context
'when the artifact has a file attached to it'
do
let_it_be
(
:undeleted_artifact
,
refind:
true
)
do
before
do
create
(
:ci_job_artifact
)
artifact
.
file
=
fixture_file_upload
(
Rails
.
root
.
join
(
'spec/fixtures/ci_build_artifacts.zip'
),
'application/zip'
)
artifact
.
save!
end
end
it
'creates a deleted object'
do
describe
'.execute'
do
subject
(
:execute
)
{
service
.
execute
}
it
'creates a deleted object for artifact with attached file'
do
expect
{
subject
}.
to
change
{
Ci
::
DeletedObject
.
count
}.
by
(
1
)
expect
{
subject
}.
to
change
{
Ci
::
DeletedObject
.
count
}.
by
(
1
)
end
end
it
'does not remove the files'
do
it
'does not remove the attached file'
do
expect
{
execute
}.
not_to
change
{
artifact
.
file
.
exists?
}
expect
{
execute
}.
not_to
change
{
artifact_with_file
.
file
.
exists?
}
end
it
'deletes the artifact records'
do
expect
{
subject
}.
to
change
{
Ci
::
JobArtifact
.
count
}.
by
(
-
2
)
end
end
it
'reports metrics for destroyed artifacts'
do
it
'reports metrics for destroyed artifacts'
do
expect_next_instance_of
(
Gitlab
::
Ci
::
Artifacts
::
Metrics
)
do
|
metrics
|
expect_next_instance_of
(
Gitlab
::
Ci
::
Artifacts
::
Metrics
)
do
|
metrics
|
expect
(
metrics
).
to
receive
(
:increment_destroyed_artifacts_count
).
with
(
1
).
and_call_original
expect
(
metrics
).
to
receive
(
:increment_destroyed_artifacts_count
).
with
(
2
).
and_call_original
expect
(
metrics
).
to
receive
(
:increment_destroyed_artifacts_bytes
).
with
(
107464
).
and_call_original
expect
(
metrics
).
to
receive
(
:increment_destroyed_artifacts_bytes
).
with
(
107464
).
and_call_original
end
end
...
@@ -39,7 +45,10 @@ RSpec.describe Ci::JobArtifacts::DestroyBatchService do
...
@@ -39,7 +45,10 @@ RSpec.describe Ci::JobArtifacts::DestroyBatchService do
context
'ProjectStatistics'
do
context
'ProjectStatistics'
do
it
'resets project statistics'
do
it
'resets project statistics'
do
expect
(
ProjectStatistics
).
to
receive
(
:increment_statistic
).
once
expect
(
ProjectStatistics
).
to
receive
(
:increment_statistic
).
once
.
with
(
artifact
.
project
,
:build_artifacts_size
,
-
artifact
.
file
.
size
)
.
with
(
artifact_with_file
.
project
,
:build_artifacts_size
,
-
artifact_with_file
.
file
.
size
)
.
and_call_original
expect
(
ProjectStatistics
).
to
receive
(
:increment_statistic
).
once
.
with
(
artifact_without_file
.
project
,
:build_artifacts_size
,
0
)
.
and_call_original
.
and_call_original
execute
execute
...
@@ -53,9 +62,15 @@ RSpec.describe Ci::JobArtifacts::DestroyBatchService do
...
@@ -53,9 +62,15 @@ RSpec.describe Ci::JobArtifacts::DestroyBatchService do
end
end
it
'returns size statistics'
do
it
'returns size statistics'
do
expected_updates
=
{
statistics_updates:
{
artifact_with_file
.
project
=>
-
artifact_with_file
.
file
.
size
,
artifact_without_file
.
project
=>
0
}
}
expect
(
service
.
execute
(
update_stats:
false
)).
to
match
(
expect
(
service
.
execute
(
update_stats:
false
)).
to
match
(
a_hash_including
(
statistics_updates:
{
artifact
.
project
=>
-
artifact
.
file
.
size
}))
a_hash_including
(
expected_updates
))
end
end
end
end
end
end
end
...
@@ -71,7 +86,7 @@ RSpec.describe Ci::JobArtifacts::DestroyBatchService do
...
@@ -71,7 +86,7 @@ RSpec.describe Ci::JobArtifacts::DestroyBatchService do
it
'raises an exception and stop destroying'
do
it
'raises an exception and stop destroying'
do
expect
{
execute
}.
to
raise_error
(
ActiveRecord
::
RecordNotDestroyed
)
expect
{
execute
}.
to
raise_error
(
ActiveRecord
::
RecordNotDestroyed
)
.
and
not_change
{
Ci
::
JobArtifact
.
count
}
.
from
(
1
)
.
and
not_change
{
Ci
::
JobArtifact
.
count
}
end
end
end
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