67 lines
2.9 KiB
Ruby
67 lines
2.9 KiB
Ruby
require 'lib/executors/stack_executor'
|
|
|
|
class Devops::Executor::StackExecutor
|
|
RSpec.describe self, type: :executor, stubbed_connector: true, stubbed_logger: true do
|
|
let(:out) { double('out', puts: nil, flush: nil) }
|
|
let(:stack) { build(:stack) }
|
|
let(:executor_without_stack) { described_class.new(out: out) }
|
|
let(:executor_with_stack) { described_class.new(out: out, stack: stack) }
|
|
|
|
describe '#wait_till_stack_is_created' do
|
|
it "return true if syncer returns ok" do
|
|
allow_any_instance_of(StackCreationWaiter).to receive(:sync) { double("creation_result", ok?: true) }
|
|
expect(executor_with_stack.wait_till_stack_is_created).to be true
|
|
end
|
|
|
|
it "return false if syncer returns not ok" do
|
|
allow_any_instance_of(StackCreationWaiter).to receive(:sync) { double("creation_result", ok?: false, reason: '') }
|
|
expect(executor_with_stack.wait_till_stack_is_created).to be false
|
|
end
|
|
end
|
|
|
|
describe '#create_stack', stubbed_connector: true do
|
|
it 'initiate creation in cloud and persists stack' do
|
|
expect(Devops::Model::StackFactory).to receive(:create).with('ec2', instance_of(Hash), out)
|
|
expect(stubbed_connector).to receive(:stack_insert)
|
|
executor_with_stack.create_stack({'provider' => 'ec2'})
|
|
end
|
|
end
|
|
|
|
describe '#persist_stack_servers' do
|
|
let(:persister) {
|
|
instance_double(StackServersPersister,
|
|
persist_new_servers: nil, just_persisted_by_priority: nil, deleted: nil
|
|
)
|
|
}
|
|
before { allow(StackServersPersister).to receive(:new).and_return(persister) }
|
|
|
|
it 'calls StackServersPersister#persist_new_servers' do
|
|
expect(persister).to receive(:persist_new_servers)
|
|
executor_with_stack.persist_stack_servers
|
|
end
|
|
|
|
it 'returns hash with :just_persisted_by_priority and :deleted keys' do
|
|
expect(executor_with_stack.persist_stack_servers).to include(just_persisted_by_priority: nil, deleted: nil)
|
|
end
|
|
end
|
|
|
|
describe '#bootstrap_servers_by_priority' do
|
|
it 'calls PrioritizedGroupsBootstrapper#bootstrap_servers_by_priority' do
|
|
result = double('bootstrap_result')
|
|
allow_any_instance_of(PrioritizedGroupsBootstrapper).to receive(:bootstrap_servers_by_priority) { result }
|
|
expect_any_instance_of(PrioritizedGroupsBootstrapper).to receive(:bootstrap_servers_by_priority)
|
|
expect(executor_with_stack.bootstrap_servers_by_priority({}, 1000)).to eq result
|
|
end
|
|
end
|
|
|
|
describe '#delete_stack', stubbed_connector: true do
|
|
it 'deletes stack from cloud, then deletes stack servers, and then deletes stack itself' do
|
|
expect(stack).to receive(:delete_stack_in_cloud!).ordered
|
|
expect(stubbed_connector).to receive(:stack_servers_delete).ordered
|
|
expect(stubbed_connector).to receive(:stack_delete).ordered
|
|
executor_with_stack.delete_stack
|
|
end
|
|
|
|
end
|
|
end
|
|
end |