Commit 01fe6506 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg Committed by Kamil Trzcinski

Fix bunch of test failures

parent 8c021a2e
...@@ -338,6 +338,10 @@ module Ci ...@@ -338,6 +338,10 @@ module Ci
project.running_or_pending_build_count(force: true) project.running_or_pending_build_count(force: true)
end end
def browsable_artifacts?
artifacts_metadata?
end
def artifacts_metadata_entry(path, **options) def artifacts_metadata_entry(path, **options)
artifacts_metadata.use_file do |metadata_path| artifacts_metadata.use_file do |metadata_path|
metadata = Gitlab::Ci::Build::Artifacts::Metadata.new( metadata = Gitlab::Ci::Build::Artifacts::Metadata.new(
......
...@@ -764,6 +764,7 @@ test: ...@@ -764,6 +764,7 @@ test:
aws_secret_access_key: AWS_SECRET_ACCESS_KEY aws_secret_access_key: AWS_SECRET_ACCESS_KEY
region: eu-central-1 region: eu-central-1
artifacts: artifacts:
path: tmp/tests/artifacts
enabled: true enabled: true
# The location where build artifacts are stored (default: shared/artifacts). # The location where build artifacts are stored (default: shared/artifacts).
# path: shared/artifacts # path: shared/artifacts
...@@ -785,8 +786,6 @@ test: ...@@ -785,8 +786,6 @@ test:
# user: YOUR_USERNAME # user: YOUR_USERNAME
pages: pages:
path: tmp/tests/pages path: tmp/tests/pages
artifacts:
path: tmp/tests/artifacts
repositories: repositories:
storages: storages:
default: default:
......
...@@ -12,6 +12,6 @@ class AddFileStoreJobArtifacts < ActiveRecord::Migration ...@@ -12,6 +12,6 @@ class AddFileStoreJobArtifacts < ActiveRecord::Migration
end end
def down def down
drop_column(:ci_job_artifacts, :file_store) remove_column(:ci_job_artifacts, :file_store)
end end
end end
...@@ -474,7 +474,6 @@ ActiveRecord::Schema.define(version: 20171124165823) do ...@@ -474,7 +474,6 @@ ActiveRecord::Schema.define(version: 20171124165823) do
t.integer "source" t.integer "source"
t.boolean "protected" t.boolean "protected"
t.integer "failure_reason" t.integer "failure_reason"
t.integer "config_source"
end end
add_index "ci_pipelines", ["auto_canceled_by_id"], name: "index_ci_pipelines_on_auto_canceled_by_id", using: :btree add_index "ci_pipelines", ["auto_canceled_by_id"], name: "index_ci_pipelines_on_auto_canceled_by_id", using: :btree
......
...@@ -12,8 +12,8 @@ namespace :gitlab do ...@@ -12,8 +12,8 @@ namespace :gitlab do
.with_artifacts_stored_locally .with_artifacts_stored_locally
.find_each(batch_size: 10) do |build| .find_each(batch_size: 10) do |build|
begin begin
build.artifacts_file.migrate!(ArtifactUploader::REMOTE_STORE) build.artifacts_file.migrate!(ObjectStoreUploader::REMOTE_STORE)
build.artifacts_metadata.migrate!(ArtifactUploader::REMOTE_STORE) build.artifacts_metadata.migrate!(ObjectStoreUploader::REMOTE_STORE)
logger.info("Transferred artifacts of #{build.id} of #{build.artifacts_size} to object storage") logger.info("Transferred artifacts of #{build.id} of #{build.artifacts_size} to object storage")
rescue => e rescue => e
......
...@@ -117,7 +117,8 @@ describe Projects::ArtifactsController do ...@@ -117,7 +117,8 @@ describe Projects::ArtifactsController do
context 'when the file exists' do context 'when the file exists' do
let(:path) { 'ci_artifacts.txt' } let(:path) { 'ci_artifacts.txt' }
let(:job) { create(:ci_build, :success, :artifacts, pipeline: pipeline, artifacts_file_store: store, artifacts_metadata_store: store) } let(:job) { create(:ci_build, :success, pipeline: pipeline) }
let!(:artifact) { create(:ci_job_artifact, job: job, file_store: store) }
shared_examples 'a valid file' do shared_examples 'a valid file' do
it 'serves the file using workhorse' do it 'serves the file using workhorse' do
......
...@@ -4,7 +4,6 @@ FactoryGirl.define do ...@@ -4,7 +4,6 @@ FactoryGirl.define do
factory :ci_job_artifact, class: Ci::JobArtifact do factory :ci_job_artifact, class: Ci::JobArtifact do
job factory: :ci_build job factory: :ci_build
file_type :archive file_type :archive
file_store JobArtifactUploader::LOCAL_STORE
trait :remote_store do trait :remote_store do
file_store JobArtifactUploader::REMOTE_STORE file_store JobArtifactUploader::REMOTE_STORE
......
...@@ -299,13 +299,16 @@ describe API::Jobs do ...@@ -299,13 +299,16 @@ describe API::Jobs do
context 'normal authentication' do context 'normal authentication' do
before do before do
stub_artifacts_object_storage stub_artifacts_object_storage
get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user)
end end
context 'job with artifacts' do context 'job with artifacts' do
context 'when artifacts are stored locally' do context 'when artifacts are stored locally' do
let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) } let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) }
before do
get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user)
end
context 'authorized user' do context 'authorized user' do
it_behaves_like 'downloads artifact' it_behaves_like 'downloads artifact'
end end
...@@ -320,7 +323,14 @@ describe API::Jobs do ...@@ -320,7 +323,14 @@ describe API::Jobs do
end end
context 'when artifacts are stored remotely' do context 'when artifacts are stored remotely' do
let(:job) { create(:ci_build, :artifacts, :remote_store, pipeline: pipeline) } let(:job) { create(:ci_build, pipeline: pipeline) }
let!(:artifact) { create(:ci_job_artifact, :remote_store, job: job) }
before do
job.reload
get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user)
end
it 'returns location redirect' do it 'returns location redirect' do
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(302)
...@@ -328,6 +338,8 @@ describe API::Jobs do ...@@ -328,6 +338,8 @@ describe API::Jobs do
end end
it 'does not return job artifacts if not uploaded' do it 'does not return job artifacts if not uploaded' do
get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
end end
...@@ -440,7 +452,14 @@ describe API::Jobs do ...@@ -440,7 +452,14 @@ describe API::Jobs do
end end
context 'when artifacts are stored remotely' do context 'when artifacts are stored remotely' do
let(:job) { create(:ci_build, :artifacts, :remote_store, pipeline: pipeline, user: api_user) } let(:job) { create(:ci_build, pipeline: pipeline, user: api_user) }
let!(:artifact) { create(:ci_job_artifact, :remote_store, job: job) }
before do
job.reload
get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user)
end
it 'returns location redirect' do it 'returns location redirect' do
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(302)
......
...@@ -1134,7 +1134,7 @@ describe API::Runner do ...@@ -1134,7 +1134,7 @@ describe API::Runner do
# by configuring this path we allow to pass file from @tmpdir only # by configuring this path we allow to pass file from @tmpdir only
# but all temporary files are stored in system tmp directory # but all temporary files are stored in system tmp directory
@tmpdir = Dir.mktmpdir @tmpdir = Dir.mktmpdir
allow(ArtifactUploader).to receive(:artifacts_upload_path).and_return(@tmpdir) allow(JobArtifactUploader).to receive(:artifacts_upload_path).and_return(@tmpdir)
end end
after do after do
...@@ -1161,13 +1161,16 @@ describe API::Runner do ...@@ -1161,13 +1161,16 @@ describe API::Runner do
describe 'GET /api/v4/jobs/:id/artifacts' do describe 'GET /api/v4/jobs/:id/artifacts' do
let(:token) { job.token } let(:token) { job.token }
context 'when job has artifacts' do
let(:job) { create(:ci_build) }
let(:store) { JobArtifactUploader::LOCAL_STORE }
before do before do
create(:ci_job_artifact, file_store: store, job: job)
download_artifact download_artifact
end end
context 'when job has artifacts' do
let(:job) { create(:ci_build, :artifacts) }
context 'when using job token' do context 'when using job token' do
context 'when artifacts are stored locally' do context 'when artifacts are stored locally' do
let(:download_headers) do let(:download_headers) do
...@@ -1182,7 +1185,8 @@ describe API::Runner do ...@@ -1182,7 +1185,8 @@ describe API::Runner do
end end
context 'when artifacts are stored remotely' do context 'when artifacts are stored remotely' do
let(:job) { create(:ci_build, :artifacts, :remote_store) } let(:store) { JobArtifactUploader::REMOTE_STORE }
let!(:job) { create(:ci_build) }
it 'download artifacts' do it 'download artifacts' do
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(302)
...@@ -1201,12 +1205,16 @@ describe API::Runner do ...@@ -1201,12 +1205,16 @@ describe API::Runner do
context 'when job does not has artifacts' do context 'when job does not has artifacts' do
it 'responds with not found' do it 'responds with not found' do
download_artifact
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(404)
end end
end end
def download_artifact(params = {}, request_headers = headers) def download_artifact(params = {}, request_headers = headers)
params = params.merge(token: token) params = params.merge(token: token)
job.reload
get api("/jobs/#{job.id}/artifacts"), params, request_headers get api("/jobs/#{job.id}/artifacts"), params, request_headers
end end
end end
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe API::V3::Builds do describe API::V3::Builds do
set(:user) { create(:user) } set(:user) { create(:user) }
let(:api_user) { user } let(:api_user) { user }
let!(:project) { create(:project, :repository, creator: user, public_builds: false) } set(:project) { create(:project, :repository, creator: user, public_builds: false) }
let!(:developer) { create(:project_member, :developer, user: user, project: project) } let!(:developer) { create(:project_member, :developer, user: user, project: project) }
let(:reporter) { create(:project_member, :reporter, project: project) } let(:reporter) { create(:project_member, :reporter, project: project) }
let(:guest) { create(:project_member, :guest, project: project) } let(:guest) { create(:project_member, :guest, project: project) }
...@@ -215,9 +215,12 @@ describe API::V3::Builds do ...@@ -215,9 +215,12 @@ describe API::V3::Builds do
end end
context 'when artifacts are stored remotely' do context 'when artifacts are stored remotely' do
let(:build) { create(:ci_build, :artifacts, :remote_store, pipeline: pipeline) } let(:build) { create(:ci_build, pipeline: pipeline) }
let!(:artifact) { create(:ci_job_artifact, :remote_store, job: build) }
it 'returns location redirect' do it 'returns location redirect' do
get v3_api("/projects/#{project.id}/builds/#{build.id}/artifacts", api_user)
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(302)
end end
end end
...@@ -309,7 +312,14 @@ describe API::V3::Builds do ...@@ -309,7 +312,14 @@ describe API::V3::Builds do
end end
context 'when artifacts are stored remotely' do context 'when artifacts are stored remotely' do
let(:build) { create(:ci_build, :artifacts, :remote_store, pipeline: pipeline) } let(:build) { create(:ci_build, pipeline: pipeline) }
let!(:artifact) { create(:ci_job_artifact, :remote_store, job: build) }
before do
build.reload
get v3_api("/projects/#{project.id}/builds/#{build.id}/artifacts", api_user)
end
it 'returns location redirect' do it 'returns location redirect' do
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(302)
......
...@@ -18,7 +18,7 @@ module StubConfiguration ...@@ -18,7 +18,7 @@ module StubConfiguration
def stub_artifacts_object_storage(**params) def stub_artifacts_object_storage(**params)
stub_object_storage_uploader(config: Gitlab.config.artifacts.object_store, stub_object_storage_uploader(config: Gitlab.config.artifacts.object_store,
uploader: ArtifactUploader, uploader: JobArtifactUploader,
remote_directory: 'artifacts', remote_directory: 'artifacts',
**params) **params)
end end
......
require 'rake_helper' require 'rake_helper'
describe 'gitlab:artifacts namespace rake task' do describe 'gitlab:artifacts namespace rake task' do
before :all do before(:context) do
Rake.application.rake_require 'tasks/gitlab/artifacts' Rake.application.rake_require 'tasks/gitlab/artifacts'
end end
subject { run_rake_task('gitlab:artifacts:migrate') }
context 'legacy artifacts' do
describe 'migrate' do describe 'migrate' do
let(:job) { create(:ci_build, :artifacts, artifacts_file_store: store, artifacts_metadata_store: store) } let(:build) { create(:ci_build, artifacts_file_store: store, artifacts_metadata_store: store) }
subject { run_rake_task('gitlab:artifacts:migrate') } before do
# Mock the legacy way of artifacts
path = Rails.root.join('shared/artifacts',
build.created_at.utc.strftime('%Y_%m'),
build.project_id.to_s,
build.id.to_s)
FileUtils.mkdir_p(path)
FileUtils.copy(
Rails.root.join('spec/fixtures/ci_build_artifacts.zip'),
File.join(path, "ci_build_artifacts.zip"))
FileUtils.copy(
Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'),
File.join(path, "ci_build_artifacts_metadata.gz"))
build.update_columns(
artifacts_file: 'ci_build_artifacts.zip',
artifacts_metadata: 'ci_build_artifacts_metadata.gz')
end
context 'when local storage is used' do context 'when local storage is used' do
let(:store) { ObjectStoreUploader::LOCAL_STORE } let(:store) { ObjectStoreUploader::LOCAL_STORE }
context 'and job does not have file store defined' do context 'and job does not have file store defined' do
before do before do
stub_artifacts_object_storage build.update(artifacts_file_store: nil)
job.update(artifacts_file_store: nil)
end end
it "migrates file to remote storage" do it "migrates file to remote storage" do
stub_artifacts_object_storage
subject subject
expect(job.reload.artifacts_file_store).to eq(ObjectStoreUploader::REMOTE_STORE) expect(build.reload.artifacts_file_store).to eq(ObjectStoreUploader::REMOTE_STORE)
expect(job.reload.artifacts_metadata_store).to eq(ObjectStoreUploader::REMOTE_STORE) expect(build.reload.artifacts_metadata_store).to eq(ObjectStoreUploader::REMOTE_STORE)
end end
end end
context 'and remote storage is defined' do context 'and remote storage is defined' do
before do it "migrates file to remote storage" do
stub_artifacts_object_storage stub_artifacts_object_storage
job
end
it "migrates file to remote storage" do
subject subject
expect(job.reload.artifacts_file_store).to eq(ObjectStoreUploader::REMOTE_STORE) expect(build.reload.artifacts_file_store).to eq(ObjectStoreUploader::REMOTE_STORE)
expect(job.reload.artifacts_metadata_store).to eq(ObjectStoreUploader::REMOTE_STORE) expect(build.reload.artifacts_metadata_store).to eq(ObjectStoreUploader::REMOTE_STORE)
end end
end end
context 'and remote storage is not defined' do context 'and remote storage is not defined' do
before do
job
end
it "fails to migrate to remote storage" do it "fails to migrate to remote storage" do
subject subject
expect(job.reload.artifacts_file_store).to eq(ObjectStoreUploader::LOCAL_STORE) expect(build.reload.artifacts_file_store).to eq(ObjectStoreUploader::LOCAL_STORE)
expect(job.reload.artifacts_metadata_store).to eq(ObjectStoreUploader::LOCAL_STORE) expect(build.reload.artifacts_metadata_store).to eq(ObjectStoreUploader::LOCAL_STORE)
end end
end end
end end
...@@ -58,16 +74,66 @@ describe 'gitlab:artifacts namespace rake task' do ...@@ -58,16 +74,66 @@ describe 'gitlab:artifacts namespace rake task' do
context 'when remote storage is used' do context 'when remote storage is used' do
let(:store) { ObjectStoreUploader::REMOTE_STORE } let(:store) { ObjectStoreUploader::REMOTE_STORE }
it "file stays on remote storage" do
stub_artifacts_object_storage
subject
expect(build.reload.artifacts_file_store).to eq(ObjectStoreUploader::REMOTE_STORE)
expect(build.reload.artifacts_metadata_store).to eq(ObjectStoreUploader::REMOTE_STORE)
end
end
end
end
context 'job artifacts' do
let(:artifact) { create(:ci_job_artifact, file_store: store) }
context 'when local storage is used' do
let(:store) { ObjectStoreUploader::LOCAL_STORE }
context 'and job does not have file store defined' do
before do before do
artifact.update(file_store: nil)
end
it "migrates file to remote storage" do
stub_artifacts_object_storage stub_artifacts_object_storage
job
subject
expect(artifact.reload.file_store).to eq(ObjectStoreUploader::REMOTE_STORE)
end
end end
context 'and remote storage is defined' do
it "migrates file to remote storage" do
stub_artifacts_object_storage
subject
expect(artifact.reload.file_store).to eq(ObjectStoreUploader::REMOTE_STORE)
end
end
context 'and remote storage is not defined' do
it "fails to migrate to remote storage" do
subject
expect(artifact.reload.file_store).to eq(ObjectStoreUploader::LOCAL_STORE)
end
end
end
context 'when remote storage is used' do
let(:store) { ObjectStoreUploader::REMOTE_STORE }
it "file stays on remote storage" do it "file stays on remote storage" do
stub_artifacts_object_storage
subject subject
expect(job.reload.artifacts_file_store).to eq(ObjectStoreUploader::REMOTE_STORE) expect(artifact.reload.file_store).to eq(ObjectStoreUploader::REMOTE_STORE)
expect(job.reload.artifacts_metadata_store).to eq(ObjectStoreUploader::REMOTE_STORE)
end end
end end
end end
......
...@@ -4,18 +4,18 @@ require 'carrierwave/storage/fog' ...@@ -4,18 +4,18 @@ require 'carrierwave/storage/fog'
describe ObjectStoreUploader do describe ObjectStoreUploader do
let(:uploader_class) { Class.new(described_class) } let(:uploader_class) { Class.new(described_class) }
let(:object) { double } let(:object) { double }
let(:uploader) { uploader_class.new(object, :artifacts_file) } let(:uploader) { uploader_class.new(object, :file) }
describe '#object_store' do describe '#object_store' do
it "calls artifacts_file_store on object" do it "calls artifacts_file_store on object" do
expect(object).to receive(:artifacts_file_store) expect(object).to receive(:file_store)
uploader.object_store uploader.object_store
end end
context 'when store is null' do context 'when store is null' do
before do before do
expect(object).to receive(:artifacts_file_store).twice.and_return(nil) expect(object).to receive(:file_store).twice.and_return(nil)
end end
it "returns LOCAL_STORE" do it "returns LOCAL_STORE" do
...@@ -26,7 +26,7 @@ describe ObjectStoreUploader do ...@@ -26,7 +26,7 @@ describe ObjectStoreUploader do
context 'when value is set' do context 'when value is set' do
before do before do
expect(object).to receive(:artifacts_file_store).twice.and_return(described_class::REMOTE_STORE) expect(object).to receive(:file_store).twice.and_return(described_class::REMOTE_STORE)
end end
it "returns given value" do it "returns given value" do
...@@ -38,7 +38,7 @@ describe ObjectStoreUploader do ...@@ -38,7 +38,7 @@ describe ObjectStoreUploader do
describe '#object_store=' do describe '#object_store=' do
it "calls artifacts_file_store= on object" do it "calls artifacts_file_store= on object" do
expect(object).to receive(:artifacts_file_store=).with(described_class::REMOTE_STORE) expect(object).to receive(:file_store=).with(described_class::REMOTE_STORE)
uploader.object_store = described_class::REMOTE_STORE uploader.object_store = described_class::REMOTE_STORE
end end
...@@ -47,7 +47,7 @@ describe ObjectStoreUploader do ...@@ -47,7 +47,7 @@ describe ObjectStoreUploader do
describe '#file_storage?' do describe '#file_storage?' do
context 'when file storage is used' do context 'when file storage is used' do
before do before do
expect(object).to receive(:artifacts_file_store).and_return(described_class::LOCAL_STORE) expect(object).to receive(:file_store).and_return(described_class::LOCAL_STORE)
end end
it { expect(uploader).to be_file_storage } it { expect(uploader).to be_file_storage }
...@@ -57,7 +57,7 @@ describe ObjectStoreUploader do ...@@ -57,7 +57,7 @@ describe ObjectStoreUploader do
before do before do
uploader_class.storage_options double( uploader_class.storage_options double(
object_store: double(enabled: true)) object_store: double(enabled: true))
expect(object).to receive(:artifacts_file_store).and_return(described_class::REMOTE_STORE) expect(object).to receive(:file_store).and_return(described_class::REMOTE_STORE)
end end
it { expect(uploader).not_to be_file_storage } it { expect(uploader).not_to be_file_storage }
...@@ -82,9 +82,9 @@ describe ObjectStoreUploader do ...@@ -82,9 +82,9 @@ describe ObjectStoreUploader do
end end
end end
context 'when using ArtifactsUploader' do context 'when using JobArtifactsUploader' do
let(:job) { create(:ci_build, :artifacts, artifacts_file_store: store) } let(:artifact) { create(:ci_job_artifact, file_store: store) }
let(:uploader) { job.artifacts_file } let(:uploader) { artifact.file }
context 'checking described_class' do context 'checking described_class' do
let(:store) { described_class::LOCAL_STORE } let(:store) { described_class::LOCAL_STORE }
...@@ -103,7 +103,7 @@ describe ObjectStoreUploader do ...@@ -103,7 +103,7 @@ describe ObjectStoreUploader do
let(:store) { nil } let(:store) { nil }
it "sets the store to LOCAL_STORE" do it "sets the store to LOCAL_STORE" do
expect(job.artifacts_file_store).to eq(described_class::LOCAL_STORE) expect(artifact.file_store).to eq(described_class::LOCAL_STORE)
end end
end end
...@@ -130,8 +130,8 @@ describe ObjectStoreUploader do ...@@ -130,8 +130,8 @@ describe ObjectStoreUploader do
end end
describe '#migrate!' do describe '#migrate!' do
let(:job) { create(:ci_build, :artifacts, artifacts_file_store: store) } let(:artifact) { create(:ci_job_artifact, file_store: store) }
let(:uploader) { job.artifacts_file } let(:uploader) { artifact.file }
let(:store) { described_class::LOCAL_STORE } let(:store) { described_class::LOCAL_STORE }
subject { uploader.migrate!(new_store) } subject { uploader.migrate!(new_store) }
...@@ -214,7 +214,7 @@ describe ObjectStoreUploader do ...@@ -214,7 +214,7 @@ describe ObjectStoreUploader do
context 'when subject save fails' do context 'when subject save fails' do
before do before do
expect(job).to receive(:save!).and_raise(RuntimeError, "exception") expect(artifact).to receive(:save!).and_raise(RuntimeError, "exception")
end end
it "does catch an error" do it "does catch an error" do
...@@ -272,7 +272,7 @@ describe ObjectStoreUploader do ...@@ -272,7 +272,7 @@ describe ObjectStoreUploader do
context 'when using local storage' do context 'when using local storage' do
before do before do
expect(object).to receive(:artifacts_file_store) { described_class::LOCAL_STORE } expect(object).to receive(:file_store) { described_class::LOCAL_STORE }
end end
it "does not raise an error" do it "does not raise an error" do
...@@ -284,7 +284,7 @@ describe ObjectStoreUploader do ...@@ -284,7 +284,7 @@ describe ObjectStoreUploader do
before do before do
uploader_class.storage_options double( uploader_class.storage_options double(
object_store: double(enabled: true)) object_store: double(enabled: true))
expect(object).to receive(:artifacts_file_store) { described_class::REMOTE_STORE } expect(object).to receive(:file_store) { described_class::REMOTE_STORE }
end end
context 'feature is not available' do context 'feature is not available' do
......
...@@ -48,12 +48,33 @@ describe ObjectStorageUploadWorker do ...@@ -48,12 +48,33 @@ describe ObjectStorageUploadWorker do
end end
end end
context 'for artifacts' do context 'for legacy artifacts' do
let(:job) { create(:ci_build, :artifacts, artifacts_file_store: store, artifacts_metadata_store: store) } let(:build) { create(:ci_build) }
let(:uploader_class) { ArtifactUploader } let(:uploader_class) { ArtifactUploader }
let(:subject_class) { Ci::Build } let(:subject_class) { Ci::Build }
let(:file_field) { :artifacts_file } let(:file_field) { :artifacts_file }
let(:subject_id) { job.id } let(:subject_id) { build.id }
before do
# Mock the legacy way of artifacts
path = Rails.root.join('shared/artifacts',
build.created_at.utc.strftime('%Y_%m'),
build.project_id.to_s,
build.id.to_s)
FileUtils.mkdir_p(path)
FileUtils.copy(
Rails.root.join('spec/fixtures/ci_build_artifacts.zip'),
File.join(path, "ci_build_artifacts.zip"))
FileUtils.copy(
Rails.root.join('spec/fixtures/ci_build_artifacts_metadata.gz'),
File.join(path, "ci_build_artifacts_metadata.gz"))
build.update_columns(
artifacts_file: 'ci_build_artifacts.zip',
artifacts_metadata: 'ci_build_artifacts_metadata.gz')
end
context 'when local storage is used' do context 'when local storage is used' do
let(:store) { local } let(:store) { local }
...@@ -61,13 +82,12 @@ describe ObjectStorageUploadWorker do ...@@ -61,13 +82,12 @@ describe ObjectStorageUploadWorker do
context 'and remote storage is defined' do context 'and remote storage is defined' do
before do before do
stub_artifacts_object_storage stub_artifacts_object_storage
job
end end
it "migrates file to remote storage" do it "migrates file to remote storage" do
perform perform
expect(job.reload.artifacts_file_store).to eq(remote) expect(build.reload.artifacts_file_store).to eq(remote)
end end
context 'for artifacts_metadata' do context 'for artifacts_metadata' do
...@@ -76,8 +96,32 @@ describe ObjectStorageUploadWorker do ...@@ -76,8 +96,32 @@ describe ObjectStorageUploadWorker do
it 'migrates metadata to remote storage' do it 'migrates metadata to remote storage' do
perform perform
expect(job.reload.artifacts_metadata_store).to eq(remote) expect(build.reload.artifacts_metadata_store).to eq(remote)
end
end
end
end
end
context 'for job artifacts' do
let(:artifact) { create(:ci_job_artifact) }
let(:uploader_class) { JobArtifactUploader }
let(:subject_class) { Ci::JobArtifact }
let(:file_field) { :file }
let(:subject_id) { artifact.id }
context 'when local storage is used' do
let(:store) { local }
context 'and remote storage is defined' do
before do
stub_artifacts_object_storage
end end
it "migrates file to remote storage" do
perform
expect(artifact.reload.file_store).to eq(remote)
end end
end 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