summaryrefslogtreecommitdiff
path: root/spec/support/shared_contexts/lib/container_registry/client_stubs_shared_context.rb
blob: d857e683aa2c583e0805fa9e05dd5f22952855c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

RSpec.shared_context 'container registry client stubs' do
  def stub_container_registry_gitlab_api_support(supported: true)
    allow_next_instance_of(ContainerRegistry::GitlabApiClient) do |client|
      allow(client).to receive(:supports_gitlab_api?).and_return(supported)
      yield client if block_given?
    end
  end

  def stub_container_registry_gitlab_api_repository_details(client, path:, size_bytes:)
    allow(client).to receive(:repository_details).with(path, with_size: true).and_return('size_bytes' => size_bytes)
  end

  def stub_container_registry_gitlab_api_network_error(client_method: :supports_gitlab_api?)
    allow_next_instance_of(ContainerRegistry::GitlabApiClient) do |client|
      allow(client).to receive(client_method).and_raise(::Faraday::Error, nil, nil)
    end
  end
end