diff options
Diffstat (limited to 'spec/services/dependency_proxy/find_or_create_manifest_service_spec.rb')
-rw-r--r-- | spec/services/dependency_proxy/find_or_create_manifest_service_spec.rb | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/spec/services/dependency_proxy/find_or_create_manifest_service_spec.rb b/spec/services/dependency_proxy/find_or_create_manifest_service_spec.rb index b3f88f91289..ef608c9b113 100644 --- a/spec/services/dependency_proxy/find_or_create_manifest_service_spec.rb +++ b/spec/services/dependency_proxy/find_or_create_manifest_service_spec.rb @@ -13,7 +13,7 @@ RSpec.describe DependencyProxy::FindOrCreateManifestService do let(:token) { Digest::SHA256.hexdigest('123') } let(:headers) do { - 'docker-content-digest' => dependency_proxy_manifest.digest, + DependencyProxy::Manifest::DIGEST_HEADER => dependency_proxy_manifest.digest, 'content-type' => dependency_proxy_manifest.content_type } end @@ -31,6 +31,14 @@ RSpec.describe DependencyProxy::FindOrCreateManifestService do end end + shared_examples 'returning no manifest' do + it 'returns a nil manifest' do + expect(subject[:status]).to eq(:success) + expect(subject[:from_cache]).to eq false + expect(subject[:manifest]).to be_nil + end + end + context 'when no manifest exists' do let_it_be(:image) { 'new-image' } @@ -40,7 +48,15 @@ RSpec.describe DependencyProxy::FindOrCreateManifestService do stub_manifest_download(image, tag, headers: headers) end - it_behaves_like 'downloading the manifest' + it_behaves_like 'returning no manifest' + + context 'with dependency_proxy_manifest_workhorse feature disabled' do + before do + stub_feature_flags(dependency_proxy_manifest_workhorse: false) + end + + it_behaves_like 'downloading the manifest' + end end context 'failed head request' do @@ -49,7 +65,15 @@ RSpec.describe DependencyProxy::FindOrCreateManifestService do stub_manifest_download(image, tag, headers: headers) end - it_behaves_like 'downloading the manifest' + it_behaves_like 'returning no manifest' + + context 'with dependency_proxy_manifest_workhorse feature disabled' do + before do + stub_feature_flags(dependency_proxy_manifest_workhorse: false) + end + + it_behaves_like 'downloading the manifest' + end end end @@ -60,7 +84,7 @@ RSpec.describe DependencyProxy::FindOrCreateManifestService do shared_examples 'using the cached manifest' do it 'uses cached manifest instead of downloading one', :aggregate_failures do - expect { subject }.to change { dependency_proxy_manifest.reload.updated_at } + expect { subject }.to change { dependency_proxy_manifest.reload.read_at } expect(subject[:status]).to eq(:success) expect(subject[:manifest]).to be_a(DependencyProxy::Manifest) @@ -76,16 +100,24 @@ RSpec.describe DependencyProxy::FindOrCreateManifestService do let(:content_type) { 'new-content-type' } before do - stub_manifest_head(image, tag, headers: { 'docker-content-digest' => digest, 'content-type' => content_type }) - stub_manifest_download(image, tag, headers: { 'docker-content-digest' => digest, 'content-type' => content_type }) + stub_manifest_head(image, tag, headers: { DependencyProxy::Manifest::DIGEST_HEADER => digest, 'content-type' => content_type }) + stub_manifest_download(image, tag, headers: { DependencyProxy::Manifest::DIGEST_HEADER => digest, 'content-type' => content_type }) end - it 'downloads the new manifest and updates the existing record', :aggregate_failures do - expect(subject[:status]).to eq(:success) - expect(subject[:manifest]).to eq(dependency_proxy_manifest) - expect(subject[:manifest].content_type).to eq(content_type) - expect(subject[:manifest].digest).to eq(digest) - expect(subject[:from_cache]).to eq false + it_behaves_like 'returning no manifest' + + context 'with dependency_proxy_manifest_workhorse feature disabled' do + before do + stub_feature_flags(dependency_proxy_manifest_workhorse: false) + end + + it 'downloads the new manifest and updates the existing record', :aggregate_failures do + expect(subject[:status]).to eq(:success) + expect(subject[:manifest]).to eq(dependency_proxy_manifest) + expect(subject[:manifest].content_type).to eq(content_type) + expect(subject[:manifest].digest).to eq(digest) + expect(subject[:from_cache]).to eq false + end end end @@ -96,7 +128,15 @@ RSpec.describe DependencyProxy::FindOrCreateManifestService do stub_manifest_download(image, tag, headers: headers) end - it_behaves_like 'downloading the manifest' + it_behaves_like 'returning no manifest' + + context 'with dependency_proxy_manifest_workhorse feature disabled' do + before do + stub_feature_flags(dependency_proxy_manifest_workhorse: false) + end + + it_behaves_like 'downloading the manifest' + end end context 'failed connection' do |