Commit 88967ac4 authored by Alishan Ladhani's avatar Alishan Ladhani

Don't raise an error if output directory already exists

parent 73a754e9
...@@ -240,9 +240,7 @@ namespace :gitlab do ...@@ -240,9 +240,7 @@ namespace :gitlab do
desc 'Run migrations with instrumentation' desc 'Run migrations with instrumentation'
task migration_testing: :environment do task migration_testing: :environment do
result_dir = Gitlab::Database::Migrations::Instrumentation::RESULT_DIR result_dir = Gitlab::Database::Migrations::Instrumentation::RESULT_DIR
raise "Directory exists already, won't overwrite: #{result_dir}" if File.exist?(result_dir) FileUtils.mkdir_p(result_dir)
Dir.mkdir(result_dir)
verbose_was = ActiveRecord::Migration.verbose verbose_was = ActiveRecord::Migration.verbose
ActiveRecord::Migration.verbose = true ActiveRecord::Migration.verbose = true
......
...@@ -306,7 +306,7 @@ RSpec.describe 'gitlab:db namespace rake task' do ...@@ -306,7 +306,7 @@ RSpec.describe 'gitlab:db namespace rake task' do
let(:all_migrations) { [double('migration1', version: 1), pending_migration] } let(:all_migrations) { [double('migration1', version: 1), pending_migration] }
let(:pending_migration) { double('migration2', version: 2) } let(:pending_migration) { double('migration2', version: 2) }
let(:filename) { Gitlab::Database::Migrations::Instrumentation::STATS_FILENAME } let(:filename) { Gitlab::Database::Migrations::Instrumentation::STATS_FILENAME }
let!(:directory) { Dir.mktmpdir } let(:result_dir) { Dir.mktmpdir }
let(:observations) { %w[some data] } let(:observations) { %w[some data] }
before do before do
...@@ -316,19 +316,17 @@ RSpec.describe 'gitlab:db namespace rake task' do ...@@ -316,19 +316,17 @@ RSpec.describe 'gitlab:db namespace rake task' do
allow(instrumentation).to receive(:observe).and_yield allow(instrumentation).to receive(:observe).and_yield
allow(Dir).to receive(:mkdir) stub_const('Gitlab::Database::Migrations::Instrumentation::RESULT_DIR', result_dir)
allow(File).to receive(:exist?).with(directory).and_return(false)
stub_const('Gitlab::Database::Migrations::Instrumentation::RESULT_DIR', directory)
end end
after do after do
FileUtils.rm_rf([directory]) FileUtils.rm_rf(result_dir)
end end
it 'fails when the directory already exists' do it 'creates result directory when one does not exist' do
expect(File).to receive(:exist?).with(directory).and_return(true) FileUtils.rm_rf(result_dir)
expect { subject }.to raise_error(/Directory exists/) expect { subject }.to change { Dir.exist?(result_dir) }.from(false).to(true)
end end
it 'instruments the pending migration' do it 'instruments the pending migration' do
...@@ -346,7 +344,7 @@ RSpec.describe 'gitlab:db namespace rake task' do ...@@ -346,7 +344,7 @@ RSpec.describe 'gitlab:db namespace rake task' do
it 'writes observations out to JSON file' do it 'writes observations out to JSON file' do
subject subject
expect(File.read(File.join(directory, filename))).to eq(observations.to_json) expect(File.read(File.join(result_dir, filename))).to eq(observations.to_json)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment