BigW Consortium Gitlab

artifact_blob_spec.rb 2.41 KB
Newer Older
1 2
require 'spec_helper'

3
describe Ci::ArtifactBlob do
4 5
  set(:project) { create(:project, :public) }
  set(:build) { create(:ci_build, :artifacts, project: project) }
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  let(:entry) { build.artifacts_metadata_entry('other_artifacts_0.1.2/another-subdirectory/banana_sample.gif') }

  subject { described_class.new(entry) }

  describe '#id' do
    it 'returns a hash of the path' do
      expect(subject.id).to eq(Digest::SHA1.hexdigest(entry.path))
    end
  end

  describe '#name' do
    it 'returns the entry name' do
      expect(subject.name).to eq(entry.name)
    end
  end

  describe '#path' do
    it 'returns the entry path' do
      expect(subject.path).to eq(entry.path)
    end
  end

  describe '#size' do
    it 'returns the entry size' do
      expect(subject.size).to eq(entry.metadata[:size])
    end
  end

  describe '#mode' do
    it 'returns the entry mode' do
      expect(subject.mode).to eq(entry.metadata[:mode])
    end
  end

  describe '#external_storage' do
    it 'returns :build_artifact' do
      expect(subject.external_storage).to eq(:build_artifact)
    end
  end
45

46
  describe '#external_url' do
47 48 49 50 51 52 53 54 55 56 57 58
    before do
      allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
      allow(Gitlab.config.pages).to receive(:artifacts_server).and_return(true)
    end

    context '.gif extension' do
      it 'returns nil' do
        expect(subject.external_url(build.project, build)).to be_nil
      end
    end

    context 'txt extensions' do
59 60
      let(:path) { 'other_artifacts_0.1.2/doc_sample.txt' }
      let(:entry) { build.artifacts_metadata_entry(path) }
61 62 63 64 65

      it 'returns a URL' do
        url = subject.external_url(build.project, build)

        expect(url).not_to be_nil
66
        expect(url).to eq("http://#{project.namespace.path}.#{Gitlab.config.pages.host}/-/#{project.path}/-/jobs/#{build.id}/artifacts/#{path}")
67 68 69 70 71 72 73 74 75 76
      end
    end
  end

  describe '#external_link?' do
    before do
      allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
      allow(Gitlab.config.pages).to receive(:artifacts_server).and_return(true)
    end

77 78 79 80 81
    context 'gif extensions' do
      it 'returns false' do
        expect(subject.external_link?(build)).to be false
      end
    end
82 83 84 85

    context 'txt extensions' do
      let(:entry) { build.artifacts_metadata_entry('other_artifacts_0.1.2/doc_sample.txt') }

86 87 88
      it 'returns true' do
        expect(subject.external_link?(build)).to be true
      end
89 90
    end
  end
91
end