debian-mirror-gitlab/spec/tasks/gitlab/terraform/migrate_rake_spec.rb

46 lines
1.4 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
require 'rake_helper'
2021-09-04 01:27:46 +05:30
RSpec.describe 'gitlab:terraform_states', :silence_stdout do
2021-03-11 19:13:27 +05:30
let_it_be(:version) { create(:terraform_state_version) }
let(:logger) { instance_double(Logger) }
let(:helper) { double }
before(:all) do
Rake.application.rake_require 'tasks/gitlab/terraform/migrate'
end
before do
2021-09-04 01:27:46 +05:30
allow(Logger).to receive(:new).with($stdout).and_return(logger)
2021-03-11 19:13:27 +05:30
end
describe 'gitlab:terraform_states:migrate' do
subject { run_rake_task('gitlab:terraform_states:migrate') }
it 'invokes the migration helper to move files to object storage' do
expect(Gitlab::Terraform::StateMigrationHelper).to receive(:migrate_to_remote_storage).and_yield(version)
expect(logger).to receive(:info).with('Starting transfer of Terraform states to object storage')
expect(logger).to receive(:info).with(/Transferred Terraform state version ID #{version.id}/)
subject
end
context 'an error is raised while migrating' do
let(:error_message) { 'Something went wrong' }
before do
allow(Gitlab::Terraform::StateMigrationHelper).to receive(:migrate_to_remote_storage).and_raise(StandardError, error_message)
end
it 'logs the error' do
expect(logger).to receive(:info).with('Starting transfer of Terraform states to object storage')
expect(logger).to receive(:error).with("Failed to migrate: #{error_message}")
subject
end
end
end
end