2021-09-04 01:27:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
RSpec.describe API::Ci::Helpers::Runner do
|
|
|
|
let(:helper) { Class.new { include API::Ci::Helpers::Runner }.new }
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:env).and_return({})
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#current_job' do
|
|
|
|
let(:build) { create(:ci_build, :running) }
|
|
|
|
|
|
|
|
it 'handles sticking of a build when a build ID is specified' do
|
|
|
|
allow(helper).to receive(:params).and_return(id: build.id)
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(Ci::Build.sticking)
|
2021-11-18 22:05:49 +05:30
|
|
|
.to receive(:stick_or_unstick_request)
|
2021-09-04 01:27:46 +05:30
|
|
|
.with({}, :build, build.id)
|
|
|
|
|
|
|
|
helper.current_job
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not handle sticking if no build ID was specified' do
|
|
|
|
allow(helper).to receive(:params).and_return({})
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(Ci::Build.sticking)
|
2021-11-18 22:05:49 +05:30
|
|
|
.not_to receive(:stick_or_unstick_request)
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
helper.current_job
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the build if one could be found' do
|
|
|
|
allow(helper).to receive(:params).and_return(id: build.id)
|
|
|
|
|
|
|
|
expect(helper.current_job).to eq(build)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#current_runner' do
|
|
|
|
let(:runner) { create(:ci_runner, token: 'foo') }
|
|
|
|
|
|
|
|
it 'handles sticking of a runner if a token is specified' do
|
|
|
|
allow(helper).to receive(:params).and_return(token: runner.token)
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(Ci::Runner.sticking)
|
2021-11-18 22:05:49 +05:30
|
|
|
.to receive(:stick_or_unstick_request)
|
2021-09-04 01:27:46 +05:30
|
|
|
.with({}, :runner, runner.token)
|
|
|
|
|
|
|
|
helper.current_runner
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not handle sticking if no token was specified' do
|
|
|
|
allow(helper).to receive(:params).and_return({})
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(Ci::Runner.sticking)
|
2021-11-18 22:05:49 +05:30
|
|
|
.not_to receive(:stick_or_unstick_request)
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
helper.current_runner
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the runner if one could be found' do
|
|
|
|
allow(helper).to receive(:params).and_return(token: runner.token)
|
|
|
|
|
|
|
|
expect(helper.current_runner).to eq(runner)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|