50 lines
1.7 KiB
Ruby
50 lines
1.7 KiB
Ruby
|
|
require 'lib/executors/server_executor'
|
||
|
|
|
||
|
|
RSpec.describe Devops::Executor::ServerExecutor, type: :executor, stubbed_connector: true do
|
||
|
|
let(:project) { build(:project) }
|
||
|
|
let(:deploy_env) { project.deploy_env('foo') }
|
||
|
|
let(:server) { build(:server, project: project.id, deploy_env: 'foo') }
|
||
|
|
let(:executor) { described_class.new(server, '') }
|
||
|
|
|
||
|
|
before do
|
||
|
|
allow(stubbed_connector).to receive(:project) { project }
|
||
|
|
end
|
||
|
|
|
||
|
|
describe '#initialize' do
|
||
|
|
|
||
|
|
it 'sets server, project, deploy_env, out instance variables' do
|
||
|
|
expect(executor).to have_instance_variable_value(:server, server)
|
||
|
|
expect(executor).to have_instance_variable_value(:project, project)
|
||
|
|
expect(executor).to have_instance_variable_value(:deploy_env, deploy_env)
|
||
|
|
expect(executor).to have_instance_variable_value(:out, '')
|
||
|
|
end
|
||
|
|
|
||
|
|
it 'set knife_instance instance variable' do
|
||
|
|
allow(KnifeFactory).to receive(:instance)
|
||
|
|
expect(executor).to be_instance_variable_defined(:@knife_instance)
|
||
|
|
end
|
||
|
|
|
||
|
|
it 'defines :flush method on @out if it is absent' do
|
||
|
|
out = Class.new.new
|
||
|
|
expect(out).not_to respond_to(:flush)
|
||
|
|
described_class.new(server, out)
|
||
|
|
expect(out).to respond_to(:flush)
|
||
|
|
end
|
||
|
|
|
||
|
|
it 'sets current_user from options' do
|
||
|
|
user = double
|
||
|
|
executor = described_class.new(server, '', {current_user: user})
|
||
|
|
expect(executor).to have_instance_variable_value(:current_user, user)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
describe '#create_server_object' do
|
||
|
|
it 'builds Server object' do
|
||
|
|
server = executor.create_server_object('created_by' => 'me')
|
||
|
|
expect(server).to be_a(Devops::Model::Server)
|
||
|
|
expect(server.project).to eq 'my_project'
|
||
|
|
expect(server.deploy_env).to eq 'foo'
|
||
|
|
expect(server.created_by).to eq 'me'
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|