1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Client do
describe '.builds' do
before do
stub_get('/projects/3/builds', 'builds')
@builds = Gitlab.builds(3)
end
it 'gets the correct resource' do
expect(a_get('/projects/3/builds')).to have_been_made
end
it "returns a paginated response of project's builds" do
expect(@builds).to be_a Gitlab::PaginatedResponse
end
end
describe '.build' do
before do
stub_get('/projects/3/builds/8', 'build')
@build = Gitlab.build(3, 8)
end
it 'gets the correct resource' do
expect(a_get('/projects/3/builds/8')).to have_been_made
end
it 'returns a single build' do
expect(@build).to be_a Gitlab::ObjectifiedHash
end
it 'returns information about a build' do
expect(@build.id).to eq(8)
expect(@build.user.name).to eq('John Smith')
end
end
describe '.build_artifacts' do
context 'when successful request' do
before do
fixture = load_fixture('build_artifacts.zip')
fixture.set_encoding(Encoding::ASCII_8BIT)
stub_request(:get, "#{Gitlab.endpoint}/projects/3/builds/8/artifacts")
.with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token })
.to_return(body: fixture.read, headers: { 'Content-Disposition' => 'attachment; filename=artifacts.zip' })
@build_artifacts = Gitlab.build_artifacts(3, 8)
end
it 'gets the correct resource' do
expect(a_get('/projects/3/builds/8/artifacts')).to have_been_made
end
it 'returns a FileResponse' do
expect(@build_artifacts).to be_a Gitlab::FileResponse
end
it 'returns a file with filename' do
expect(@build_artifacts.filename).to eq 'artifacts.zip'
end
end
context 'when bad request' do
it 'throws an exception' do
stub_get('/projects/3/builds/8/artifacts', 'error_project_not_found', 404)
expect { Gitlab.build_artifacts(3, 8) }.to raise_error(Gitlab::Error::NotFound, "Server responded with code 404, message: 404 Project Not Found. Request URI: #{Gitlab.endpoint}/projects/3/builds/8/artifacts")
end
end
end
describe '.builds_commits' do
before do
stub_get('/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds', 'builds_commits')
@builds_commits = Gitlab.commit_builds(3, '0ff3ae198f8601a285adcf5c0fff204ee6fba5fd')
end
it 'gets the correct resource' do
expect(a_get('/projects/3/repository/commits/0ff3ae198f8601a285adcf5c0fff204ee6fba5fd/builds')).to have_been_made
end
it 'returns a paginated response of commit builds' do
expect(@builds_commits).to be_a Gitlab::PaginatedResponse
end
it 'returns information about the builds' do
expect(@builds_commits.count).to eq(2)
end
end
describe '.build_cancel' do
before do
stub_post('/projects/3/builds/8/cancel', 'build_cancel')
@build_cancel = Gitlab.build_cancel(3, 8)
end
it 'gets the correct resource' do
expect(a_post('/projects/3/builds/8/cancel')).to have_been_made
end
it 'returns a single build' do
expect(@build_cancel).to be_a Gitlab::ObjectifiedHash
end
it 'returns information about a build' do
expect(@build_cancel.commit.author_name).to eq('John Smith')
end
end
describe '.build_retry' do
before do
stub_post('/projects/3/builds/69/retry', 'build_retry')
@build_retry = Gitlab.build_retry(3, 69)
end
it 'gets the correct resource' do
expect(a_post('/projects/3/builds/69/retry')).to have_been_made
end
it 'returns a single build' do
expect(@build_retry).to be_a Gitlab::ObjectifiedHash
end
it 'returns information about a build' do
expect(@build_retry.commit.author_name).to eq('John Smith')
end
end
describe '.build_erase' do
before do
stub_post('/projects/3/builds/69/erase', 'build_erase')
@build_retry = Gitlab.build_erase(3, 69)
end
it 'gets the correct resource' do
expect(a_post('/projects/3/builds/69/erase')).to have_been_made
end
it 'returns a single build' do
expect(@build_retry).to be_a Gitlab::ObjectifiedHash
end
it 'returns information about a build' do
expect(@build_retry.commit.author_name).to eq('John Smith')
end
end
end
|