diff options
Diffstat (limited to 'spec/services/dependency_proxy/pull_manifest_service_spec.rb')
-rw-r--r-- | spec/services/dependency_proxy/pull_manifest_service_spec.rb | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/spec/services/dependency_proxy/pull_manifest_service_spec.rb b/spec/services/dependency_proxy/pull_manifest_service_spec.rb index 030ed9c001b..b760839d1fb 100644 --- a/spec/services/dependency_proxy/pull_manifest_service_spec.rb +++ b/spec/services/dependency_proxy/pull_manifest_service_spec.rb @@ -8,26 +8,43 @@ RSpec.describe DependencyProxy::PullManifestService do let(:tag) { '3.9' } let(:token) { Digest::SHA256.hexdigest('123') } let(:manifest) { { foo: 'bar' }.to_json } + let(:digest) { '12345' } + let(:headers) { { 'docker-content-digest' => digest } } - subject { described_class.new(image, tag, token).execute } + subject { described_class.new(image, tag, token).execute_with_manifest(&method(:check_response)) } context 'remote request is successful' do before do - stub_manifest_download(image, tag) + stub_manifest_download(image, tag, headers: headers) end - it { expect(subject[:status]).to eq(:success) } - it { expect(subject[:manifest]).to eq(manifest) } + it 'successfully returns the manifest' do + def check_response(response) + response[:file].rewind + + expect(response[:status]).to eq(:success) + expect(response[:file].read).to eq(manifest) + expect(response[:digest]).to eq(digest) + end + + subject + end end context 'remote request is not found' do before do - stub_manifest_download(image, tag, 404, 'Not found') + stub_manifest_download(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') } + it 'returns a 404 not found error' do + def check_response(response) + expect(response[:status]).to eq(:error) + expect(response[:http_status]).to eq(404) + expect(response[:message]).to eq('Not found') + end + + subject + end end context 'net timeout exception' do @@ -37,8 +54,20 @@ RSpec.describe DependencyProxy::PullManifestService do stub_full_request(manifest_link).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') } + it 'returns a 599 error' do + def check_response(response) + expect(response[:status]).to eq(:error) + expect(response[:http_status]).to eq(599) + expect(response[:message]).to eq('execution expired') + end + + subject + end + end + + context 'no block is given' do + subject { described_class.new(image, tag, token).execute_with_manifest } + + it { expect { subject }.to raise_error(ArgumentError, 'Block must be provided') } end end |