Commit 20462ea0 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix specs failures, and use factory with `:ci_job_artifact, :archive`

parent 68616987
...@@ -6,7 +6,7 @@ class JobArtifactUploader < ObjectStoreUploader ...@@ -6,7 +6,7 @@ class JobArtifactUploader < ObjectStoreUploader
end end
def self.artifacts_upload_path def self.artifacts_upload_path
File.join(self.local_artifacts_store, 'tmp/uploads/') File.join(self.local_store_path, 'tmp/uploads/')
end end
def size def size
......
...@@ -167,8 +167,8 @@ FactoryGirl.define do ...@@ -167,8 +167,8 @@ FactoryGirl.define do
trait :artifacts do trait :artifacts do
after(:create) do |build| after(:create) do |build|
create(:ci_job_artifact, job: build) create(:ci_job_artifact, :archive, job: build)
create(:ci_job_metadata, job: build) create(:ci_job_artifact, :metadata, job: build)
build.reload build.reload
end end
end end
......
...@@ -13,22 +13,24 @@ FactoryGirl.define do ...@@ -13,22 +13,24 @@ FactoryGirl.define do
artifact.project ||= artifact.job.project artifact.project ||= artifact.job.project
end end
after :create do |artifact| trait :archive do
if artifact.archive? after(:create) do |artifact, _|
artifact.file = fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts.zip'), artifact.update!(
'application/zip') file_type: :archive,
artifact.save file: fixture_file_upload(
Rails.root.join('spec/fixtures/ci_build_artifacts.zip'), 'application/zip')
)
end end
end end
end
factory :ci_job_metadata, parent: :ci_job_artifact do
file_type :metadata
after :create do |artifact| trait :metadata do
artifact.file = fixture_file_upload(Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'), after(:create) do |artifact, _|
'application/x-gzip') artifact.update!(
artifact.save file_type: :metadata,
file: fixture_file_upload(
Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'), 'application/x-gzip')
)
end
end end
end end
end end
...@@ -40,7 +40,7 @@ describe MigrateOldArtifacts do ...@@ -40,7 +40,7 @@ describe MigrateOldArtifacts do
end end
it "legacy artifacts are set" do it "legacy artifacts are set" do
expect(build_with_legacy_artifacts.artifacts_file_identifier).not_to be_nil expect(build_with_legacy_artifacts.legacy_artifacts_file_identifier).not_to be_nil
end end
describe '#min_id' do describe '#min_id' do
......
require 'spec_helper' require 'spec_helper'
describe Ci::JobArtifact do describe Ci::JobArtifact do
set(:artifact) { create(:ci_job_artifact) } set(:artifact) { create(:ci_job_artifact, :archive) }
describe "Associations" do describe "Associations" do
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
......
...@@ -137,7 +137,7 @@ describe ProjectStatistics do ...@@ -137,7 +137,7 @@ describe ProjectStatistics do
before do before do
create(:ci_build, pipeline: pipeline, artifacts_size: 56.megabytes) create(:ci_build, pipeline: pipeline, artifacts_size: 56.megabytes)
create(:ci_job_artifact, project: pipeline.project, job: ci_build) create(:ci_job_artifact, :archive, project: pipeline.project, job: ci_build)
statistics.update_build_artifacts_size statistics.update_build_artifacts_size
end end
......
...@@ -2,14 +2,46 @@ require 'spec_helper' ...@@ -2,14 +2,46 @@ require 'spec_helper'
describe JobArtifactUploader do describe JobArtifactUploader do
set(:job_artifact) { create(:ci_job_artifact) } set(:job_artifact) { create(:ci_job_artifact) }
let(:job) { job_artifact.job }
let(:uploader) { described_class.new(job_artifact, :file) } let(:uploader) { described_class.new(job_artifact, :file) }
let(:path) { Gitlab.config.artifacts.path }
describe '#store_dir' do describe '#store_dir' do
subject { uploader.store_dir } subject { uploader.store_dir }
it { is_expected.to start_with(Gitlab.config.artifacts.path) } it { is_expected.to start_with(path) }
it { is_expected.not_to end_with("#{job.project_id}/#{job.created_at.utc.strftime('%Y_%m')}/#{job.id}") } it { is_expected.not_to end_with("#{job_artifact.project_id}/#{job_artifact.created_at.utc.strftime('%Y_%m')}/#{job_artifact.id}") }
it { is_expected.to match(/\h{2}\/\h{2}\/\h{64}\/\d{4}_\d{1,2}_\d{1,2}\/\d+\/\d+\z/) } it { is_expected.to match(/\h{2}\/\h{2}\/\h{64}\/\d{4}_\d{1,2}_\d{1,2}\/\d+\/\d+\z/) }
end end
describe '#cache_dir' do
subject { uploader.cache_dir }
it { is_expected.to start_with(path) }
it { is_expected.to end_with('/tmp/cache') }
end
describe '#work_dir' do
subject { uploader.work_dir }
it { is_expected.to start_with(path) }
it { is_expected.to end_with('/tmp/work') }
end
context 'file is stored in valid path' do
let(:file) do
fixture_file_upload(Rails.root.join(
'spec/fixtures/ci_build_artifacts.zip'), 'application/zip')
end
before do
uploader.store!(file)
end
subject { uploader.file.path }
it { is_expected.to start_with(path) }
it { is_expected.to include("/#{job_artifact.created_at.utc.strftime('%Y_%m_%d')}/") }
it { is_expected.to include("/#{job_artifact.project_id.to_s}/") }
it { is_expected.to end_with("ci_build_artifacts.zip") }
end
end end
...@@ -67,4 +67,22 @@ describe LegacyArtifactUploader do ...@@ -67,4 +67,22 @@ describe LegacyArtifactUploader do
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
context 'file is stored in valid path' do
let(:file) do
fixture_file_upload(Rails.root.join(
'spec/fixtures/ci_build_artifacts.zip'), 'application/zip')
end
before do
uploader.store!(file)
end
subject { uploader.file.path }
it { is_expected.to start_with(path) }
it { is_expected.to include("/#{job.created_at.utc.strftime('%Y_%m')}/") }
it { is_expected.to include("/#{job.project_id.to_s}/") }
it { is_expected.to end_with("ci_build_artifacts.zip") }
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