diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/ci/build_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/project_services/buildkite_service_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/project_services/drone_ci_service_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/snippet_repository_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/snippet_spec.rb | 34 |
5 files changed, 49 insertions, 15 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 8c7969af177..88c26c92417 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1882,7 +1882,7 @@ describe Ci::Build do describe '#options' do let(:options) do { - image: "ruby:2.1", + image: "ruby:2.7", services: ["postgres"], script: ["ls -a"] } @@ -1893,11 +1893,11 @@ describe Ci::Build do end it 'allows to access with keys' do - expect(build.options[:image]).to eq('ruby:2.1') + expect(build.options[:image]).to eq('ruby:2.7') end it 'allows to access with strings' do - expect(build.options['image']).to eq('ruby:2.1') + expect(build.options['image']).to eq('ruby:2.7') end context 'when ci_build_metadata_config is set' do diff --git a/spec/models/project_services/buildkite_service_spec.rb b/spec/models/project_services/buildkite_service_spec.rb index c622b7706c6..8b6fa36eaa5 100644 --- a/spec/models/project_services/buildkite_service_spec.rb +++ b/spec/models/project_services/buildkite_service_spec.rb @@ -84,6 +84,10 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do describe '#calculate_reactive_cache' do describe '#commit_status' do + let(:buildkite_full_url) do + 'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=123' + end + subject { service.calculate_reactive_cache('123', 'unused')[:commit_status] } it 'sets commit status to :error when status is 500' do @@ -103,13 +107,25 @@ describe BuildkiteService, :use_clean_rails_memory_store_caching do is_expected.to eq('Great Success') end + + Gitlab::HTTP::HTTP_ERRORS.each do |http_error| + it "sets commit status to :error with a #{http_error.name} error" do + WebMock.stub_request(:get, buildkite_full_url) + .to_raise(http_error) + + expect(Gitlab::ErrorTracking) + .to receive(:log_exception) + .with(instance_of(http_error), project_id: project.id) + + is_expected.to eq(:error) + end + end end end end def stub_request(status: 200, body: nil) body ||= %q({"status":"success"}) - buildkite_full_url = 'https://gitlab.buildkite.com/status/secret-sauce-status-token.json?commit=123' stub_full_request(buildkite_full_url) .to_return(status: status, diff --git a/spec/models/project_services/drone_ci_service_spec.rb b/spec/models/project_services/drone_ci_service_spec.rb index 0639a4c1f23..1ee9c5f90c6 100644 --- a/spec/models/project_services/drone_ci_service_spec.rb +++ b/spec/models/project_services/drone_ci_service_spec.rb @@ -106,6 +106,10 @@ describe DroneCiService, :use_clean_rails_memory_store_caching do WebMock.stub_request(:get, commit_status_path) .to_raise(http_error) + expect(Gitlab::ErrorTracking) + .to receive(:log_exception) + .with(instance_of(http_error), project_id: project.id) + is_expected.to eq(:error) end end diff --git a/spec/models/snippet_repository_spec.rb b/spec/models/snippet_repository_spec.rb index c31fe192367..dc9f9a95d24 100644 --- a/spec/models/snippet_repository_spec.rb +++ b/spec/models/snippet_repository_spec.rb @@ -16,7 +16,7 @@ describe SnippetRepository do describe '.find_snippet' do it 'finds snippet by disk path' do snippet = create(:snippet, author: user) - snippet.track_snippet_repository + snippet.track_snippet_repository(snippet.repository.storage) expect(described_class.find_snippet(snippet.disk_path)).to eq(snippet) end diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index 0e19dfc147b..8ce3718e3c1 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -567,18 +567,21 @@ describe Snippet do describe '#track_snippet_repository' do let(:snippet) { create(:snippet) } + let(:shard_name) { 'foo' } + + subject { snippet.track_snippet_repository(shard_name) } context 'when a snippet repository entry does not exist' do it 'creates a new entry' do - expect { snippet.track_snippet_repository }.to change(snippet, :snippet_repository) + expect { subject }.to change(snippet, :snippet_repository) end it 'tracks the snippet storage location' do - snippet.track_snippet_repository + subject expect(snippet.snippet_repository).to have_attributes( disk_path: snippet.disk_path, - shard_name: snippet.repository_storage + shard_name: shard_name ) end end @@ -586,21 +589,20 @@ describe Snippet do context 'when a tracking entry exists' do let!(:snippet) { create(:snippet, :repository) } let(:snippet_repository) { snippet.snippet_repository } - let!(:shard) { create(:shard, name: 'foo') } + let(:shard_name) { 'bar' } it 'does not create a new entry in the database' do - expect { snippet.track_snippet_repository }.not_to change(snippet, :snippet_repository) + expect { subject }.not_to change(snippet, :snippet_repository) end it 'updates the snippet storage location' do allow(snippet).to receive(:disk_path).and_return('fancy/new/path') - allow(snippet).to receive(:repository_storage).and_return('foo') - snippet.track_snippet_repository + subject expect(snippet.snippet_repository).to have_attributes( disk_path: 'fancy/new/path', - shard_name: 'foo' + shard_name: shard_name ) end end @@ -609,19 +611,31 @@ describe Snippet do describe '#create_repository' do let(:snippet) { create(:snippet) } + subject { snippet.create_repository } + it 'creates the repository' do expect(snippet.repository).to receive(:after_create).and_call_original - expect(snippet.create_repository).to be_truthy + expect(subject).to be_truthy expect(snippet.repository.exists?).to be_truthy end it 'tracks snippet repository' do expect do - snippet.create_repository + subject end.to change(SnippetRepository, :count).by(1) end + it 'sets same shard in snippet repository as in the repository storage' do + expect(snippet).to receive(:repository_storage).and_return('picked') + expect(snippet).to receive(:repository_exists?).and_return(false) + expect(snippet.repository).to receive(:create_if_not_exists) + + subject + + expect(snippet.snippet_repository.shard_name).to eq 'picked' + end + context 'when repository exists' do let!(:snippet) { create(:snippet, :repository) } |