Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-13 18:08:52 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-13 18:08:52 +0300
commit0ab47b994caa80c5587f33dc818626b66cfdafe2 (patch)
tree5ef3976d2f84e3368903a67ba2dbd87a74b9a43c /spec/services
parent1308dc5eb484ab0f8064989fc551ebdb4b1a7976 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/container_expiration_policy_service_spec.rb2
-rw-r--r--spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb69
-rw-r--r--spec/services/projects/container_repository/cleanup_tags_service_spec.rb32
-rw-r--r--spec/services/users/block_service_spec.rb38
4 files changed, 140 insertions, 1 deletions
diff --git a/spec/services/container_expiration_policy_service_spec.rb b/spec/services/container_expiration_policy_service_spec.rb
index 1e4899c627f..b2f2b2e1236 100644
--- a/spec/services/container_expiration_policy_service_spec.rb
+++ b/spec/services/container_expiration_policy_service_spec.rb
@@ -17,7 +17,7 @@ describe ContainerExpirationPolicyService do
it 'kicks off a cleanup worker for the container repository' do
expect(CleanupContainerRepositoryWorker).to receive(:perform_async)
- .with(user.id, container_repository.id, anything)
+ .with(nil, container_repository.id, hash_including(container_expiration_policy: true))
subject
end
diff --git a/spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb b/spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb
new file mode 100644
index 00000000000..9ee5b06b410
--- /dev/null
+++ b/spec/services/metrics/dashboard/self_monitoring_dashboard_service_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Metrics::Dashboard::SelfMonitoringDashboardService, :use_clean_rails_memory_store_caching do
+ include MetricsDashboardHelpers
+
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
+ let_it_be(:environment) { create(:environment, project: project) }
+
+ before do
+ project.add_maintainer(user)
+ stub_application_setting(self_monitoring_project_id: project.id)
+ end
+
+ describe '#get_dashboard' do
+ let(:service_params) { [project, user, { environment: environment }] }
+ let(:service_call) { described_class.new(*service_params).get_dashboard }
+
+ it_behaves_like 'valid dashboard service response'
+ it_behaves_like 'raises error for users with insufficient permissions'
+ it_behaves_like 'caches the unprocessed dashboard for subsequent calls'
+ end
+
+ describe '.all_dashboard_paths' do
+ it 'returns the dashboard attributes' do
+ all_dashboards = described_class.all_dashboard_paths(project)
+
+ expect(all_dashboards).to eq(
+ [{
+ path: described_class::DASHBOARD_PATH,
+ display_name: described_class::DASHBOARD_NAME,
+ default: true,
+ system_dashboard: false
+ }]
+ )
+ end
+ end
+
+ describe '.valid_params?' do
+ subject { described_class.valid_params?(params) }
+
+ context 'with environment' do
+ let(:params) { { environment: environment } }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'with dashboard_path' do
+ let(:params) { { dashboard_path: self_monitoring_dashboard_path } }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'with a different dashboard selected' do
+ let(:dashboard_path) { '.gitlab/dashboards/test.yml' }
+ let(:params) { { dashboard_path: dashboard_path, environment: environment } }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'missing environment and dashboard_path' do
+ let(:params) { {} }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+end
diff --git a/spec/services/projects/container_repository/cleanup_tags_service_spec.rb b/spec/services/projects/container_repository/cleanup_tags_service_spec.rb
index cd4d1e3fe67..ef7e9cda9e0 100644
--- a/spec/services/projects/container_repository/cleanup_tags_service_spec.rb
+++ b/spec/services/projects/container_repository/cleanup_tags_service_spec.rb
@@ -130,6 +130,38 @@ describe Projects::ContainerRepository::CleanupTagsService do
is_expected.to include(status: :success, deleted: %w(Bb Ba C))
end
end
+
+ context 'when running a container_expiration_policy' do
+ let(:user) { nil }
+
+ context 'with valid container_expiration_policy param' do
+ let(:params) do
+ { 'name_regex' => '.*',
+ 'keep_n' => 1,
+ 'older_than' => '1 day',
+ 'container_expiration_policy' => true }
+ end
+
+ it 'succeeds without a user' do
+ expect_delete('sha256:configB').twice
+ expect_delete('sha256:configC')
+
+ is_expected.to include(status: :success, deleted: %w(Bb Ba C))
+ end
+ end
+
+ context 'without container_expiration_policy param' do
+ let(:params) do
+ { 'name_regex' => '.*',
+ 'keep_n' => 1,
+ 'older_than' => '1 day' }
+ end
+
+ it 'fails' do
+ is_expected.to include(status: :error, message: 'access denied')
+ end
+ end
+ end
end
private
diff --git a/spec/services/users/block_service_spec.rb b/spec/services/users/block_service_spec.rb
new file mode 100644
index 00000000000..c3a65a08c0d
--- /dev/null
+++ b/spec/services/users/block_service_spec.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Users::BlockService do
+ let(:current_user) { create(:admin) }
+
+ subject(:service) { described_class.new(current_user) }
+
+ describe '#execute' do
+ subject(:operation) { service.execute(user) }
+
+ context 'when successful' do
+ let(:user) { create(:user) }
+
+ it { is_expected.to eq(status: :success) }
+
+ it "change the user's state" do
+ expect { operation }.to change { user.state }.to('blocked')
+ end
+ end
+
+ context 'when failed' do
+ let(:user) { create(:user, :blocked) }
+
+ it 'returns error result' do
+ aggregate_failures 'error result' do
+ expect(operation[:status]).to eq(:error)
+ expect(operation[:message]).to match(/State cannot transition/)
+ end
+ end
+
+ it "does not change the user's state" do
+ expect { operation }.not_to change { user.state }
+ end
+ end
+ end
+end