Commit 3465fda1 authored by Fabio Pitino's avatar Fabio Pitino Committed by Sean Arnold

Create shared examples and helpers to test EventStore

Have a consistent way of testing publishing and consumption
of events.
parent 8c178ce5
......@@ -5,6 +5,7 @@ module Ci
def schema
{
'type' => 'object',
'required' => ['pipeline_id'],
'properties' => {
'pipeline_id' => { 'type' => 'integer' }
}
......
......@@ -293,8 +293,7 @@ in the `handle_event` method of the subscriber worker.
## Testing
A publisher doesn't must care what subscribed to the event being published. The publisher's
responsibility is to ensure that the event is published correctly.
The publisher's responsibility is to ensure that the event is published correctly.
To test that an event has been published correctly, we can use the RSpec matcher `:publish_event`:
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::PipelineCreatedEvent do
using RSpec::Parameterized::TableSyntax
where(:data, :valid) do
{ pipeline_id: 1 } | true
{ pipeline_id: nil } | false
{ pipeline_id: "test" } | false
{} | false
{ job_id: 1 } | false
end
with_them do
let(:event) { described_class.new(data: data) }
it 'validates the data according to the schema' do
if valid
expect { event }.not_to raise_error
else
expect { event }.to raise_error(Gitlab::EventStore::InvalidEvent)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment