Generalize method and constant names for runner management
This commit is contained in:
@ -192,45 +192,4 @@ describe ExecutionEnvironment do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#copy_to_poseidon' do
|
||||
let(:execution_environment) { FactoryBot.create(:ruby) }
|
||||
|
||||
it 'makes the correct request to Poseidon' do
|
||||
allow(Faraday).to receive(:put).and_return(Faraday::Response.new(status: 201))
|
||||
execution_environment.copy_to_poseidon
|
||||
expect(Faraday).to have_received(:put) do |url, body, headers|
|
||||
expect(url).to match(%r{execution-environments/#{execution_environment.id}\z})
|
||||
expect(body).to eq(execution_environment.to_json)
|
||||
expect(headers).to include({'Content-Type' => 'application/json'})
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'returns true when the api request was successful' do |status|
|
||||
it "returns true on status #{status}" do
|
||||
allow(Faraday).to receive(:put).and_return(Faraday::Response.new(status: status))
|
||||
expect(execution_environment.copy_to_poseidon).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'returns false when the api request failed' do |status|
|
||||
it "returns false on status #{status}" do
|
||||
allow(Faraday).to receive(:put).and_return(Faraday::Response.new(status: status))
|
||||
expect(execution_environment.copy_to_poseidon).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
[201, 204].each do |status|
|
||||
include_examples 'returns true when the api request was successful', status
|
||||
end
|
||||
|
||||
[400, 500].each do |status|
|
||||
include_examples 'returns false when the api request failed', status
|
||||
end
|
||||
|
||||
it 'returns false if Faraday raises an error' do
|
||||
allow(Faraday).to receive(:put).and_raise(Faraday::TimeoutError)
|
||||
expect(execution_environment.copy_to_poseidon).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -30,8 +30,20 @@ describe Runner do
|
||||
|
||||
describe '::strategy_class' do
|
||||
shared_examples 'uses the strategy defined in the constant' do |strategy, strategy_class|
|
||||
let(:codeocean_config) { instance_double(CodeOcean::Config) }
|
||||
let(:runner_management_config) { {runner_management: {enabled: true, strategy: strategy}} }
|
||||
|
||||
before do
|
||||
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
|
||||
allow(codeocean_config).to receive(:read).and_return(runner_management_config)
|
||||
end
|
||||
|
||||
after do
|
||||
# Reset the memorized helper
|
||||
described_class.remove_instance_variable :@strategy_class
|
||||
end
|
||||
|
||||
it "uses #{strategy_class} as strategy class for constant #{strategy}" do
|
||||
stub_const('Runner::STRATEGY_NAME', strategy)
|
||||
expect(described_class.strategy_class).to eq(strategy_class)
|
||||
end
|
||||
end
|
||||
@ -41,7 +53,7 @@ describe Runner do
|
||||
docker_container_pool: Runner::Strategy::DockerContainerPool,
|
||||
}
|
||||
available_strategies.each do |strategy, strategy_class|
|
||||
include_examples 'uses the strategy defined in the constant', strategy, strategy_class
|
||||
it_behaves_like 'uses the strategy defined in the constant', strategy, strategy_class
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user