diff options
Diffstat (limited to 'spec/services/dependency_proxy/find_or_create_blob_service_spec.rb')
-rw-r--r-- | spec/services/dependency_proxy/find_or_create_blob_service_spec.rb | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/spec/services/dependency_proxy/find_or_create_blob_service_spec.rb b/spec/services/dependency_proxy/find_or_create_blob_service_spec.rb index 3fac749be29..20b0546effa 100644 --- a/spec/services/dependency_proxy/find_or_create_blob_service_spec.rb +++ b/spec/services/dependency_proxy/find_or_create_blob_service_spec.rb @@ -4,7 +4,8 @@ require 'spec_helper' RSpec.describe DependencyProxy::FindOrCreateBlobService do include DependencyProxyHelpers - let(:blob) { create(:dependency_proxy_blob) } + let_it_be_with_reload(:blob) { create(:dependency_proxy_blob) } + let(:group) { blob.group } let(:image) { 'alpine' } let(:tag) { '3.9' } @@ -17,11 +18,7 @@ RSpec.describe DependencyProxy::FindOrCreateBlobService do stub_registry_auth(image, token) end - context 'no cache' do - before do - stub_blob_download(image, blob_sha) - end - + shared_examples 'downloads the remote blob' do it 'downloads blob from remote registry if there is no cached one' do expect(subject[:status]).to eq(:success) expect(subject[:blob]).to be_a(DependencyProxy::Blob) @@ -30,15 +27,34 @@ RSpec.describe DependencyProxy::FindOrCreateBlobService do end end + context 'no cache' do + before do + stub_blob_download(image, blob_sha) + end + + it_behaves_like 'downloads the remote blob' + end + context 'cached blob' do let(:blob_sha) { blob.file_name.sub('.gz', '') } it 'uses cached blob instead of downloading one' do + expect { subject }.to change { blob.reload.updated_at } + expect(subject[:status]).to eq(:success) expect(subject[:blob]).to be_a(DependencyProxy::Blob) expect(subject[:blob]).to eq(blob) expect(subject[:from_cache]).to eq true end + + context 'when the cached blob is expired' do + before do + blob.update_column(:status, DependencyProxy::Blob.statuses[:expired]) + stub_blob_download(image, blob_sha) + end + + it_behaves_like 'downloads the remote blob' + end end context 'no such blob exists remotely' do |