diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/github_import/importer/releases_importer_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/clusters/cluster_spec.rb | 9 | ||||
-rw-r--r-- | spec/tasks/gitlab/artifacts/migrate_rake_spec.rb | 42 | ||||
-rw-r--r-- | spec/tasks/gitlab/lfs/migrate_rake_spec.rb | 43 | ||||
-rw-r--r-- | spec/tasks/gitlab/traces_rake_spec.rb | 113 | ||||
-rw-r--r-- | spec/tasks/gitlab/uploads/migrate_rake_spec.rb | 25 | ||||
-rw-r--r-- | spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb | 22 |
7 files changed, 138 insertions, 156 deletions
diff --git a/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb b/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb index 0e5419e6c5e..a1585fd2eb3 100644 --- a/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb @@ -4,17 +4,17 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do let(:project) { create(:project) } let(:client) { double(:client) } let(:importer) { described_class.new(project, client) } + let(:github_release_name) { 'Initial Release' } let(:created_at) { Time.new(2017, 1, 1, 12, 00) } - let(:updated_at) { Time.new(2017, 1, 1, 12, 15) } let(:released_at) { Time.new(2017, 1, 1, 12, 00) } - let(:release) do + let(:github_release) do double( - :release, + :github_release, tag_name: '1.0', + name: github_release_name, body: 'This is my release', created_at: created_at, - updated_at: updated_at, published_at: released_at ) end @@ -25,7 +25,7 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do tag_name: '1.0', description: 'This is my release', created_at: created_at, - updated_at: updated_at, + updated_at: created_at, released_at: released_at } @@ -37,8 +37,8 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do end describe '#build_releases' do - it 'returns an Array containnig release rows' do - expect(importer).to receive(:each_release).and_return([release]) + it 'returns an Array containing release rows' do + expect(importer).to receive(:each_release).and_return([github_release]) rows = importer.build_releases @@ -49,13 +49,13 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do it 'does not create releases that already exist' do create(:release, project: project, tag: '1.0', description: '1.0') - expect(importer).to receive(:each_release).and_return([release]) + expect(importer).to receive(:each_release).and_return([github_release]) expect(importer.build_releases).to be_empty end it 'uses a default release description if none is provided' do - expect(release).to receive(:body).and_return('') - expect(importer).to receive(:each_release).and_return([release]) + expect(github_release).to receive(:body).and_return('') + expect(importer).to receive(:each_release).and_return([github_release]) release = importer.build_releases.first @@ -64,7 +64,7 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do end describe '#build' do - let(:release_hash) { importer.build(release) } + let(:release_hash) { importer.build(github_release) } it 'returns the attributes of the release as a Hash' do expect(release_hash).to be_an_instance_of(Hash) @@ -88,13 +88,17 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do end it 'includes the updated timestamp' do - expect(release_hash[:updated_at]).to eq(updated_at) + expect(release_hash[:updated_at]).to eq(created_at) + end + + it 'includes the release name' do + expect(release_hash[:name]).to eq(github_release_name) end end end describe '#each_release' do - let(:release) { double(:release) } + let(:github_release) { double(:github_release) } before do allow(project).to receive(:import_source).and_return('foo/bar') @@ -102,7 +106,7 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do allow(client) .to receive(:releases) .with('foo/bar') - .and_return([release].to_enum) + .and_return([github_release].to_enum) end it 'returns an Enumerator' do @@ -110,19 +114,19 @@ describe Gitlab::GithubImport::Importer::ReleasesImporter do end it 'yields every release to the Enumerator' do - expect(importer.each_release.next).to eq(release) + expect(importer.each_release.next).to eq(github_release) end end describe '#description_for' do it 'returns the description when present' do - expect(importer.description_for(release)).to eq(release.body) + expect(importer.description_for(github_release)).to eq(github_release.body) end it 'returns a generated description when one is not present' do - allow(release).to receive(:body).and_return('') + allow(github_release).to receive(:body).and_return('') - expect(importer.description_for(release)).to eq('Release for tag 1.0') + expect(importer.description_for(github_release)).to eq('Release for tag 1.0') end end end diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb index 9afbe6328ca..b8a6fd6f914 100644 --- a/spec/models/clusters/cluster_spec.rb +++ b/spec/models/clusters/cluster_spec.rb @@ -38,6 +38,15 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do it { is_expected.to respond_to :project } + describe 'applications have inverse_of: :cluster option' do + let(:cluster) { create(:cluster) } + let!(:helm) { create(:clusters_applications_helm, cluster: cluster) } + + it 'does not do a third query when referencing cluster again' do + expect { cluster.application_helm.cluster }.not_to exceed_query_limit(2) + end + end + describe '.enabled' do subject { described_class.enabled } diff --git a/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb b/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb index be69c10d7c8..afa9ff50146 100644 --- a/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/artifacts/migrate_rake_spec.rb @@ -11,10 +11,11 @@ describe 'gitlab:artifacts namespace rake task' do stub_artifacts_object_storage(enabled: object_storage_enabled) end - subject { run_rake_task('gitlab:artifacts:migrate') } + describe 'gitlab:artifacts:migrate' do + subject { run_rake_task('gitlab:artifacts:migrate') } - context 'job artifacts' do let!(:artifact) { create(:ci_job_artifact, :archive, file_store: store) } + let!(:job_trace) { create(:ci_job_artifact, :trace, file_store: store) } context 'when local storage is used' do let(:store) { ObjectStorage::Store::LOCAL } @@ -27,6 +28,7 @@ describe 'gitlab:artifacts namespace rake task' do subject expect(artifact.reload.file_store).to eq(ObjectStorage::Store::REMOTE) + expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE) end end @@ -37,6 +39,7 @@ describe 'gitlab:artifacts namespace rake task' do subject expect(artifact.reload.file_store).to eq(ObjectStorage::Store::REMOTE) + expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE) end end @@ -45,6 +48,7 @@ describe 'gitlab:artifacts namespace rake task' do subject expect(artifact.reload.file_store).to eq(ObjectStorage::Store::LOCAL) + expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL) end end end @@ -57,6 +61,40 @@ describe 'gitlab:artifacts namespace rake task' do subject expect(artifact.reload.file_store).to eq(ObjectStorage::Store::REMOTE) + expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE) + end + end + end + + describe 'gitlab:artifacts:migrate_to_local' do + let(:object_storage_enabled) { true } + + subject { run_rake_task('gitlab:artifacts:migrate_to_local') } + + let!(:artifact) { create(:ci_job_artifact, :archive, file_store: store) } + let!(:job_trace) { create(:ci_job_artifact, :trace, file_store: store) } + + context 'when remote storage is used' do + let(:store) { ObjectStorage::Store::REMOTE } + + context 'and job has remote file store defined' do + it "migrates file to local storage" do + subject + + expect(artifact.reload.file_store).to eq(ObjectStorage::Store::LOCAL) + expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL) + end + end + end + + context 'when local storage is used' do + let(:store) { ObjectStorage::Store::LOCAL } + + it 'file stays on local storage' do + subject + + expect(artifact.reload.file_store).to eq(ObjectStorage::Store::LOCAL) + expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL) end end end diff --git a/spec/tasks/gitlab/lfs/migrate_rake_spec.rb b/spec/tasks/gitlab/lfs/migrate_rake_spec.rb index 66d1a192a96..a85a0031a6c 100644 --- a/spec/tasks/gitlab/lfs/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/lfs/migrate_rake_spec.rb @@ -5,32 +5,49 @@ describe 'gitlab:lfs namespace rake task' do Rake.application.rake_require 'tasks/gitlab/lfs/migrate' end - describe 'migrate' do + context 'migration tasks' do let(:local) { ObjectStorage::Store::LOCAL } let(:remote) { ObjectStorage::Store::REMOTE } - let!(:lfs_object) { create(:lfs_object, :with_file, file_store: local) } - def lfs_migrate - run_rake_task('gitlab:lfs:migrate') + before do + stub_lfs_object_storage(background_upload: false, direct_upload: false) end - context 'object storage disabled' do - before do - stub_lfs_object_storage(enabled: false) + describe 'migrate' do + subject { run_rake_task('gitlab:lfs:migrate') } + + let!(:lfs_object) { create(:lfs_object, :with_file) } + + context 'object storage disabled' do + before do + stub_lfs_object_storage(enabled: false) + end + + it "doesn't migrate files" do + expect { subject }.not_to change { lfs_object.reload.file_store } + end end - it "doesn't migrate files" do - expect { lfs_migrate }.not_to change { lfs_object.reload.file_store } + context 'object storage enabled' do + it 'migrates local file to object storage' do + expect { subject }.to change { lfs_object.reload.file_store }.from(local).to(remote) + end end end - context 'object storage enabled' do + describe 'migrate_to_local' do + subject { run_rake_task('gitlab:lfs:migrate_to_local') } + + let(:lfs_object) { create(:lfs_object, :with_file, :object_storage) } + before do - stub_lfs_object_storage + stub_lfs_object_storage(background_upload: false, direct_upload: true) end - it 'migrates local file to object storage' do - expect { lfs_migrate }.to change { lfs_object.reload.file_store }.from(local).to(remote) + context 'object storage enabled' do + it 'migrates remote files to local storage' do + expect { subject }.to change { lfs_object.reload.file_store }.from(remote).to(local) + end end end end diff --git a/spec/tasks/gitlab/traces_rake_spec.rb b/spec/tasks/gitlab/traces_rake_spec.rb deleted file mode 100644 index aaf0d7242dd..00000000000 --- a/spec/tasks/gitlab/traces_rake_spec.rb +++ /dev/null @@ -1,113 +0,0 @@ -require 'rake_helper' - -describe 'gitlab:traces rake tasks' do - before do - Rake.application.rake_require 'tasks/gitlab/traces' - end - - describe 'gitlab:traces:archive' do - shared_examples 'passes the job id to worker' do - it do - expect(ArchiveTraceWorker).to receive(:bulk_perform_async).with([[job.id]]) - - run_rake_task('gitlab:traces:archive') - end - end - - shared_examples 'does not pass the job id to worker' do - it do - expect(ArchiveTraceWorker).not_to receive(:bulk_perform_async) - - run_rake_task('gitlab:traces:archive') - end - end - - context 'when trace file stored in default path' do - let!(:job) { create(:ci_build, :success, :trace_live) } - - it_behaves_like 'passes the job id to worker' - end - - context 'when trace is stored in database' do - let!(:job) { create(:ci_build, :success) } - - before do - job.update_column(:trace, 'trace in db') - end - - it_behaves_like 'passes the job id to worker' - end - - context 'when job has trace artifact' do - let!(:job) { create(:ci_build, :success) } - - before do - create(:ci_job_artifact, :trace, job: job) - end - - it_behaves_like 'does not pass the job id to worker' - end - - context 'when job is not finished yet' do - let!(:build) { create(:ci_build, :running, :trace_live) } - - it_behaves_like 'does not pass the job id to worker' - end - end - - describe 'gitlab:traces:migrate' do - let(:object_storage_enabled) { false } - - before do - stub_artifacts_object_storage(enabled: object_storage_enabled) - end - - subject { run_rake_task('gitlab:traces:migrate') } - - let!(:job_trace) { create(:ci_job_artifact, :trace, file_store: store) } - - context 'when local storage is used' do - let(:store) { ObjectStorage::Store::LOCAL } - - context 'and job does not have file store defined' do - let(:object_storage_enabled) { true } - let(:store) { nil } - - it "migrates file to remote storage" do - subject - - expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE) - end - end - - context 'and remote storage is defined' do - let(:object_storage_enabled) { true } - - it "migrates file to remote storage" do - subject - - expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE) - end - end - - context 'and remote storage is not defined' do - it "fails to migrate to remote storage" do - subject - - expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL) - end - end - end - - context 'when remote storage is used' do - let(:object_storage_enabled) { true } - let(:store) { ObjectStorage::Store::REMOTE } - - it "file stays on remote storage" do - subject - - expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE) - end - end - end -end diff --git a/spec/tasks/gitlab/uploads/migrate_rake_spec.rb b/spec/tasks/gitlab/uploads/migrate_rake_spec.rb index 9588e8be5dc..8d1e355a7d3 100644 --- a/spec/tasks/gitlab/uploads/migrate_rake_spec.rb +++ b/spec/tasks/gitlab/uploads/migrate_rake_spec.rb @@ -1,31 +1,42 @@ require 'rake_helper' -describe 'gitlab:uploads:migrate rake tasks' do +describe 'gitlab:uploads:migrate and migrate_to_local rake tasks' do let(:model_class) { nil } let(:uploader_class) { nil } let(:mounted_as) { nil } let(:batch_size) { 3 } before do - stub_env('BATCH', batch_size.to_s) + stub_env('MIGRATION_BATCH_SIZE', batch_size.to_s) stub_uploads_object_storage(uploader_class) Rake.application.rake_require 'tasks/gitlab/uploads/migrate' allow(ObjectStorage::MigrateUploadsWorker).to receive(:perform_async) end - def run + def run(task) args = [uploader_class.to_s, model_class.to_s, mounted_as].compact - run_rake_task("gitlab:uploads:migrate", *args) + run_rake_task(task, *args) end shared_examples 'enqueue jobs in batch' do |batch:| - it do + it 'migrates local storage to remote object storage' do expect(ObjectStorage::MigrateUploadsWorker) .to receive(:perform_async).exactly(batch).times - .and_return("A fake job.") + .and_return("A fake job.") - run + run('gitlab:uploads:migrate') + end + + it 'migrates remote object storage to local storage' do + expect(Upload).to receive(:where).exactly(batch + 1).times { Upload.all } + expect(ObjectStorage::MigrateUploadsWorker) + .to receive(:perform_async) + .with(anything, model_class.name, mounted_as, ObjectStorage::Store::LOCAL) + .exactly(batch).times + .and_return("A fake job.") + + run('gitlab:uploads:migrate_to_local') end end diff --git a/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb b/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb index da490cb02af..6c2544d2efd 100644 --- a/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb +++ b/spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb @@ -11,8 +11,8 @@ describe ObjectStorage::MigrateUploadsWorker, :sidekiq do let(:uploads) { Upload.all } let(:to_store) { ObjectStorage::Store::REMOTE } - def perform(uploads) - described_class.new.perform(uploads.ids, model_class.to_s, mounted_as, to_store) + def perform(uploads, store = nil) + described_class.new.perform(uploads.ids, model_class.to_s, mounted_as, store || to_store) rescue ObjectStorage::MigrateUploadsWorker::Report::MigrationFailures # swallow end @@ -97,12 +97,28 @@ describe ObjectStorage::MigrateUploadsWorker, :sidekiq do it_behaves_like 'outputs correctly', success: 10 - it 'migrates files' do + it 'migrates files to remote storage' do perform(uploads) expect(Upload.where(store: ObjectStorage::Store::LOCAL).count).to eq(0) end + context 'reversed' do + let(:to_store) { ObjectStorage::Store::LOCAL } + + before do + perform(uploads, ObjectStorage::Store::REMOTE) + end + + it 'migrates files to local storage' do + expect(Upload.where(store: ObjectStorage::Store::REMOTE).count).to eq(10) + + perform(uploads) + + expect(Upload.where(store: ObjectStorage::Store::LOCAL).count).to eq(10) + end + end + context 'migration is unsuccessful' do before do allow_any_instance_of(ObjectStorage::Concern) |