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
a7d17cad
Commit
a7d17cad
authored
Mar 09, 2022
by
Albert Salim
Committed by
Fabio Pitino
Mar 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve matcher for publishing event
parent
f83b68da
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
31 deletions
+43
-31
ee/spec/services/ee/ci/job_artifacts/destroy_all_expired_service_spec.rb
...s/ee/ci/job_artifacts/destroy_all_expired_service_spec.rb
+1
-10
ee/spec/services/ee/ci/job_artifacts/destroy_batch_service_spec.rb
...ervices/ee/ci/job_artifacts/destroy_batch_service_spec.rb
+1
-10
spec/services/projects/destroy_service_spec.rb
spec/services/projects/destroy_service_spec.rb
+2
-6
spec/support/event_store.rb
spec/support/event_store.rb
+7
-0
spec/support/matchers/event_store.rb
spec/support/matchers/event_store.rb
+32
-5
No files found.
ee/spec/services/ee/ci/job_artifacts/destroy_all_expired_service_spec.rb
View file @
a7d17cad
...
...
@@ -28,16 +28,7 @@ RSpec.describe Ci::JobArtifacts::DestroyAllExpiredService, :clean_gitlab_redis_s
end
it
'publishes Ci::JobArtifactsDeletedEvent'
do
event
=
double
(
:event
)
expect
(
Ci
::
JobArtifactsDeletedEvent
)
.
to
receive
(
:new
)
.
with
(
data:
event_data
)
.
and_return
(
event
)
expect
(
Gitlab
::
EventStore
).
to
receive
(
:publish
).
with
(
event
)
subject
expect
{
subject
}.
to
publish_event
(
Ci
::
JobArtifactsDeletedEvent
).
with
(
event_data
)
end
end
...
...
ee/spec/services/ee/ci/job_artifacts/destroy_batch_service_spec.rb
View file @
a7d17cad
...
...
@@ -21,16 +21,7 @@ RSpec.describe Ci::JobArtifacts::DestroyBatchService do
end
it
'publishes Ci::JobArtifactsDeletedEvent'
do
event
=
double
(
:event
)
expect
(
Ci
::
JobArtifactsDeletedEvent
)
.
to
receive
(
:new
)
.
with
(
data:
event_data
)
.
and_return
(
event
)
expect
(
Gitlab
::
EventStore
).
to
receive
(
:publish
).
with
(
event
)
subject
expect
{
subject
}.
to
publish_event
(
Ci
::
JobArtifactsDeletedEvent
).
with
(
event_data
)
end
context
'with Geo replication'
do
...
...
spec/services/projects/destroy_service_spec.rb
View file @
a7d17cad
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
Projects
::
DestroyService
,
:aggregate_failures
do
RSpec
.
describe
Projects
::
DestroyService
,
:aggregate_failures
,
:event_store_publisher
do
include
ProjectForksHelper
let_it_be
(
:user
)
{
create
(
:user
)
}
...
...
@@ -15,7 +15,6 @@ RSpec.describe Projects::DestroyService, :aggregate_failures do
before
do
stub_container_registry_config
(
enabled:
true
)
stub_container_registry_tags
(
repository: :any
,
tags:
[])
allow
(
Gitlab
::
EventStore
).
to
receive
(
:publish
)
end
shared_examples
'deleting the project'
do
...
...
@@ -30,11 +29,8 @@ RSpec.describe Projects::DestroyService, :aggregate_failures do
it
'publishes a ProjectDeleted event with project id and namespace id'
do
expected_data
=
{
project_id:
project
.
id
,
namespace_id:
project
.
namespace_id
}
expect
(
Gitlab
::
EventStore
)
.
to
receive
(
:publish
)
.
with
(
event_type
(
Projects
::
ProjectDeletedEvent
).
containing
(
expected_data
))
destroy_project
(
project
,
user
,
{}
)
expect
{
destroy_project
(
project
,
user
,
{})
}.
to
publish_event
(
Projects
::
ProjectDeletedEvent
).
with
(
expected_data
)
end
end
...
...
spec/support/event_store.rb
0 → 100644
View file @
a7d17cad
# frozen_string_literal: true
RSpec
.
configure
do
|
config
|
config
.
before
(
:each
,
:event_store_publisher
)
do
allow
(
Gitlab
::
EventStore
).
to
receive
(
:publish
)
end
end
spec/support/matchers/event_store.rb
View file @
a7d17cad
# frozen_string_literal: true
RSpec
::
Matchers
.
define
:event_type
do
|
event_class
|
match
do
|
actual
|
actual
.
instance_of?
(
event_class
)
&&
actual
.
data
==
@expected_data
RSpec
::
Matchers
.
define
:publish_event
do
|
expected_event_class
|
supports_block_expectations
match
do
|
proc
|
raise
ArgumentError
,
'This matcher only supports block expectation'
unless
proc
.
respond_to?
(
:call
)
@events
||=
[]
allow
(
Gitlab
::
EventStore
).
to
receive
(
:publish
)
do
|
published_event
|
@events
<<
published_event
end
proc
.
call
@events
.
any?
do
|
event
|
event
.
instance_of?
(
expected_event_class
)
&&
event
.
data
==
@expected_data
end
end
chain
:
containing
do
|
expected_data
|
chain
:
with
do
|
expected_data
|
@expected_data
=
expected_data
end
failure_message
do
"expected
#{
expected_event_class
}
with
#{
@expected_data
}
to be published, but got
#{
@events
}
"
end
match_when_negated
do
|
proc
|
raise
ArgumentError
,
'This matcher only supports block expectation'
unless
proc
.
respond_to?
(
:call
)
allow
(
Gitlab
::
EventStore
).
to
receive
(
:publish
)
proc
.
call
expect
(
Gitlab
::
EventStore
).
not_to
have_received
(
:publish
).
with
(
instance_of
(
expected_event_class
))
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