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
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/graphql/mutations/clusters/agent_tokens/revoke_spec.rb55
-rw-r--r--spec/lib/gitlab/import/set_async_jid_spec.rb2
-rw-r--r--spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb61
-rw-r--r--spec/lib/gitlab/sidekiq_status_spec.rb40
-rw-r--r--spec/requests/api/merge_requests_spec.rb5
-rw-r--r--spec/services/deployments/archive_in_project_service_spec.rb11
6 files changed, 113 insertions, 61 deletions
diff --git a/spec/graphql/mutations/clusters/agent_tokens/revoke_spec.rb b/spec/graphql/mutations/clusters/agent_tokens/revoke_spec.rb
new file mode 100644
index 00000000000..f5f4c0cefad
--- /dev/null
+++ b/spec/graphql/mutations/clusters/agent_tokens/revoke_spec.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::Clusters::AgentTokens::Revoke do
+ let_it_be(:token) { create(:cluster_agent_token) }
+ let_it_be(:user) { create(:user) }
+
+ let(:mutation) do
+ described_class.new(
+ object: double,
+ context: { current_user: user },
+ field: double
+ )
+ end
+
+ it { expect(described_class.graphql_name).to eq('ClusterAgentTokenRevoke') }
+ it { expect(described_class).to require_graphql_authorizations(:admin_cluster) }
+
+ describe '#resolve' do
+ let(:global_id) { token.to_global_id }
+
+ subject { mutation.resolve(id: global_id) }
+
+ context 'user does not have permission' do
+ it 'does not revoke the token' do
+ expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
+
+ expect(token.reload).not_to be_revoked
+ end
+ end
+
+ context 'user has permission' do
+ before do
+ token.agent.project.add_maintainer(user)
+ end
+
+ it 'revokes the token' do
+ subject
+
+ expect(token.reload).to be_revoked
+ end
+
+ context 'supplied ID is invalid' do
+ let(:global_id) { token.id }
+
+ it 'raises a coercion error' do
+ expect { subject }.to raise_error(::GraphQL::CoercionError)
+
+ expect(token.reload).not_to be_revoked
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/import/set_async_jid_spec.rb b/spec/lib/gitlab/import/set_async_jid_spec.rb
index 016f7cac61a..6931a7a953d 100644
--- a/spec/lib/gitlab/import/set_async_jid_spec.rb
+++ b/spec/lib/gitlab/import/set_async_jid_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Gitlab::Import::SetAsyncJid do
it 'sets the JID in Redis' do
expect(Gitlab::SidekiqStatus)
.to receive(:set)
- .with("async-import/project-import-state/#{project.id}", Gitlab::Import::StuckImportJob::IMPORT_JOBS_EXPIRATION, value: 2)
+ .with("async-import/project-import-state/#{project.id}", Gitlab::Import::StuckImportJob::IMPORT_JOBS_EXPIRATION)
.and_call_original
described_class.set_jid(project.import_state)
diff --git a/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb b/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb
index 2f2499753b9..cb1616ec40a 100644
--- a/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb
+++ b/spec/lib/gitlab/sidekiq_status/client_middleware_spec.rb
@@ -1,24 +1,61 @@
# frozen_string_literal: true
-require 'fast_spec_helper'
+# This can use fast_spec_helper when the feature flag stubbing is removed.
+require 'spec_helper'
-RSpec.describe Gitlab::SidekiqStatus::ClientMiddleware do
+RSpec.describe Gitlab::SidekiqStatus::ClientMiddleware, :clean_gitlab_redis_queues do
describe '#call' do
- context 'when the job has status_expiration set' do
- it 'tracks the job in Redis with a value of 2' do
- expect(Gitlab::SidekiqStatus).to receive(:set).with('123', 1.hour.to_i, value: 2)
+ context 'when opt_in_sidekiq_status is disabled' do
+ before do
+ stub_feature_flags(opt_in_sidekiq_status: false)
+ end
+
+ context 'when the job has status_expiration set' do
+ it 'tracks the job in Redis' do
+ expect(Gitlab::SidekiqStatus).to receive(:set).with('123', 1.hour.to_i).and_call_original
+
+ described_class.new
+ .call('Foo', { 'jid' => '123', 'status_expiration' => 1.hour.to_i }, double(:queue), double(:pool)) { nil }
+
+ expect(Gitlab::SidekiqStatus.num_running(['123'])).to eq(1)
+ end
+ end
+
+ context 'when the job does not have status_expiration set' do
+ it 'tracks the job in Redis' do
+ expect(Gitlab::SidekiqStatus).to receive(:set).with('123', 30.minutes.to_i).and_call_original
+
+ described_class.new
+ .call('Foo', { 'jid' => '123' }, double(:queue), double(:pool)) { nil }
- described_class.new
- .call('Foo', { 'jid' => '123', 'status_expiration' => 1.hour.to_i }, double(:queue), double(:pool)) { nil }
+ expect(Gitlab::SidekiqStatus.num_running(['123'])).to eq(1)
+ end
end
end
- context 'when the job does not have status_expiration set' do
- it 'tracks the job in Redis with a value of 1' do
- expect(Gitlab::SidekiqStatus).to receive(:set).with('123', Gitlab::SidekiqStatus::DEFAULT_EXPIRATION, value: 1)
+ context 'when opt_in_sidekiq_status is enabled' do
+ before do
+ stub_feature_flags(opt_in_sidekiq_status: true)
+ end
+
+ context 'when the job has status_expiration set' do
+ it 'tracks the job in Redis' do
+ expect(Gitlab::SidekiqStatus).to receive(:set).with('123', 1.hour.to_i).and_call_original
+
+ described_class.new
+ .call('Foo', { 'jid' => '123', 'status_expiration' => 1.hour.to_i }, double(:queue), double(:pool)) { nil }
+
+ expect(Gitlab::SidekiqStatus.num_running(['123'])).to eq(1)
+ end
+ end
+
+ context 'when the job does not have status_expiration set' do
+ it 'does not track the job in Redis' do
+ described_class.new
+ .call('Foo', { 'jid' => '123' }, double(:queue), double(:pool)) { nil }
- described_class.new
- .call('Foo', { 'jid' => '123' }, double(:queue), double(:pool)) { nil }
+ expect(Gitlab::SidekiqStatus.num_running(['123'])).to be_zero
+ end
end
end
end
diff --git a/spec/lib/gitlab/sidekiq_status_spec.rb b/spec/lib/gitlab/sidekiq_status_spec.rb
index 1e7b52471b0..c94deb8e008 100644
--- a/spec/lib/gitlab/sidekiq_status_spec.rb
+++ b/spec/lib/gitlab/sidekiq_status_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe Gitlab::SidekiqStatus, :clean_gitlab_redis_queues, :clean_gitlab_
Sidekiq.redis do |redis|
expect(redis.exists(key)).to eq(true)
expect(redis.ttl(key) > 0).to eq(true)
- expect(redis.get(key)).to eq(described_class::DEFAULT_VALUE.to_s)
+ expect(redis.get(key)).to eq('1')
end
end
@@ -24,19 +24,17 @@ RSpec.describe Gitlab::SidekiqStatus, :clean_gitlab_redis_queues, :clean_gitlab_
Sidekiq.redis do |redis|
expect(redis.exists(key)).to eq(true)
expect(redis.ttl(key) > described_class::DEFAULT_EXPIRATION).to eq(true)
- expect(redis.get(key)).to eq(described_class::DEFAULT_VALUE.to_s)
+ expect(redis.get(key)).to eq('1')
end
end
- it 'allows overriding the default value' do
- described_class.set('123', value: 2)
+ it 'does not store anything with a nil expiry' do
+ described_class.set('123', nil)
key = described_class.key_for('123')
Sidekiq.redis do |redis|
- expect(redis.exists(key)).to eq(true)
- expect(redis.ttl(key) > 0).to eq(true)
- expect(redis.get(key)).to eq('2')
+ expect(redis.exists(key)).to eq(false)
end
end
end
@@ -138,33 +136,5 @@ RSpec.describe Gitlab::SidekiqStatus, :clean_gitlab_redis_queues, :clean_gitlab_
it 'handles an empty array' do
expect(described_class.job_status([])).to eq([])
end
-
- context 'when log_implicit_sidekiq_status_calls is enabled' do
- it 'logs keys that contained the default value' do
- described_class.set('123', value: 2)
- described_class.set('456')
- described_class.set('012')
-
- expect(Sidekiq.logger).to receive(:info).with(message: described_class::DEFAULT_VALUE_MESSAGE,
- keys: [described_class.key_for('456'), described_class.key_for('012')])
-
- expect(described_class.job_status(%w(123 456 789 012))).to eq([true, true, false, true])
- end
- end
-
- context 'when log_implicit_sidekiq_status_calls is disabled' do
- before do
- stub_feature_flags(log_implicit_sidekiq_status_calls: false)
- end
-
- it 'does not perform any logging' do
- described_class.set('123', value: 2)
- described_class.set('456')
-
- expect(Sidekiq.logger).not_to receive(:info)
-
- expect(described_class.job_status(%w(123 456 789))).to eq([true, true, false])
- end
- end
end
end
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 7c147419354..d5f0fdeacd7 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -3278,9 +3278,10 @@ RSpec.describe API::MergeRequests do
context 'when skip_ci parameter is set' do
it 'enqueues a rebase of the merge request with skip_ci flag set' do
- allow(RebaseWorker).to receive(:with_status).and_return(RebaseWorker)
+ with_status = RebaseWorker.with_status
- expect(RebaseWorker).to receive(:perform_async).with(merge_request.id, user.id, true).and_call_original
+ expect(RebaseWorker).to receive(:with_status).and_return(with_status)
+ expect(with_status).to receive(:perform_async).with(merge_request.id, user.id, true).and_call_original
Sidekiq::Testing.fake! do
expect do
diff --git a/spec/services/deployments/archive_in_project_service_spec.rb b/spec/services/deployments/archive_in_project_service_spec.rb
index d4039ee7b4a..a316c210d64 100644
--- a/spec/services/deployments/archive_in_project_service_spec.rb
+++ b/spec/services/deployments/archive_in_project_service_spec.rb
@@ -50,17 +50,6 @@ RSpec.describe Deployments::ArchiveInProjectService do
end
end
- context 'when deployments_archive feature flag is disabled' do
- before do
- stub_feature_flags(deployments_archive: false)
- end
-
- it 'does not do anything' do
- expect(subject[:status]).to eq(:error)
- expect(subject[:message]).to eq('Feature flag is not enabled')
- end
- end
-
def deployment_refs_exist?
deployment_refs.map { |path| project.repository.ref_exists?(path) }
end