2021-05-26 17:10:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-07-20 17:09:52 -04:00
|
|
|
RSpec.describe API::Ci::Helpers::Runner do
|
2021-05-26 17:10:49 -04:00
|
|
|
let(:ip_address) { '1.2.3.4' }
|
|
|
|
let(:runner_class) do
|
|
|
|
Class.new do
|
|
|
|
include API::Helpers
|
2021-07-20 17:09:52 -04:00
|
|
|
include API::Ci::Helpers::Runner
|
2021-05-26 17:10:49 -04:00
|
|
|
|
|
|
|
attr_accessor :params
|
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
|
|
|
def ip_address
|
|
|
|
'1.2.3.4'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:runner_helper) { runner_class.new(runner_params) }
|
|
|
|
|
|
|
|
describe '#get_runner_details_from_request' do
|
|
|
|
context 'when no runner info is present' do
|
|
|
|
let(:runner_params) { {} }
|
|
|
|
|
|
|
|
it 'returns the runner IP' do
|
|
|
|
expect(runner_helper.get_runner_details_from_request).to eq({ ip_address: ip_address })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner info is present' do
|
|
|
|
let(:name) { 'runner' }
|
|
|
|
let(:version) { '1.2.3' }
|
|
|
|
let(:revision) { '10.0' }
|
|
|
|
let(:platform) { 'test' }
|
|
|
|
let(:architecture) { 'arm' }
|
2021-12-13 10:12:59 -05:00
|
|
|
let(:executor) { 'shell' }
|
2021-05-26 17:10:49 -04:00
|
|
|
let(:config) { { 'gpus' => 'all' } }
|
|
|
|
let(:runner_params) do
|
|
|
|
{
|
|
|
|
'info' =>
|
|
|
|
{
|
|
|
|
'name' => name,
|
|
|
|
'version' => version,
|
|
|
|
'revision' => revision,
|
|
|
|
'platform' => platform,
|
|
|
|
'architecture' => architecture,
|
2021-12-13 10:12:59 -05:00
|
|
|
'executor' => executor,
|
2021-05-26 17:10:49 -04:00
|
|
|
'config' => config,
|
|
|
|
'ignored' => 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:details) { runner_helper.get_runner_details_from_request }
|
|
|
|
|
|
|
|
it 'extracts the runner details', :aggregate_failures do
|
2021-12-13 10:12:59 -05:00
|
|
|
expect(details.keys).to match_array(%w(name version revision platform architecture executor config ip_address))
|
2021-05-26 17:10:49 -04:00
|
|
|
expect(details['name']).to eq(name)
|
|
|
|
expect(details['version']).to eq(version)
|
|
|
|
expect(details['revision']).to eq(revision)
|
|
|
|
expect(details['platform']).to eq(platform)
|
|
|
|
expect(details['architecture']).to eq(architecture)
|
2021-12-13 10:12:59 -05:00
|
|
|
expect(details['executor']).to eq(executor)
|
2021-05-26 17:10:49 -04:00
|
|
|
expect(details['config']).to eq(config)
|
|
|
|
expect(details['ip_address']).to eq(ip_address)
|
|
|
|
end
|
|
|
|
end
|
2022-05-02 14:10:57 -04:00
|
|
|
|
|
|
|
describe '#log_artifact_size' do
|
|
|
|
subject { runner_helper.log_artifact_size(artifact) }
|
|
|
|
|
|
|
|
let(:runner_params) { {} }
|
|
|
|
let(:artifact) { create(:ci_job_artifact, size: 42) }
|
|
|
|
let(:expected_params) { { artifact_size: artifact.size } }
|
|
|
|
let(:subject_proc) { proc { subject } }
|
|
|
|
|
|
|
|
it_behaves_like 'storing arguments in the application context'
|
|
|
|
it_behaves_like 'not executing any extra queries for the application context'
|
|
|
|
end
|
2021-05-26 17:10:49 -04:00
|
|
|
end
|
|
|
|
end
|