Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-06-03 09:04:47 +0300
committerShinya Maeda <shinya@gitlab.com>2018-06-04 08:14:20 +0300
commitbcd664f53a4009bc752fbc47e1c4d6f76c0b8cc2 (patch)
treebf5371ebe3e97e68cb0a8b84680bf32657cbfc12 /spec/migrations
parent0d00d02e842a0c4b22d213e00143a08d97597000 (diff)
Fix specs. Rename migration file name which was conflicted with background migration's.
Diffstat (limited to 'spec/migrations')
-rw-r--r--spec/migrations/archive_legacy_traces_spec.rb45
-rw-r--r--spec/migrations/schedule_to_archive_legacy_traces_spec.rb45
2 files changed, 45 insertions, 45 deletions
diff --git a/spec/migrations/archive_legacy_traces_spec.rb b/spec/migrations/archive_legacy_traces_spec.rb
deleted file mode 100644
index fc61c4bec17..00000000000
--- a/spec/migrations/archive_legacy_traces_spec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require 'spec_helper'
-require Rails.root.join('db', 'post_migrate', '20180529152628_archive_legacy_traces')
-
-describe ArchiveLegacyTraces, :migration do
- let(:namespaces) { table(:namespaces) }
- let(:projects) { table(:projects) }
- let(:builds) { table(:ci_builds) }
- let(:job_artifacts) { table(:ci_job_artifacts) }
-
- before do
- namespaces.create!(id: 123, name: 'gitlab1', path: 'gitlab1')
- projects.create!(id: 123, name: 'gitlab1', path: 'gitlab1', namespace_id: 123)
- build = builds.create!(id: 1)
-
- @legacy_trace_path = File.join(
- Settings.gitlab_ci.builds_path,
- build.created_at.utc.strftime("%Y_%m"),
- build.project_id.to_s,
- "#{job.id}.log"
- )
-
- File.open(@legacy_trace_path, 'wb') { |stream| stream.write('aiueo') }
- end
-
- it 'correctly archive legacy traces' do
- expect(job_artifacts.count).to eq(0)
- expect(File.exist?(@legacy_trace_path)).to be_truthy
-
- migrate!
-
- expect(job_artifacts.count).to eq(1)
- expect(File.exist?(@legacy_trace_path)).to be_falsy
- expect(File.exist?(new_trace_path)).to be_truthy
- end
-
- def new_trace_path
- job_artifact = job_artifacts.first
-
- disk_hash = Digest::SHA2.hexdigest(job_artifact.project_id.to_s)
- creation_date = job_artifact.created_at.utc.strftime('%Y_%m_%d')
-
- File.join(disk_hash[0..1], disk_hash[2..3], disk_hash,
- creation_date, job_artifact.job_id.to_s, job_artifact.id.to_s)
- end
-end
diff --git a/spec/migrations/schedule_to_archive_legacy_traces_spec.rb b/spec/migrations/schedule_to_archive_legacy_traces_spec.rb
new file mode 100644
index 00000000000..d3eac3c45ea
--- /dev/null
+++ b/spec/migrations/schedule_to_archive_legacy_traces_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20180529152628_schedule_to_archive_legacy_traces')
+
+describe ScheduleToArchiveLegacyTraces, :migration do
+ include TraceHelpers
+
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:builds) { table(:ci_builds) }
+ let(:job_artifacts) { table(:ci_job_artifacts) }
+
+ before do
+ namespaces.create!(id: 123, name: 'gitlab1', path: 'gitlab1')
+ projects.create!(id: 123, name: 'gitlab1', path: 'gitlab1', namespace_id: 123)
+ @build_success = builds.create!(id: 1, project_id: 123, status: 'success', type: 'Ci::Build')
+ @build_failed = builds.create!(id: 2, project_id: 123, status: 'failed', type: 'Ci::Build')
+ @builds_canceled = builds.create!(id: 3, project_id: 123, status: 'canceled', type: 'Ci::Build')
+ @build_running = builds.create!(id: 4, project_id: 123, status: 'running', type: 'Ci::Build')
+
+ create_legacy_trace(@build_success, 'This job is done')
+ create_legacy_trace(@build_failed, 'This job is done')
+ create_legacy_trace(@builds_canceled, 'This job is done')
+ create_legacy_trace(@build_running, 'This job is not done yet')
+ end
+
+ it 'correctly archive legacy traces' do
+ expect(job_artifacts.count).to eq(0)
+ expect(File.exist?(legacy_trace_path(@build_success))).to be_truthy
+ expect(File.exist?(legacy_trace_path(@build_failed))).to be_truthy
+ expect(File.exist?(legacy_trace_path(@builds_canceled))).to be_truthy
+ expect(File.exist?(legacy_trace_path(@build_running))).to be_truthy
+
+ migrate!
+
+ expect(job_artifacts.count).to eq(3)
+ expect(File.exist?(legacy_trace_path(@build_success))).to be_falsy
+ expect(File.exist?(legacy_trace_path(@build_failed))).to be_falsy
+ expect(File.exist?(legacy_trace_path(@builds_canceled))).to be_falsy
+ expect(File.exist?(legacy_trace_path(@build_running))).to be_truthy
+ expect(File.exist?(archived_trace_path(job_artifacts.where(job_id: @build_success.id).first))).to be_truthy
+ expect(File.exist?(archived_trace_path(job_artifacts.where(job_id: @build_failed.id).first))).to be_truthy
+ expect(File.exist?(archived_trace_path(job_artifacts.where(job_id: @builds_canceled.id).first))).to be_truthy
+ expect(job_artifacts.where(job_id: @build_running.id)).not_to be_exist
+ end
+end