From d47f9d2304dbc3a23bba7fe7a5cd07218eeb41cd Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 16 Jan 2020 15:08:41 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../self_monitoring/project/delete_service_spec.rb | 34 +++---- spec/lib/gitlab/file_hook_spec.rb | 107 +++++++++++++++++++++ spec/lib/gitlab/plugin_spec.rb | 107 --------------------- 3 files changed, 121 insertions(+), 127 deletions(-) create mode 100644 spec/lib/gitlab/file_hook_spec.rb delete mode 100644 spec/lib/gitlab/plugin_spec.rb (limited to 'spec/lib') diff --git a/spec/lib/gitlab/database_importers/self_monitoring/project/delete_service_spec.rb b/spec/lib/gitlab/database_importers/self_monitoring/project/delete_service_spec.rb index b0cec61ce06..6446ab1beb4 100644 --- a/spec/lib/gitlab/database_importers/self_monitoring/project/delete_service_spec.rb +++ b/spec/lib/gitlab/database_importers/self_monitoring/project/delete_service_spec.rb @@ -4,12 +4,8 @@ require 'spec_helper' describe Gitlab::DatabaseImporters::SelfMonitoring::Project::DeleteService do describe '#execute' do + let!(:application_setting) { create(:application_setting) } let(:result) { subject.execute } - let(:application_setting) { Gitlab::CurrentSettings.current_application_settings } - - before do - allow(ApplicationSetting).to receive(:current_without_cache) { application_setting } - end context 'when project does not exist' do it 'returns error' do @@ -21,24 +17,16 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::DeleteService do end end - context 'with project destroyed but ID still present in application settings' do - before do - application_setting.instance_administration_project_id = 1 - end - - it 'deletes project ID from application settings' do - subject.execute - - expect(application_setting.instance_administration_project_id).to be_nil - end - end - context 'when self monitoring project exists' do let(:group) { create(:group) } let(:project) { create(:project, namespace: group) } - before do - application_setting.instance_administration_project = project + let(:application_setting) do + create( + :application_setting, + instance_administration_project_id: project.id, + instance_administrators_group_id: group.id + ) end it 'destroys project' do @@ -50,7 +38,13 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::DeleteService do it 'deletes project ID from application settings' do subject.execute - expect(application_setting.instance_administration_project_id).to be_nil + expect(application_setting.reload.instance_administration_project_id).to be_nil + end + + it 'does not delete group' do + subject.execute + + expect(application_setting.instance_administrators_group).to eq(group) end end end diff --git a/spec/lib/gitlab/file_hook_spec.rb b/spec/lib/gitlab/file_hook_spec.rb new file mode 100644 index 00000000000..d184eb483d4 --- /dev/null +++ b/spec/lib/gitlab/file_hook_spec.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::FileHook do + let(:file_hook) { Rails.root.join('plugins', 'test.rb') } + let(:tmp_file) { Tempfile.new('file_hook-dump') } + + let(:file_hook_source) do + <<~EOS + #!/usr/bin/env ruby + x = STDIN.read + File.write('#{tmp_file.path}', x) + EOS + end + + context 'with file_hooks present' do + before do + File.write(file_hook, file_hook_source) + end + + after do + FileUtils.rm(file_hook) + end + + describe '.any?' do + it 'returns true' do + expect(described_class.any?).to be true + end + end + + describe '.files?' do + it 'returns a list of file_hooks' do + expect(described_class.files).to match_array([file_hook.to_s]) + end + end + end + + context 'without any file_hooks' do + describe '.any?' do + it 'returns false' do + expect(described_class.any?).to be false + end + end + + describe '.files' do + it 'returns an empty list' do + expect(described_class.files).to be_empty + end + end + end + + describe '.execute' do + let(:data) { Gitlab::DataBuilder::Push::SAMPLE_DATA } + let(:result) { described_class.execute(file_hook.to_s, data) } + let(:success) { result.first } + let(:message) { result.last } + + before do + File.write(file_hook, file_hook_source) + end + + after do + FileUtils.rm(file_hook) + end + + context 'successful execution' do + before do + File.chmod(0o777, file_hook) + end + + after do + tmp_file.close! + end + + it { expect(success).to be true } + it { expect(message).to be_empty } + + it 'ensures file_hook received data via stdin' do + result + + expect(File.read(tmp_file.path)).to eq(data.to_json) + end + end + + context 'non-executable' do + it { expect(success).to be false } + it { expect(message).to include('Permission denied') } + end + + context 'non-zero exit' do + let(:file_hook_source) do + <<~EOS + #!/usr/bin/env ruby + exit 1 + EOS + end + + before do + File.chmod(0o777, file_hook) + end + + it { expect(success).to be false } + it { expect(message).to be_empty } + end + end +end diff --git a/spec/lib/gitlab/plugin_spec.rb b/spec/lib/gitlab/plugin_spec.rb deleted file mode 100644 index 5d9f6d04caa..00000000000 --- a/spec/lib/gitlab/plugin_spec.rb +++ /dev/null @@ -1,107 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::Plugin do - let(:plugin) { Rails.root.join('plugins', 'test.rb') } - let(:tmp_file) { Tempfile.new('plugin-dump') } - - let(:plugin_source) do - <<~EOS - #!/usr/bin/env ruby - x = STDIN.read - File.write('#{tmp_file.path}', x) - EOS - end - - context 'with plugins present' do - before do - File.write(plugin, plugin_source) - end - - after do - FileUtils.rm(plugin) - end - - describe '.any?' do - it 'returns true' do - expect(described_class.any?).to be true - end - end - - describe '.files?' do - it 'returns a list of plugins' do - expect(described_class.files).to match_array([plugin.to_s]) - end - end - end - - context 'without any plugins' do - describe '.any?' do - it 'returns false' do - expect(described_class.any?).to be false - end - end - - describe '.files' do - it 'returns an empty list' do - expect(described_class.files).to be_empty - end - end - end - - describe '.execute' do - let(:data) { Gitlab::DataBuilder::Push::SAMPLE_DATA } - let(:result) { described_class.execute(plugin.to_s, data) } - let(:success) { result.first } - let(:message) { result.last } - - before do - File.write(plugin, plugin_source) - end - - after do - FileUtils.rm(plugin) - end - - context 'successful execution' do - before do - File.chmod(0o777, plugin) - end - - after do - tmp_file.close! - end - - it { expect(success).to be true } - it { expect(message).to be_empty } - - it 'ensures plugin received data via stdin' do - result - - expect(File.read(tmp_file.path)).to eq(data.to_json) - end - end - - context 'non-executable' do - it { expect(success).to be false } - it { expect(message).to include('Permission denied') } - end - - context 'non-zero exit' do - let(:plugin_source) do - <<~EOS - #!/usr/bin/env ruby - exit 1 - EOS - end - - before do - File.chmod(0o777, plugin) - end - - it { expect(success).to be false } - it { expect(message).to be_empty } - end - end -end -- cgit v1.2.3