debian-mirror-gitlab/spec/services/dependency_proxy/head_manifest_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe DependencyProxy::HeadManifestService, feature_category: :dependency_proxy do
2021-02-22 17:27:13 +05:30
include DependencyProxyHelpers
let(:image) { 'alpine' }
let(:tag) { 'latest' }
let(:token) { Digest::SHA256.hexdigest('123') }
let(:digest) { '12345' }
2021-04-17 20:07:23 +05:30
let(:content_type) { 'foo' }
let(:headers) do
{
2021-12-11 22:18:48 +05:30
DependencyProxy::Manifest::DIGEST_HEADER => digest,
2021-04-17 20:07:23 +05:30
'content-type' => content_type
}
end
2021-02-22 17:27:13 +05:30
subject { described_class.new(image, tag, token).execute }
context 'remote request is successful' do
before do
2021-04-17 20:07:23 +05:30
stub_manifest_head(image, tag, headers: headers)
2021-02-22 17:27:13 +05:30
end
it { expect(subject[:status]).to eq(:success) }
it { expect(subject[:digest]).to eq(digest) }
end
context 'remote request is not found' do
before do
stub_manifest_head(image, tag, status: 404, body: 'Not found')
end
it { expect(subject[:status]).to eq(:error) }
it { expect(subject[:http_status]).to eq(404) }
it { expect(subject[:message]).to eq('Not found') }
end
context 'net timeout exception' do
before do
manifest_link = DependencyProxy::Registry.manifest_url(image, tag)
stub_full_request(manifest_link, method: :head).to_timeout
end
it { expect(subject[:status]).to eq(:error) }
it { expect(subject[:http_status]).to eq(599) }
it { expect(subject[:message]).to eq('execution expired') }
end
end