From 045d07bab37df2020f650f7354157f5267f57c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Thu, 10 Jan 2019 15:22:58 +0100 Subject: Add Container Registry API This includes a set of APIs to manipulate container registry. This includes also an ability to delete tags based on requested criteria, like keep-last-n, matching-name, older-than. --- spec/support/helpers/stub_gitlab_calls.rb | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'spec/support/helpers/stub_gitlab_calls.rb') diff --git a/spec/support/helpers/stub_gitlab_calls.rb b/spec/support/helpers/stub_gitlab_calls.rb index 2933f2c78dc..370d20df444 100644 --- a/spec/support/helpers/stub_gitlab_calls.rb +++ b/spec/support/helpers/stub_gitlab_calls.rb @@ -36,31 +36,41 @@ module StubGitlabCalls .to receive(:full_access_token).and_return('token') end - def stub_container_registry_tags(repository: :any, tags:) + def stub_container_registry_tags(repository: :any, tags: [], with_manifest: false) repository = any_args if repository == :any allow_any_instance_of(ContainerRegistry::Client) .to receive(:repository_tags).with(repository) .and_return({ 'tags' => tags }) - allow_any_instance_of(ContainerRegistry::Client) - .to receive(:repository_manifest).with(repository, anything) - .and_return(stub_container_registry_tag_manifest) + if with_manifest + tags.each do |tag| + allow_any_instance_of(ContainerRegistry::Client) + .to receive(:repository_tag_digest) + .with(repository, tag) + .and_return('sha256:4c8e63ca4cb663ce6c688cb06f1c3' \ + '72b088dac5b6d7ad7d49cd620d85cf72a15') + end - allow_any_instance_of(ContainerRegistry::Client) - .to receive(:blob).with(repository, anything, 'application/octet-stream') - .and_return(stub_container_registry_blob) + allow_any_instance_of(ContainerRegistry::Client) + .to receive(:repository_manifest).with(repository, anything) + .and_return(stub_container_registry_tag_manifest_content) + + allow_any_instance_of(ContainerRegistry::Client) + .to receive(:blob).with(repository, anything, 'application/octet-stream') + .and_return(stub_container_registry_blob_content) + end end private - def stub_container_registry_tag_manifest + def stub_container_registry_tag_manifest_content fixture_path = 'spec/fixtures/container_registry/tag_manifest.json' JSON.parse(File.read(Rails.root + fixture_path)) end - def stub_container_registry_blob + def stub_container_registry_blob_content fixture_path = 'spec/fixtures/container_registry/config_blob.json' File.read(Rails.root + fixture_path) -- cgit v1.2.1