debian-mirror-gitlab/spec/services/ci/runners/unassign_runner_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.4 KiB
Ruby
Raw Normal View History

2022-05-07 20:08:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ci::Runners::UnassignRunnerService, '#execute' do
let_it_be(:project) { create(:project) }
2022-08-27 11:52:29 +05:30
let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) }
2022-05-07 20:08:51 +05:30
let(:runner_project) { runner.runner_projects.last }
2022-08-27 11:52:29 +05:30
subject(:execute) { described_class.new(runner_project, user).execute }
2022-05-07 20:08:51 +05:30
context 'without user' do
let(:user) { nil }
it 'does not destroy runner_project', :aggregate_failures do
expect(runner_project).not_to receive(:destroy)
2022-08-27 11:52:29 +05:30
expect { execute }.not_to change { runner.runner_projects.count }.from(1)
2022-05-07 20:08:51 +05:30
2022-08-27 11:52:29 +05:30
is_expected.to be_error
2022-05-07 20:08:51 +05:30
end
end
context 'with unauthorized user' do
let(:user) { build(:user) }
it 'does not call destroy on runner_project' do
expect(runner).not_to receive(:destroy)
2022-08-27 11:52:29 +05:30
is_expected.to be_error
2022-05-07 20:08:51 +05:30
end
end
context 'with admin user', :enable_admin_mode do
let(:user) { create_default(:user, :admin) }
2022-08-27 11:52:29 +05:30
context 'with destroy returning false' do
it 'returns error response' do
expect(runner_project).to receive(:destroy).once.and_return(false)
is_expected.to be_error
end
end
context 'with destroy returning true' do
it 'returns success response' do
expect(runner_project).to receive(:destroy).once.and_return(true)
2022-05-07 20:08:51 +05:30
2022-08-27 11:52:29 +05:30
is_expected.to be_success
end
2022-05-07 20:08:51 +05:30
end
end
end