2018-02-26 10:33:19 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Plugin do
|
|
|
|
describe '.execute' do
|
|
|
|
let(:data) { Gitlab::DataBuilder::Push::SAMPLE_DATA }
|
|
|
|
let(:plugin) { Rails.root.join('plugins', 'test.rb') }
|
2018-02-27 07:33:32 -05:00
|
|
|
let(:tmp_file) { Tempfile.new('plugin-dump') }
|
2018-02-28 05:16:23 -05:00
|
|
|
let(:result) { described_class.execute(plugin.to_s, data) }
|
|
|
|
let(:success) { result.first }
|
|
|
|
let(:message) { result.last }
|
2018-02-26 10:33:19 -05:00
|
|
|
|
2018-02-27 11:08:38 -05:00
|
|
|
let(:plugin_source) do
|
|
|
|
<<~EOS
|
|
|
|
#!/usr/bin/env ruby
|
|
|
|
x = STDIN.read
|
|
|
|
File.write('#{tmp_file.path}', x)
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
2018-02-26 10:33:19 -05:00
|
|
|
before do
|
|
|
|
File.write(plugin, plugin_source)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
FileUtils.rm(plugin)
|
|
|
|
end
|
|
|
|
|
2018-02-27 11:08:38 -05:00
|
|
|
context 'successful execution' do
|
|
|
|
before do
|
|
|
|
File.chmod(0o777, plugin)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
tmp_file.close!
|
|
|
|
end
|
2018-02-26 10:33:19 -05:00
|
|
|
|
2018-02-28 05:16:23 -05:00
|
|
|
it { expect(success).to be true }
|
|
|
|
it { expect(message).to be_empty }
|
2018-02-26 10:33:19 -05:00
|
|
|
|
2018-02-27 11:08:38 -05:00
|
|
|
it 'ensures plugin received data via stdin' do
|
2018-02-28 05:16:23 -05:00
|
|
|
result
|
2018-02-27 11:08:38 -05:00
|
|
|
|
|
|
|
expect(File.read(tmp_file.path)).to eq(data.to_json)
|
|
|
|
end
|
2018-02-26 10:33:19 -05:00
|
|
|
end
|
|
|
|
|
2018-02-27 11:08:38 -05:00
|
|
|
context 'non-executable' do
|
2018-02-28 05:16:23 -05:00
|
|
|
it { expect(success).to be false }
|
|
|
|
it { expect(message).to include('Permission denied') }
|
2018-02-27 11:08:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'non-zero exit' do
|
|
|
|
let(:plugin_source) do
|
|
|
|
<<~EOS
|
|
|
|
#!/usr/bin/env ruby
|
|
|
|
exit 1
|
|
|
|
EOS
|
|
|
|
end
|
2018-02-26 10:33:19 -05:00
|
|
|
|
2018-02-27 11:08:38 -05:00
|
|
|
before do
|
|
|
|
File.chmod(0o777, plugin)
|
|
|
|
end
|
|
|
|
|
2018-02-28 05:16:23 -05:00
|
|
|
it { expect(success).to be false }
|
|
|
|
it { expect(message).to be_empty }
|
2018-02-27 11:08:38 -05:00
|
|
|
end
|
2018-02-26 10:33:19 -05:00
|
|
|
end
|
|
|
|
end
|