From 6cd5b7dbfaa4ff630ecbbfe351a1faac5fc71a8d Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 19 Sep 2019 11:50:12 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/lib/container_registry/client_spec.rb | 65 ++++++++++++++++++++++++++++++ spec/lib/container_registry/tag_spec.rb | 4 +- 2 files changed, 67 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/container_registry/client_spec.rb b/spec/lib/container_registry/client_spec.rb index 6c2b338bfcd..3782c30e88a 100644 --- a/spec/lib/container_registry/client_spec.rb +++ b/spec/lib/container_registry/client_spec.rb @@ -73,4 +73,69 @@ describe ContainerRegistry::Client do expect(response).to eq('Successfully redirected') end end + + def stub_upload(path, content, digest, status = 200) + stub_request(:post, "http://container-registry/v2/#{path}/blobs/uploads/") + .to_return(status: status, body: "", headers: { 'location' => 'http://container-registry/next_upload?id=someid' }) + + stub_request(:put, "http://container-registry/next_upload?digest=#{digest}&id=someid") + .with(body: content) + .to_return(status: status, body: "", headers: {}) + end + + describe '#upload_blob' do + subject { client.upload_blob('path', 'content', 'sha256:123') } + + context 'with successful uploads' do + it 'starts the upload and posts the blob' do + stub_upload('path', 'content', 'sha256:123') + + expect(subject).to be_success + end + end + + context 'with a failed upload' do + before do + stub_upload('path', 'content', 'sha256:123', 400) + end + + it 'returns nil' do + expect(subject).to be nil + end + end + end + + describe '#generate_empty_manifest' do + subject { client.generate_empty_manifest('path') } + + let(:result_manifest) do + { + schemaVersion: 2, + mediaType: 'application/vnd.docker.distribution.manifest.v2+json', + config: { + mediaType: 'application/vnd.docker.container.image.v1+json', + size: 21, + digest: 'sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3' + } + } + end + + it 'uploads a random image and returns the manifest' do + stub_upload('path', "{\n \"config\": {\n }\n}", 'sha256:4435000728ee66e6a80e55637fc22725c256b61de344a2ecdeaac6bdb36e8bc3') + + expect(subject).to eq(result_manifest) + end + end + + describe '#put_tag' do + subject { client.put_tag('path', 'tagA', { foo: :bar }) } + + it 'uploads the manifest and returns the digest' do + stub_request(:put, "http://container-registry/v2/path/manifests/tagA") + .with(body: "{\n \"foo\": \"bar\"\n}") + .to_return(status: 200, body: "", headers: { 'docker-content-digest' => 'sha256:123' }) + + expect(subject).to eq 'sha256:123' + end + end end diff --git a/spec/lib/container_registry/tag_spec.rb b/spec/lib/container_registry/tag_spec.rb index 110f006536b..3115dfe852f 100644 --- a/spec/lib/container_registry/tag_spec.rb +++ b/spec/lib/container_registry/tag_spec.rb @@ -179,7 +179,7 @@ describe ContainerRegistry::Tag do end end - describe '#delete' do + describe '#unsafe_delete' do before do stub_request(:delete, 'http://registry.gitlab/v2/group/test/manifests/sha256:digest') .with(headers: headers) @@ -187,7 +187,7 @@ describe ContainerRegistry::Tag do end it 'correctly deletes the tag' do - expect(tag.delete).to be_truthy + expect(tag.unsafe_delete).to be_truthy end end end -- cgit v1.2.1