legacy_artifact_uploader_spec.rb 1.74 KB
Newer Older
Kamil Trzcinski's avatar
Kamil Trzcinski committed
1 2
require 'rails_helper'

3
describe LegacyArtifactUploader do
4
  let(:store) { described_class::Store::LOCAL }
5
  let(:job) { create(:ci_build, artifacts_file_store: store) }
6
  let(:uploader) { described_class.new(job, :legacy_artifacts_file) }
7
  let(:local_path) { described_class.root }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
8

9
  subject { uploader }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
10

11 12 13
  # TODO: move to Workhorse::UploadPath
  describe '.workhorse_upload_path' do
    subject { described_class.workhorse_upload_path }
14

15
    it { is_expected.to start_with(local_path) }
16
    it { is_expected.to end_with('tmp/uploads') }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
17 18
  end

19 20 21 22
  it_behaves_like "builds correct paths",
                  store_dir: %r[\d{4}_\d{1,2}/\d+/\d+\z],
                  cache_dir: %r[artifacts/tmp/cache],
                  work_dir: %r[artifacts/tmp/work]
23

24 25 26
  context 'object store is remote' do
    before do
      stub_artifacts_object_storage
27
    end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
28

29
    include_context 'with storage', described_class::Store::REMOTE
30

31 32
    it_behaves_like "builds correct paths",
                    store_dir: %r[\d{4}_\d{1,2}/\d+/\d+\z]
Kamil Trzcinski's avatar
Kamil Trzcinski committed
33
  end
34 35 36 37 38 39 40 41 42 43

  describe '#filename' do
    # we need to use uploader, as this makes to use mounter
    # which initialises uploader.file object
    let(:uploader) { job.artifacts_file }

    subject { uploader.filename }

    it { is_expected.to be_nil }
  end
44 45 46

  context 'file is stored in valid path' do
    let(:file) do
47
      fixture_file_upload('spec/fixtures/ci_build_artifacts.zip', 'application/zip')
48 49 50 51 52 53 54 55
    end

    before do
      uploader.store!(file)
    end

    subject { uploader.file.path }

56
    it { is_expected.to start_with("#{uploader.root}") }
57
    it { is_expected.to include("/#{job.created_at.utc.strftime('%Y_%m')}/") }
Kamil Trzcinski's avatar
Kamil Trzcinski committed
58
    it { is_expected.to include("/#{job.project_id}/") }
59 60
    it { is_expected.to end_with("ci_build_artifacts.zip") }
  end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
61
end