summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2017-11-08 10:46:47 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2017-12-03 12:04:49 +0100
commitba5697fd809563cb2fd619d7c50362303ab86434 (patch)
tree3aeacb4859798379b9a2ed1cf41356e49fb70cae
parent1756604f90588a746ce6df7e4386830db9b3a485 (diff)
downloadgitlab-ce-ba5697fd809563cb2fd619d7c50362303ab86434.tar.gz
Fix legacy migration test
-rw-r--r--app/uploaders/artifact_uploader.rb4
-rw-r--r--db/migrate/20170918072948_create_job_artifacts.rb4
-rw-r--r--spec/migrations/migrate_old_artifacts_spec.rb37
-rw-r--r--spec/support/test_env.rb5
-rw-r--r--spec/uploaders/artifact_uploader_spec.rb2
5 files changed, 38 insertions, 14 deletions
diff --git a/app/uploaders/artifact_uploader.rb b/app/uploaders/artifact_uploader.rb
index d4dda8e9e67..14addb6cf14 100644
--- a/app/uploaders/artifact_uploader.rb
+++ b/app/uploaders/artifact_uploader.rb
@@ -34,8 +34,6 @@ class ArtifactUploader < GitlabUploader
end
def default_path
- File.join(job.project_id.to_s,
- job.created_at.utc.strftime('%Y_%m'),
- job.id.to_s)
+ File.join(job.created_at.utc.strftime('%Y_%m'), job.project_id.to_s, job.id.to_s)
end
end
diff --git a/db/migrate/20170918072948_create_job_artifacts.rb b/db/migrate/20170918072948_create_job_artifacts.rb
index 078e3e9dc4e..90152127ed5 100644
--- a/db/migrate/20170918072948_create_job_artifacts.rb
+++ b/db/migrate/20170918072948_create_job_artifacts.rb
@@ -14,8 +14,8 @@ class CreateJobArtifacts < ActiveRecord::Migration
t.datetime_with_timezone :updated_at, null: false
t.string :file
- end
- add_foreign_key :ci_job_artifacts, :ci_builds, column: :job_id, on_delete: :cascade
+ t.foreign_key :ci_builds, column: :job_id, on_delete: :cascade
+ end
end
end
diff --git a/spec/migrations/migrate_old_artifacts_spec.rb b/spec/migrations/migrate_old_artifacts_spec.rb
index 81366d15b34..b09243e5c95 100644
--- a/spec/migrations/migrate_old_artifacts_spec.rb
+++ b/spec/migrations/migrate_old_artifacts_spec.rb
@@ -16,20 +16,22 @@ describe MigrateOldArtifacts do
end
context 'with migratable data' do
- let(:project1) { create(:project, ci_id: 2) }
- let(:project2) { create(:project, ci_id: 3) }
- let(:project3) { create(:project) }
+ set(:project1) { create(:project, ci_id: 2) }
+ set(:project2) { create(:project, ci_id: 3) }
+ set(:project3) { create(:project) }
- let(:pipeline1) { create(:ci_empty_pipeline, project: project1) }
- let(:pipeline2) { create(:ci_empty_pipeline, project: project2) }
- let(:pipeline3) { create(:ci_empty_pipeline, project: project3) }
+ set(:pipeline1) { create(:ci_empty_pipeline, project: project1) }
+ set(:pipeline2) { create(:ci_empty_pipeline, project: project2) }
+ set(:pipeline3) { create(:ci_empty_pipeline, project: project3) }
let!(:build_with_legacy_artifacts) { create(:ci_build, pipeline: pipeline1) }
let!(:build_without_artifacts) { create(:ci_build, pipeline: pipeline1) }
- let!(:build2) { create(:ci_build, :artifacts, pipeline: pipeline2) }
- let!(:build3) { create(:ci_build, :artifacts, pipeline: pipeline3) }
+ let!(:build2) { create(:ci_build, pipeline: pipeline2) }
+ let!(:build3) { create(:ci_build, pipeline: pipeline3) }
before do
+ setup_builds(build2, build3)
+
store_artifacts_in_legacy_path(build_with_legacy_artifacts)
end
@@ -113,5 +115,24 @@ describe MigrateOldArtifacts do
build.project.ci_id.to_s,
build.id.to_s)
end
+
+ def new_legacy_path(build)
+ File.join(directory,
+ build.created_at.utc.strftime('%Y_%m'),
+ build.project_id.to_s,
+ build.id.to_s)
+ end
+
+ def setup_builds(*builds)
+ builds.each do |build|
+ FileUtils.mkdir_p(new_legacy_path(build))
+
+ build.update_columns(
+ artifacts_file: 'ci_build_artifacts.zip',
+ artifacts_metadata: 'ci_build_artifacts_metadata.gz')
+
+ build.reload
+ end
+ end
end
end
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
index fff120fcb88..b300b493f86 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/test_env.rb
@@ -120,6 +120,7 @@ module TestEnv
FileUtils.mkdir_p(repos_path)
FileUtils.mkdir_p(backup_path)
FileUtils.mkdir_p(pages_path)
+ FileUtils.mkdir_p(artifacts_path)
end
def clean_gitlab_test_path
@@ -233,6 +234,10 @@ module TestEnv
Gitlab.config.pages.path
end
+ def artifacts_path
+ Gitlab.config.artifacts.path
+ end
+
# When no cached assets exist, manually hit the root path to create them
#
# Otherwise they'd be created by the first test, often timing out and
diff --git a/spec/uploaders/artifact_uploader_spec.rb b/spec/uploaders/artifact_uploader_spec.rb
index 9cb2c090b43..0a07a7337b5 100644
--- a/spec/uploaders/artifact_uploader_spec.rb
+++ b/spec/uploaders/artifact_uploader_spec.rb
@@ -26,7 +26,7 @@ describe ArtifactUploader do
subject { uploader.store_dir }
it { is_expected.to start_with(path) }
- it { is_expected.to end_with("#{job.project_id}/#{job.created_at.utc.strftime('%Y_%m')}/#{job.id}") }
+ it { is_expected.to end_with("#{job.project_id}/#{job.id}") }
end
describe '#cache_dir' do