2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-02 18:42:37 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Ci::ArtifactBlob do
|
2020-02-05 07:09:15 -05:00
|
|
|
let_it_be(:project) { create(:project, :public) }
|
|
|
|
let_it_be(:build) { create(:ci_build, :artifacts, project: project) }
|
2021-04-06 14:09:02 -04:00
|
|
|
|
2017-05-02 18:42:37 -04:00
|
|
|
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
|
2017-10-03 06:34:24 -04:00
|
|
|
|
2017-10-04 15:01:27 -04:00
|
|
|
describe '#external_url' do
|
2017-10-03 06:34:24 -04:00
|
|
|
before do
|
|
|
|
allow(Gitlab.config.pages).to receive(:enabled).and_return(true)
|
|
|
|
allow(Gitlab.config.pages).to receive(:artifacts_server).and_return(true)
|
|
|
|
end
|
|
|
|
|
2020-02-06 16:08:48 -05:00
|
|
|
describe '.gif extension' do
|
2017-10-03 06:34:24 -04:00
|
|
|
it 'returns nil' do
|
|
|
|
expect(subject.external_url(build.project, build)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'txt extensions' do
|
2017-10-20 18:38:15 -04:00
|
|
|
let(:path) { 'other_artifacts_0.1.2/doc_sample.txt' }
|
|
|
|
let(:entry) { build.artifacts_metadata_entry(path) }
|
2017-10-03 06:34:24 -04:00
|
|
|
|
|
|
|
it 'returns a URL' do
|
|
|
|
url = subject.external_url(build.project, build)
|
|
|
|
|
|
|
|
expect(url).not_to be_nil
|
2017-10-20 18:38:15 -04:00
|
|
|
expect(url).to eq("http://#{project.namespace.path}.#{Gitlab.config.pages.host}/-/#{project.path}/-/jobs/#{build.id}/artifacts/#{path}")
|
2017-10-03 06:34:24 -04:00
|
|
|
end
|
2018-03-29 05:24:08 -04:00
|
|
|
|
|
|
|
context 'when port is configured' do
|
|
|
|
let(:port) { 1234 }
|
|
|
|
|
|
|
|
it 'returns an URL with port number' do
|
|
|
|
allow(Gitlab.config.pages).to receive(:url).and_return("#{Gitlab.config.pages.url}:#{port}")
|
|
|
|
|
|
|
|
url = subject.external_url(build.project, build)
|
|
|
|
|
|
|
|
expect(url).not_to be_nil
|
|
|
|
expect(url).to eq("http://#{project.namespace.path}.#{Gitlab.config.pages.host}:#{port}/-/#{project.path}/-/jobs/#{build.id}/artifacts/#{path}")
|
|
|
|
end
|
|
|
|
end
|
2017-10-03 06:34:24 -04:00
|
|
|
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
|
|
|
|
|
2017-10-05 09:14:44 -04:00
|
|
|
context 'gif extensions' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject.external_link?(build)).to be false
|
|
|
|
end
|
|
|
|
end
|
2017-10-03 06:34:24 -04:00
|
|
|
|
|
|
|
context 'txt extensions' do
|
|
|
|
let(:entry) { build.artifacts_metadata_entry('other_artifacts_0.1.2/doc_sample.txt') }
|
|
|
|
|
2017-10-05 09:14:44 -04:00
|
|
|
it 'returns true' do
|
|
|
|
expect(subject.external_link?(build)).to be true
|
|
|
|
end
|
2017-10-03 06:34:24 -04:00
|
|
|
end
|
|
|
|
end
|
2017-05-02 18:42:37 -04:00
|
|
|
end
|