2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-02-04 15:31:55 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'socket'
|
|
|
|
require 'json'
|
|
|
|
|
2021-05-24 08:10:31 -04:00
|
|
|
RSpec.describe Integrations::Irker do
|
2015-02-04 15:31:55 -05:00
|
|
|
describe 'Validations' do
|
2021-06-30 05:08:07 -04:00
|
|
|
context 'when integration is active' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
subject.active = true
|
|
|
|
end
|
2016-04-21 11:13:14 -04:00
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:recipients) }
|
2015-02-04 15:31:55 -05:00
|
|
|
end
|
|
|
|
|
2021-06-30 05:08:07 -04:00
|
|
|
context 'when integration is inactive' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
subject.active = false
|
|
|
|
end
|
2016-04-21 11:13:14 -04:00
|
|
|
|
|
|
|
it { is_expected.not_to validate_presence_of(:recipients) }
|
2015-02-04 15:31:55 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Execute' do
|
2017-07-25 13:09:00 -04:00
|
|
|
let(:irker) { described_class.new }
|
2015-02-04 15:31:55 -05:00
|
|
|
let(:user) { create(:user) }
|
2017-01-26 17:44:58 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-08-04 11:44:27 -04:00
|
|
|
let(:sample_data) do
|
2016-08-12 04:09:29 -04:00
|
|
|
Gitlab::DataBuilder::Push.build_sample(project, user)
|
2016-08-04 11:44:27 -04:00
|
|
|
end
|
2015-02-04 15:31:55 -05:00
|
|
|
|
2015-07-03 02:17:10 -04:00
|
|
|
let(:recipients) { '#commits irc://test.net/#test ftp://bad' }
|
2015-02-04 15:31:55 -05:00
|
|
|
let(:colorize_messages) { '1' }
|
|
|
|
|
|
|
|
before do
|
2016-08-15 17:26:40 -04:00
|
|
|
@irker_server = TCPServer.new 'localhost', 0
|
|
|
|
|
2015-05-21 17:49:06 -04:00
|
|
|
allow(irker).to receive_messages(
|
2016-08-15 17:33:36 -04:00
|
|
|
active: true,
|
|
|
|
project: project,
|
|
|
|
project_id: project.id,
|
|
|
|
server_host: @irker_server.addr[2],
|
|
|
|
server_port: @irker_server.addr[1],
|
|
|
|
default_irc_uri: 'irc://chat.freenode.net/',
|
|
|
|
recipients: recipients,
|
|
|
|
colorize_messages: colorize_messages)
|
2015-07-03 02:17:10 -04:00
|
|
|
|
2015-02-04 15:31:55 -05:00
|
|
|
irker.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
@irker_server.close
|
|
|
|
end
|
|
|
|
|
2019-10-23 05:06:03 -04:00
|
|
|
it 'sends valid JSON messages to an Irker listener', :sidekiq_might_not_need_inline do
|
2015-02-04 15:31:55 -05:00
|
|
|
irker.execute(sample_data)
|
|
|
|
|
|
|
|
conn = @irker_server.accept
|
2020-03-27 14:07:48 -04:00
|
|
|
conn.each_line do |line|
|
2020-04-30 14:09:38 -04:00
|
|
|
msg = Gitlab::Json.parse(line.chomp("\n"))
|
2017-02-22 12:46:57 -05:00
|
|
|
expect(msg.keys).to match_array(%w(to privmsg))
|
2015-07-03 02:17:10 -04:00
|
|
|
expect(msg['to']).to match_array(["irc://chat.freenode.net/#commits",
|
|
|
|
"irc://test.net/#test"])
|
2015-02-04 15:31:55 -05:00
|
|
|
end
|
|
|
|
conn.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|