summaryrefslogtreecommitdiff
path: root/spec/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'spec/tasks')
-rw-r--r--spec/tasks/gitlab/db_rake_spec.rb53
-rw-r--r--spec/tasks/gitlab/packages/composer_rake_spec.rb29
2 files changed, 12 insertions, 70 deletions
diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb
index 91cd09fc6e6..ad4ada9a9f1 100644
--- a/spec/tasks/gitlab/db_rake_spec.rb
+++ b/spec/tasks/gitlab/db_rake_spec.rb
@@ -293,53 +293,24 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
end
describe '#migrate_with_instrumentation' do
- subject { run_rake_task('gitlab:db:migration_testing') }
+ describe '#up' do
+ subject { run_rake_task('gitlab:db:migration_testing:up') }
- let(:ctx) { double('ctx', migrations: all_migrations, schema_migration: double, get_all_versions: existing_versions) }
- let(:instrumentation) { instance_double(Gitlab::Database::Migrations::Instrumentation, observations: observations) }
- let(:existing_versions) { [1] }
- let(:all_migrations) { [double('migration1', version: 1, name: 'test'), pending_migration] }
- let(:pending_migration) { double('migration2', version: 2, name: 'test') }
- let(:filename) { Gitlab::Database::Migrations::Instrumentation::STATS_FILENAME }
- let(:result_dir) { Dir.mktmpdir }
- let(:observations) { %w[some data] }
+ it 'delegates to the migration runner' do
+ expect(::Gitlab::Database::Migrations::Runner).to receive_message_chain(:up, :run)
- before do
- allow(ActiveRecord::Base.connection).to receive(:migration_context).and_return(ctx)
- allow(Gitlab::Database::Migrations::Instrumentation).to receive(:new).and_return(instrumentation)
- allow(ActiveRecord::Migrator).to receive_message_chain('new.run').with(any_args).with(no_args)
-
- allow(instrumentation).to receive(:observe).and_yield
-
- stub_const('Gitlab::Database::Migrations::Instrumentation::RESULT_DIR', result_dir)
- end
-
- after do
- FileUtils.rm_rf(result_dir)
- end
-
- it 'creates result directory when one does not exist' do
- FileUtils.rm_rf(result_dir)
-
- expect { subject }.to change { Dir.exist?(result_dir) }.from(false).to(true)
- end
-
- it 'instruments the pending migration' do
- expect(instrumentation).to receive(:observe).with(version: 2, name: 'test').and_yield
-
- subject
+ subject
+ end
end
- it 'executes the pending migration' do
- expect(ActiveRecord::Migrator).to receive_message_chain('new.run').with(:up, ctx.migrations, ctx.schema_migration, pending_migration.version).with(no_args)
+ describe '#down' do
+ subject { run_rake_task('gitlab:db:migration_testing:down') }
- subject
- end
-
- it 'writes observations out to JSON file' do
- subject
+ it 'delegates to the migration runner' do
+ expect(::Gitlab::Database::Migrations::Runner).to receive_message_chain(:down, :run)
- expect(File.read(File.join(result_dir, filename))).to eq(observations.to_json)
+ subject
+ end
end
end
diff --git a/spec/tasks/gitlab/packages/composer_rake_spec.rb b/spec/tasks/gitlab/packages/composer_rake_spec.rb
deleted file mode 100644
index f4f43bf77d8..00000000000
--- a/spec/tasks/gitlab/packages/composer_rake_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-require 'rake_helper'
-
-RSpec.describe 'gitlab:packages:build_composer_cache namespace rake task', :silence_stdout do
- let_it_be(:package_name) { 'sample-project' }
- let_it_be(:package_name2) { 'sample-project2' }
- let_it_be(:json) { { 'name' => package_name } }
- let_it_be(:json2) { { 'name' => package_name2 } }
- let_it_be(:group) { create(:group) }
- let_it_be(:project) { create(:project, :custom_repo, files: { 'composer.json' => json.to_json }, group: group) }
- let_it_be(:project2) { create(:project, :custom_repo, files: { 'composer.json' => json2.to_json }, group: group) }
-
- let!(:package) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '1.0.0', json: json) }
- let!(:package2) { create(:composer_package, :with_metadatum, project: project, name: package_name, version: '2.0.0', json: json) }
- let!(:package3) { create(:composer_package, :with_metadatum, project: project2, name: package_name2, version: '3.0.0', json: json2) }
-
- before :all do
- Rake.application.rake_require 'tasks/gitlab/packages/composer'
- end
-
- subject do
- run_rake_task("gitlab:packages:build_composer_cache")
- end
-
- it 'generates the cache files' do
- expect { subject }.to change { Packages::Composer::CacheFile.count }.by(2)
- end
-end