diff options
Diffstat (limited to 'spec/lib')
44 files changed, 412 insertions, 152 deletions
diff --git a/spec/lib/api/helpers/custom_validators_spec.rb b/spec/lib/api/helpers/custom_validators_spec.rb index 9945d598a14..aed86b21cb7 100644 --- a/spec/lib/api/helpers/custom_validators_spec.rb +++ b/spec/lib/api/helpers/custom_validators_spec.rb @@ -21,7 +21,7 @@ describe API::Helpers::CustomValidators do end context 'invalid parameters' do - it 'should raise a validation error' do + it 'raises a validation error' do expect_validation_error({ 'test' => 'some_value' }) end end @@ -44,7 +44,7 @@ describe API::Helpers::CustomValidators do end context 'invalid parameters' do - it 'should raise a validation error' do + it 'raises a validation error' do expect_validation_error({ 'test' => 'some_other_string' }) end end @@ -67,7 +67,7 @@ describe API::Helpers::CustomValidators do end context 'invalid parameters' do - it 'should raise a validation error' do + it 'raises a validation error' do expect_validation_error({ 'test' => 'some_other_string' }) end end diff --git a/spec/lib/banzai/filter/blockquote_fence_filter_spec.rb b/spec/lib/banzai/filter/blockquote_fence_filter_spec.rb index b645e49bd43..5b3f679084e 100644 --- a/spec/lib/banzai/filter/blockquote_fence_filter_spec.rb +++ b/spec/lib/banzai/filter/blockquote_fence_filter_spec.rb @@ -13,6 +13,6 @@ describe Banzai::Filter::BlockquoteFenceFilter do end it 'allows trailing whitespace on blockquote fence lines' do - expect(filter(">>> \ntest\n>>> ")).to eq("> test") + expect(filter(">>> \ntest\n>>> ")).to eq("\n> test\n") end end diff --git a/spec/lib/banzai/filter/plantuml_filter_spec.rb b/spec/lib/banzai/filter/plantuml_filter_spec.rb index 8235c411eb7..6f7acfe7072 100644 --- a/spec/lib/banzai/filter/plantuml_filter_spec.rb +++ b/spec/lib/banzai/filter/plantuml_filter_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Banzai::Filter::PlantumlFilter do include FilterSpecHelper - it 'should replace plantuml pre tag with img tag' do + it 'replaces plantuml pre tag with img tag' do stub_application_setting(plantuml_enabled: true, plantuml_url: "http://localhost:8080") input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' output = '<div class="imageblock"><div class="content"><img class="plantuml" src="http://localhost:8080/png/U9npoazIqBLJ24uiIbImKl18pSd91m0rkGMq"></div></div>' @@ -12,7 +12,7 @@ describe Banzai::Filter::PlantumlFilter do expect(doc.to_s).to eq output end - it 'should not replace plantuml pre tag with img tag if disabled' do + it 'does not replace plantuml pre tag with img tag if disabled' do stub_application_setting(plantuml_enabled: false) input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' output = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' @@ -21,7 +21,7 @@ describe Banzai::Filter::PlantumlFilter do expect(doc.to_s).to eq output end - it 'should not replace plantuml pre tag with img tag if url is invalid' do + it 'does not replace plantuml pre tag with img tag if url is invalid' do stub_application_setting(plantuml_enabled: true, plantuml_url: "invalid") input = '<pre><code lang="plantuml">Bob -> Sara : Hello</code></pre>' output = '<div class="listingblock"><div class="content"><pre class="plantuml plantuml-error"> PlantUML Error: cannot connect to PlantUML server at "invalid"</pre></div></div>' diff --git a/spec/lib/forever_spec.rb b/spec/lib/forever_spec.rb index 494c0561975..b9ffe895bf0 100644 --- a/spec/lib/forever_spec.rb +++ b/spec/lib/forever_spec.rb @@ -5,7 +5,7 @@ describe Forever do subject { described_class.date } context 'when using PostgreSQL' do - it 'should return Postgresql future date' do + it 'returns Postgresql future date' do allow(Gitlab::Database).to receive(:postgresql?).and_return(true) expect(subject).to eq(described_class::POSTGRESQL_DATE) @@ -13,7 +13,7 @@ describe Forever do end context 'when using MySQL' do - it 'should return MySQL future date' do + it 'returns MySQL future date' do allow(Gitlab::Database).to receive(:postgresql?).and_return(false) expect(subject).to eq(described_class::MYSQL_DATE) diff --git a/spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb b/spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb index 812e0cc6947..128e118ac17 100644 --- a/spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb +++ b/spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb @@ -19,7 +19,7 @@ describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, : end shared_examples 'consistent kubernetes namespace attributes' do - it 'should populate namespace and service account information' do + it 'populates namespace and service account information' do migration.perform clusters_with_namespace.each do |cluster| @@ -41,7 +41,7 @@ describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, : context 'when no Clusters::Project has a Clusters::KubernetesNamespace' do let(:cluster_projects) { cluster_projects_table.all } - it 'should create a Clusters::KubernetesNamespace per Clusters::Project' do + it 'creates a Clusters::KubernetesNamespace per Clusters::Project' do expect do migration.perform end.to change(Clusters::KubernetesNamespace, :count).by(cluster_projects_table.count) @@ -57,7 +57,7 @@ describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, : create_kubernetes_namespace(clusters_table.all) end - it 'should not create any Clusters::KubernetesNamespace' do + it 'does not create any Clusters::KubernetesNamespace' do expect do migration.perform end.not_to change(Clusters::KubernetesNamespace, :count) @@ -78,7 +78,7 @@ describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, : end.to change(Clusters::KubernetesNamespace, :count).by(with_no_kubernetes_namespace.count) end - it 'should not modify clusters with Clusters::KubernetesNamespace' do + it 'does not modify clusters with Clusters::KubernetesNamespace' do migration.perform with_kubernetes_namespace.each do |cluster| diff --git a/spec/lib/gitlab/background_migration/populate_fork_networks_range_spec.rb b/spec/lib/gitlab/background_migration/populate_fork_networks_range_spec.rb index 8582af96199..0e73c8c59c9 100644 --- a/spec/lib/gitlab/background_migration/populate_fork_networks_range_spec.rb +++ b/spec/lib/gitlab/background_migration/populate_fork_networks_range_spec.rb @@ -41,7 +41,7 @@ describe Gitlab::BackgroundMigration::PopulateForkNetworksRange, :migration, sch migration.perform(1, 3) end - it 'it creates the fork network' do + it 'creates the fork network' do expect(fork_network1).not_to be_nil expect(fork_network2).not_to be_nil end diff --git a/spec/lib/gitlab/ci/config/external/file/base_spec.rb b/spec/lib/gitlab/ci/config/external/file/base_spec.rb index fa39b32d7ab..dd536a241bd 100644 --- a/spec/lib/gitlab/ci/config/external/file/base_spec.rb +++ b/spec/lib/gitlab/ci/config/external/file/base_spec.rb @@ -26,7 +26,7 @@ describe Gitlab::Ci::Config::External::File::Base do context 'when a location is present' do let(:location) { 'some-location' } - it 'should return true' do + it 'returns true' do expect(subject).to be_matching end end @@ -34,7 +34,7 @@ describe Gitlab::Ci::Config::External::File::Base do context 'with a location is missing' do let(:location) { nil } - it 'should return false' do + it 'returns false' do expect(subject).not_to be_matching end end diff --git a/spec/lib/gitlab/ci/config/external/file/local_spec.rb b/spec/lib/gitlab/ci/config/external/file/local_spec.rb index dc14b07287e..9451db9522a 100644 --- a/spec/lib/gitlab/ci/config/external/file/local_spec.rb +++ b/spec/lib/gitlab/ci/config/external/file/local_spec.rb @@ -15,7 +15,7 @@ describe Gitlab::Ci::Config::External::File::Local do context 'when a local is specified' do let(:params) { { local: 'file' } } - it 'should return true' do + it 'returns true' do expect(local_file).to be_matching end end @@ -23,7 +23,7 @@ describe Gitlab::Ci::Config::External::File::Local do context 'with a missing local' do let(:params) { { local: nil } } - it 'should return false' do + it 'returns false' do expect(local_file).not_to be_matching end end @@ -31,7 +31,7 @@ describe Gitlab::Ci::Config::External::File::Local do context 'with a missing local key' do let(:params) { {} } - it 'should return false' do + it 'returns false' do expect(local_file).not_to be_matching end end @@ -45,7 +45,7 @@ describe Gitlab::Ci::Config::External::File::Local do allow_any_instance_of(described_class).to receive(:fetch_local_content).and_return("image: 'ruby2:2'") end - it 'should return true' do + it 'returns true' do expect(local_file.valid?).to be_truthy end end @@ -53,7 +53,7 @@ describe Gitlab::Ci::Config::External::File::Local do context 'when is not a valid local path' do let(:location) { '/lib/gitlab/ci/templates/non-existent-file.yml' } - it 'should return false' do + it 'returns false' do expect(local_file.valid?).to be_falsy end end @@ -61,7 +61,7 @@ describe Gitlab::Ci::Config::External::File::Local do context 'when is not a yaml file' do let(:location) { '/config/application.rb' } - it 'should return false' do + it 'returns false' do expect(local_file.valid?).to be_falsy end end @@ -84,7 +84,7 @@ describe Gitlab::Ci::Config::External::File::Local do allow_any_instance_of(described_class).to receive(:fetch_local_content).and_return(local_file_content) end - it 'should return the content of the file' do + it 'returns the content of the file' do expect(local_file.content).to eq(local_file_content) end end @@ -92,7 +92,7 @@ describe Gitlab::Ci::Config::External::File::Local do context 'with an invalid file' do let(:location) { '/lib/gitlab/ci/templates/non-existent-file.yml' } - it 'should be nil' do + it 'is nil' do expect(local_file.content).to be_nil end end @@ -101,7 +101,7 @@ describe Gitlab::Ci::Config::External::File::Local do describe '#error_message' do let(:location) { '/lib/gitlab/ci/templates/non-existent-file.yml' } - it 'should return an error message' do + it 'returns an error message' do expect(local_file.error_message).to eq("Local file `#{location}` does not exist!") end end diff --git a/spec/lib/gitlab/ci/config/external/file/project_spec.rb b/spec/lib/gitlab/ci/config/external/file/project_spec.rb index 6e89bb1b30f..4acb4f324d3 100644 --- a/spec/lib/gitlab/ci/config/external/file/project_spec.rb +++ b/spec/lib/gitlab/ci/config/external/file/project_spec.rb @@ -19,7 +19,7 @@ describe Gitlab::Ci::Config::External::File::Project do context 'when a file and project is specified' do let(:params) { { file: 'file.yml', project: 'project' } } - it 'should return true' do + it 'returns true' do expect(project_file).to be_matching end end @@ -27,7 +27,7 @@ describe Gitlab::Ci::Config::External::File::Project do context 'with only file is specified' do let(:params) { { file: 'file.yml' } } - it 'should return false' do + it 'returns false' do expect(project_file).not_to be_matching end end @@ -35,7 +35,7 @@ describe Gitlab::Ci::Config::External::File::Project do context 'with only project is specified' do let(:params) { { project: 'project' } } - it 'should return false' do + it 'returns false' do expect(project_file).not_to be_matching end end @@ -43,7 +43,7 @@ describe Gitlab::Ci::Config::External::File::Project do context 'with a missing local key' do let(:params) { {} } - it 'should return false' do + it 'returns false' do expect(project_file).not_to be_matching end end @@ -61,14 +61,14 @@ describe Gitlab::Ci::Config::External::File::Project do stub_project_blob(root_ref_sha, '/file.yml') { 'image: ruby:2.1' } end - it 'should return true' do + it 'returns true' do expect(project_file).to be_valid end context 'when user does not have permission to access file' do let(:context_user) { create(:user) } - it 'should return false' do + it 'returns false' do expect(project_file).not_to be_valid expect(project_file.error_message).to include("Project `#{project.full_path}` not found or access denied!") end @@ -86,7 +86,7 @@ describe Gitlab::Ci::Config::External::File::Project do stub_project_blob(ref_sha, '/file.yml') { 'image: ruby:2.1' } end - it 'should return true' do + it 'returns true' do expect(project_file).to be_valid end end @@ -102,7 +102,7 @@ describe Gitlab::Ci::Config::External::File::Project do stub_project_blob(root_ref_sha, '/file.yml') { '' } end - it 'should return false' do + it 'returns false' do expect(project_file).not_to be_valid expect(project_file.error_message).to include("Project `#{project.full_path}` file `/file.yml` is empty!") end @@ -113,7 +113,7 @@ describe Gitlab::Ci::Config::External::File::Project do { project: project.full_path, ref: 'I-Do-Not-Exist', file: '/file.yml' } end - it 'should return false' do + it 'returns false' do expect(project_file).not_to be_valid expect(project_file.error_message).to include("Project `#{project.full_path}` reference `I-Do-Not-Exist` does not exist!") end @@ -124,7 +124,7 @@ describe Gitlab::Ci::Config::External::File::Project do { project: project.full_path, file: '/invalid-file.yml' } end - it 'should return false' do + it 'returns false' do expect(project_file).not_to be_valid expect(project_file.error_message).to include("Project `#{project.full_path}` file `/invalid-file.yml` does not exist!") end @@ -135,7 +135,7 @@ describe Gitlab::Ci::Config::External::File::Project do { project: project.full_path, file: '/invalid-file' } end - it 'should return false' do + it 'returns false' do expect(project_file).not_to be_valid expect(project_file.error_message).to include('Included file `/invalid-file` does not have YAML extension!') end diff --git a/spec/lib/gitlab/ci/config/external/file/remote_spec.rb b/spec/lib/gitlab/ci/config/external/file/remote_spec.rb index c5b32c29759..d8a61618e77 100644 --- a/spec/lib/gitlab/ci/config/external/file/remote_spec.rb +++ b/spec/lib/gitlab/ci/config/external/file/remote_spec.rb @@ -21,7 +21,7 @@ describe Gitlab::Ci::Config::External::File::Remote do context 'when a remote is specified' do let(:params) { { remote: 'http://remote' } } - it 'should return true' do + it 'returns true' do expect(remote_file).to be_matching end end @@ -29,7 +29,7 @@ describe Gitlab::Ci::Config::External::File::Remote do context 'with a missing remote' do let(:params) { { remote: nil } } - it 'should return false' do + it 'returns false' do expect(remote_file).not_to be_matching end end @@ -37,7 +37,7 @@ describe Gitlab::Ci::Config::External::File::Remote do context 'with a missing remote key' do let(:params) { {} } - it 'should return false' do + it 'returns false' do expect(remote_file).not_to be_matching end end @@ -49,7 +49,7 @@ describe Gitlab::Ci::Config::External::File::Remote do WebMock.stub_request(:get, location).to_return(body: remote_file_content) end - it 'should return true' do + it 'returns true' do expect(remote_file.valid?).to be_truthy end end @@ -57,7 +57,7 @@ describe Gitlab::Ci::Config::External::File::Remote do context 'with an irregular url' do let(:location) { 'not-valid://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml' } - it 'should return false' do + it 'returns false' do expect(remote_file.valid?).to be_falsy end end @@ -67,7 +67,7 @@ describe Gitlab::Ci::Config::External::File::Remote do allow(Gitlab::HTTP).to receive(:get).and_raise(Timeout::Error) end - it 'should be falsy' do + it 'is falsy' do expect(remote_file.valid?).to be_falsy end end @@ -75,7 +75,7 @@ describe Gitlab::Ci::Config::External::File::Remote do context 'when is not a yaml file' do let(:location) { 'https://asdasdasdaj48ggerexample.com' } - it 'should be falsy' do + it 'is falsy' do expect(remote_file.valid?).to be_falsy end end @@ -83,7 +83,7 @@ describe Gitlab::Ci::Config::External::File::Remote do context 'with an internal url' do let(:location) { 'http://localhost:8080' } - it 'should be falsy' do + it 'is falsy' do expect(remote_file.valid?).to be_falsy end end @@ -95,7 +95,7 @@ describe Gitlab::Ci::Config::External::File::Remote do WebMock.stub_request(:get, location).to_return(body: remote_file_content) end - it 'should return the content of the file' do + it 'returns the content of the file' do expect(remote_file.content).to eql(remote_file_content) end end @@ -105,7 +105,7 @@ describe Gitlab::Ci::Config::External::File::Remote do allow(Gitlab::HTTP).to receive(:get).and_raise(Timeout::Error) end - it 'should be falsy' do + it 'is falsy' do expect(remote_file.content).to be_falsy end end @@ -117,7 +117,7 @@ describe Gitlab::Ci::Config::External::File::Remote do WebMock.stub_request(:get, location).to_raise(SocketError.new('Some HTTP error')) end - it 'should be nil' do + it 'is nil' do expect(remote_file.content).to be_nil end end @@ -125,7 +125,7 @@ describe Gitlab::Ci::Config::External::File::Remote do context 'with an internal url' do let(:location) { 'http://localhost:8080' } - it 'should be nil' do + it 'is nil' do expect(remote_file.content).to be_nil end end @@ -147,7 +147,7 @@ describe Gitlab::Ci::Config::External::File::Remote do WebMock.stub_request(:get, location).to_timeout end - it 'should returns error message about a timeout' do + it 'returns error message about a timeout' do expect(subject).to match /could not be fetched because of a timeout error!/ end end @@ -157,7 +157,7 @@ describe Gitlab::Ci::Config::External::File::Remote do WebMock.stub_request(:get, location).to_raise(Gitlab::HTTP::Error) end - it 'should returns error message about a HTTP error' do + it 'returns error message about a HTTP error' do expect(subject).to match /could not be fetched because of HTTP error!/ end end @@ -167,7 +167,7 @@ describe Gitlab::Ci::Config::External::File::Remote do WebMock.stub_request(:get, location).to_return(body: remote_file_content, status: 404) end - it 'should returns error message about a timeout' do + it 'returns error message about a timeout' do expect(subject).to match /could not be fetched because of HTTP code `404` error!/ end end @@ -175,7 +175,7 @@ describe Gitlab::Ci::Config::External::File::Remote do context 'when the URL is blocked' do let(:location) { 'http://127.0.0.1/some/path/to/config.yaml' } - it 'should include details about blocked URL' do + it 'includes details about blocked URL' do expect(subject).to eq "Remote file could not be fetched because URL '#{location}' " \ 'is blocked: Requests to localhost are not allowed!' end diff --git a/spec/lib/gitlab/ci/config/external/file/template_spec.rb b/spec/lib/gitlab/ci/config/external/file/template_spec.rb index 8ecaf4800f8..1609b8fd66b 100644 --- a/spec/lib/gitlab/ci/config/external/file/template_spec.rb +++ b/spec/lib/gitlab/ci/config/external/file/template_spec.rb @@ -16,7 +16,7 @@ describe Gitlab::Ci::Config::External::File::Template do context 'when a template is specified' do let(:params) { { template: 'some-template' } } - it 'should return true' do + it 'returns true' do expect(template_file).to be_matching end end @@ -24,7 +24,7 @@ describe Gitlab::Ci::Config::External::File::Template do context 'with a missing template' do let(:params) { { template: nil } } - it 'should return false' do + it 'returns false' do expect(template_file).not_to be_matching end end @@ -32,7 +32,7 @@ describe Gitlab::Ci::Config::External::File::Template do context 'with a missing template key' do let(:params) { {} } - it 'should return false' do + it 'returns false' do expect(template_file).not_to be_matching end end @@ -42,7 +42,7 @@ describe Gitlab::Ci::Config::External::File::Template do context 'when is a valid template name' do let(:template) { 'Auto-DevOps.gitlab-ci.yml' } - it 'should return true' do + it 'returns true' do expect(template_file).to be_valid end end @@ -50,7 +50,7 @@ describe Gitlab::Ci::Config::External::File::Template do context 'with invalid template name' do let(:template) { 'Template.yml' } - it 'should return false' do + it 'returns false' do expect(template_file).not_to be_valid expect(template_file.error_message).to include('Template file `Template.yml` is not a valid location!') end @@ -59,7 +59,7 @@ describe Gitlab::Ci::Config::External::File::Template do context 'with a non-existing template' do let(:template) { 'I-Do-Not-Have-This-Template.gitlab-ci.yml' } - it 'should return false' do + it 'returns false' do expect(template_file).not_to be_valid expect(template_file.error_message).to include('Included file `I-Do-Not-Have-This-Template.gitlab-ci.yml` is empty or does not exist!') end diff --git a/spec/lib/gitlab/ci/config/external/processor_spec.rb b/spec/lib/gitlab/ci/config/external/processor_spec.rb index 3f6f6d7c5d9..e94bb44f990 100644 --- a/spec/lib/gitlab/ci/config/external/processor_spec.rb +++ b/spec/lib/gitlab/ci/config/external/processor_spec.rb @@ -21,7 +21,7 @@ describe Gitlab::Ci::Config::External::Processor do context 'when no external files defined' do let(:values) { { image: 'ruby:2.2' } } - it 'should return the same values' do + it 'returns the same values' do expect(processor.perform).to eq(values) end end @@ -29,7 +29,7 @@ describe Gitlab::Ci::Config::External::Processor do context 'when an invalid local file is defined' do let(:values) { { include: '/lib/gitlab/ci/templates/non-existent-file.yml', image: 'ruby:2.2' } } - it 'should raise an error' do + it 'raises an error' do expect { processor.perform }.to raise_error( described_class::IncludeError, "Local file `/lib/gitlab/ci/templates/non-existent-file.yml` does not exist!" @@ -45,7 +45,7 @@ describe Gitlab::Ci::Config::External::Processor do WebMock.stub_request(:get, remote_file).to_raise(SocketError.new('Some HTTP error')) end - it 'should raise an error' do + it 'raises an error' do expect { processor.perform }.to raise_error( described_class::IncludeError, "Remote file `#{remote_file}` could not be fetched because of a socket error!" @@ -78,12 +78,12 @@ describe Gitlab::Ci::Config::External::Processor do WebMock.stub_request(:get, remote_file).to_return(body: external_file_content) end - it 'should append the file to the values' do + it 'appends the file to the values' do output = processor.perform expect(output.keys).to match_array([:image, :before_script, :rspec, :rubocop]) end - it "should remove the 'include' keyword" do + it "removes the 'include' keyword" do expect(processor.perform[:include]).to be_nil end end @@ -105,12 +105,12 @@ describe Gitlab::Ci::Config::External::Processor do .to receive(:fetch_local_content).and_return(local_file_content) end - it 'should append the file to the values' do + it 'appends the file to the values' do output = processor.perform expect(output.keys).to match_array([:image, :before_script]) end - it "should remove the 'include' keyword" do + it "removes the 'include' keyword" do expect(processor.perform[:include]).to be_nil end end @@ -148,11 +148,11 @@ describe Gitlab::Ci::Config::External::Processor do WebMock.stub_request(:get, remote_file).to_return(body: remote_file_content) end - it 'should append the files to the values' do + it 'appends the files to the values' do expect(processor.perform.keys).to match_array([:image, :stages, :before_script, :rspec]) end - it "should remove the 'include' keyword" do + it "removes the 'include' keyword" do expect(processor.perform[:include]).to be_nil end end @@ -167,7 +167,7 @@ describe Gitlab::Ci::Config::External::Processor do .to receive(:fetch_local_content).and_return(local_file_content) end - it 'should raise an error' do + it 'raises an error' do expect { processor.perform }.to raise_error( described_class::IncludeError, "Included file `/lib/gitlab/ci/templates/template.yml` does not have valid YAML syntax!" @@ -190,7 +190,7 @@ describe Gitlab::Ci::Config::External::Processor do HEREDOC end - it 'should take precedence' do + it 'takes precedence' do WebMock.stub_request(:get, remote_file).to_return(body: remote_file_content) expect(processor.perform[:image]).to eq('ruby:2.2') end diff --git a/spec/lib/gitlab/ci/config_spec.rb b/spec/lib/gitlab/ci/config_spec.rb index 00b2753c5fc..fd2a29e4ddb 100644 --- a/spec/lib/gitlab/ci/config_spec.rb +++ b/spec/lib/gitlab/ci/config_spec.rb @@ -225,7 +225,7 @@ describe Gitlab::Ci::Config do end context "when gitlab_ci_yml has valid 'include' defined" do - it 'should return a composed hash' do + it 'returns a composed hash' do before_script_values = [ "apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs", "ruby -v", "which ruby", @@ -316,7 +316,7 @@ describe Gitlab::Ci::Config do HEREDOC end - it 'should take precedence' do + it 'takes precedence' do expect(config.to_hash).to eq({ image: 'ruby:2.2' }) end end @@ -341,7 +341,7 @@ describe Gitlab::Ci::Config do HEREDOC end - it 'should merge the variables dictionaries' do + it 'merges the variables dictionaries' do expect(config.to_hash).to eq({ variables: { A: 'alpha', B: 'beta', C: 'gamma', D: 'delta' } }) end end diff --git a/spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb index dc13cae961c..c7f4fc98ca3 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb @@ -23,7 +23,7 @@ describe Gitlab::Ci::Pipeline::Chain::Skip do step.perform! end - it 'should break the chain' do + it 'breaks the chain' do expect(step.break?).to be true end @@ -37,11 +37,11 @@ describe Gitlab::Ci::Pipeline::Chain::Skip do step.perform! end - it 'should not break the chain' do + it 'does not break the chain' do expect(step.break?).to be false end - it 'should not skip a pipeline chain' do + it 'does not skip a pipeline chain' do expect(pipeline.reload).not_to be_skipped end end diff --git a/spec/lib/gitlab/ci/status/build/factory_spec.rb b/spec/lib/gitlab/ci/status/build/factory_spec.rb index b379b08ad62..b6231510b91 100644 --- a/spec/lib/gitlab/ci/status/build/factory_spec.rb +++ b/spec/lib/gitlab/ci/status/build/factory_spec.rb @@ -123,6 +123,35 @@ describe Gitlab::Ci::Status::Build::Factory do expect(status.action_path).to include 'retry' end end + + context 'when build has unmet prerequisites' do + let(:build) { create(:ci_build, :prerequisite_failure) } + + it 'matches correct core status' do + expect(factory.core_status).to be_a Gitlab::Ci::Status::Failed + end + + it 'matches correct extended statuses' do + expect(factory.extended_statuses) + .to eq [Gitlab::Ci::Status::Build::Retryable, + Gitlab::Ci::Status::Build::FailedUnmetPrerequisites] + end + + it 'fabricates a failed with unmet prerequisites build status' do + expect(status).to be_a Gitlab::Ci::Status::Build::FailedUnmetPrerequisites + end + + it 'fabricates status with correct details' do + expect(status.text).to eq 'failed' + expect(status.icon).to eq 'status_failed' + expect(status.favicon).to eq 'favicon_status_failed' + expect(status.label).to eq 'failed' + expect(status).to have_details + expect(status).to have_action + expect(status.action_title).to include 'Retry' + expect(status.action_path).to include 'retry' + end + end end context 'when build is a canceled' do diff --git a/spec/lib/gitlab/ci/status/build/failed_unmet_prerequisites_spec.rb b/spec/lib/gitlab/ci/status/build/failed_unmet_prerequisites_spec.rb new file mode 100644 index 00000000000..a4854bdc6b9 --- /dev/null +++ b/spec/lib/gitlab/ci/status/build/failed_unmet_prerequisites_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +RSpec.describe Gitlab::Ci::Status::Build::FailedUnmetPrerequisites do + describe '#illustration' do + subject { described_class.new(double).illustration } + + it { is_expected.to include(:image, :size, :title, :content) } + end + + describe '.matches?' do + let(:build) { create(:ci_build, :created) } + + subject { described_class.matches?(build, double) } + + context 'when build has not failed' do + it { is_expected.to be_falsey } + end + + context 'when build has failed' do + before do + build.drop!(failure_reason) + end + + context 'with unmet prerequisites' do + let(:failure_reason) { :unmet_prerequisites } + + it { is_expected.to be_truthy } + end + + context 'with a different error' do + let(:failure_reason) { :runner_system_failure } + + it { is_expected.to be_falsey } + end + end + end +end diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 63a0d54dcfc..8b39c4e4dd0 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -615,6 +615,14 @@ module Gitlab subject { Gitlab::Ci::YamlProcessor.new(YAML.dump(config), opts) } context "when validating a ci config file with no project context" do + context "when a single string is provided" do + let(:include_content) { "/local.gitlab-ci.yml" } + + it "does not return any error" do + expect { subject }.not_to raise_error + end + end + context "when an array is provided" do let(:include_content) { ["/local.gitlab-ci.yml"] } diff --git a/spec/lib/gitlab/contributions_calendar_spec.rb b/spec/lib/gitlab/contributions_calendar_spec.rb index b7924302014..51e5bdc6307 100644 --- a/spec/lib/gitlab/contributions_calendar_spec.rb +++ b/spec/lib/gitlab/contributions_calendar_spec.rb @@ -150,13 +150,13 @@ describe Gitlab::ContributionsCalendar do end describe '#starting_year' do - it "should be the start of last year" do + it "is the start of last year" do expect(calendar.starting_year).to eq(last_year.year) end end describe '#starting_month' do - it "should be the start of this month" do + it "is the start of this month" do expect(calendar.starting_month).to eq(today.month) end end diff --git a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb index 1d31f96159c..ddd54a669a3 100644 --- a/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb +++ b/spec/lib/gitlab/database/rename_reserved_paths_migration/v1_spec.rb @@ -27,7 +27,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1, :delete do describe '#rename_wildcard_paths' do it_behaves_like 'renames child namespaces' - it 'should rename projects' do + it 'renames projects' do rename_projects = double expect(described_class::RenameProjects) .to receive(:new).with(['the-path'], subject) @@ -40,7 +40,7 @@ describe Gitlab::Database::RenameReservedPathsMigration::V1, :delete do end describe '#rename_root_paths' do - it 'should rename namespaces' do + it 'renames namespaces' do rename_namespaces = double expect(described_class::RenameNamespaces) .to receive(:new).with(['the-path'], subject) diff --git a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb index 256166dbad3..0697594c725 100644 --- a/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb +++ b/spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb @@ -27,7 +27,7 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do let(:diffable) { merge_request.merge_request_diff } end - it 'it uses a different cache key if diff line keys change' do + it 'uses a different cache key if diff line keys change' do mr_diff = described_class.new(merge_request.merge_request_diff, diff_options: nil) key = mr_diff.cache_key diff --git a/spec/lib/gitlab/etag_caching/router_spec.rb b/spec/lib/gitlab/etag_caching/router_spec.rb index f69cb502ca6..a7cb0bb2a87 100644 --- a/spec/lib/gitlab/etag_caching/router_spec.rb +++ b/spec/lib/gitlab/etag_caching/router_spec.rb @@ -19,6 +19,24 @@ describe Gitlab::EtagCaching::Router do expect(result.name).to eq 'issue_title' end + it 'matches with a project name that includes a suffix of create' do + result = described_class.match( + '/group/test-create/issues/123/realtime_changes' + ) + + expect(result).to be_present + expect(result.name).to eq 'issue_title' + end + + it 'matches with a project name that includes a prefix of create' do + result = described_class.match( + '/group/create-test/issues/123/realtime_changes' + ) + + expect(result).to be_present + expect(result.name).to eq 'issue_title' + end + it 'matches project pipelines endpoint' do result = described_class.match( '/my-group/my-project/pipelines.json' diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb index 4a4ac833e39..507bf222810 100644 --- a/spec/lib/gitlab/git/commit_spec.rb +++ b/spec/lib/gitlab/git/commit_spec.rb @@ -113,13 +113,13 @@ describe Gitlab::Git::Commit, :seed_helper do context 'Class methods' do shared_examples '.find' do - it "should return first head commit if without params" do + it "returns first head commit if without params" do expect(described_class.last(repository).id).to eq( rugged_repo.head.target.oid ) end - it "should return valid commit" do + it "returns valid commit" do expect(described_class.find(repository, SeedRepo::Commit::ID)).to be_valid_commit end @@ -127,21 +127,21 @@ describe Gitlab::Git::Commit, :seed_helper do expect(described_class.find(repository, SeedRepo::Commit::ID).parent_ids).to be_an(Array) end - it "should return valid commit for tag" do + it "returns valid commit for tag" do expect(described_class.find(repository, 'v1.0.0').id).to eq('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') end - it "should return nil for non-commit ids" do + it "returns nil for non-commit ids" do blob = Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "files/ruby/popen.rb") expect(described_class.find(repository, blob.id)).to be_nil end - it "should return nil for parent of non-commit object" do + it "returns nil for parent of non-commit object" do blob = Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "files/ruby/popen.rb") expect(described_class.find(repository, "#{blob.id}^")).to be_nil end - it "should return nil for nonexisting ids" do + it "returns nil for nonexisting ids" do expect(described_class.find(repository, "+123_4532530XYZ")).to be_nil end @@ -328,7 +328,7 @@ describe Gitlab::Git::Commit, :seed_helper do end describe '.find_all' do - it 'should return a return a collection of commits' do + it 'returns a return a collection of commits' do commits = described_class.find_all(repository) expect(commits).to all( be_a_kind_of(described_class) ) diff --git a/spec/lib/gitlab/git/diff_spec.rb b/spec/lib/gitlab/git/diff_spec.rb index 1d22329b670..9ab669ad488 100644 --- a/spec/lib/gitlab/git/diff_spec.rb +++ b/spec/lib/gitlab/git/diff_spec.rb @@ -182,7 +182,7 @@ EOT context "without default options" do let(:filtered_options) { described_class.filter_diff_options(options) } - it "should filter invalid options" do + it "filters invalid options" do expect(filtered_options).not_to have_key(:invalid_opt) end end @@ -193,16 +193,16 @@ EOT described_class.filter_diff_options(options, default_options) end - it "should filter invalid options" do + it "filters invalid options" do expect(filtered_options).not_to have_key(:invalid_opt) expect(filtered_options).not_to have_key(:bad_opt) end - it "should merge with default options" do + it "merges with default options" do expect(filtered_options).to have_key(:ignore_whitespace_change) end - it "should override default options" do + it "overrides default options" do expect(filtered_options).to have_key(:max_files) expect(filtered_options[:max_files]).to eq(100) end diff --git a/spec/lib/gitlab/git/gitmodules_parser_spec.rb b/spec/lib/gitlab/git/gitmodules_parser_spec.rb index 6fd2b33486b..de81dcd227d 100644 --- a/spec/lib/gitlab/git/gitmodules_parser_spec.rb +++ b/spec/lib/gitlab/git/gitmodules_parser_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Gitlab::Git::GitmodulesParser do - it 'should parse a .gitmodules file correctly' do + it 'parses a .gitmodules file correctly' do data = <<~GITMODULES [submodule "vendor/libgit2"] path = vendor/libgit2 diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index fc8f590068a..fdb43d1221a 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -450,20 +450,20 @@ describe Gitlab::Git::Repository, :seed_helper do ensure_seeds end - it "should create a new branch" do + it "creates a new branch" do expect(repository.create_branch('new_branch', 'master')).not_to be_nil end - it "should create a new branch with the right name" do + it "creates a new branch with the right name" do expect(repository.create_branch('another_branch', 'master').name).to eq('another_branch') end - it "should fail if we create an existing branch" do + it "fails if we create an existing branch" do repository.create_branch('duplicated_branch', 'master') expect {repository.create_branch('duplicated_branch', 'master')}.to raise_error("Branch duplicated_branch already exists") end - it "should fail if we create a branch from a non existing ref" do + it "fails if we create a branch from a non existing ref" do expect {repository.create_branch('branch_based_in_wrong_ref', 'master_2_the_revenge')}.to raise_error("Invalid reference master_2_the_revenge") end end @@ -522,7 +522,7 @@ describe Gitlab::Git::Repository, :seed_helper do describe "#refs_hash" do subject { repository.refs_hash } - it "should have as many entries as branches and tags" do + it "has as many entries as branches and tags" do expected_refs = SeedRepo::Repo::BRANCHES + SeedRepo::Repo::TAGS # We flatten in case a commit is pointed at by more than one branch and/or tag expect(subject.values.flatten.size).to eq(expected_refs.size) @@ -613,11 +613,11 @@ describe Gitlab::Git::Repository, :seed_helper do end shared_examples 'search files by content' do - it 'should have 2 items' do + it 'has 2 items' do expect(search_results.size).to eq(2) end - it 'should have the correct matching line' do + it 'has the correct matching line' do expect(search_results).to contain_exactly("search-files-by-content-branch:encoding/CHANGELOG\u00001\u0000search-files-by-content change\n", "search-files-by-content-branch:anotherfile\u00001\u0000search-files-by-content change\n") end @@ -850,7 +850,7 @@ describe Gitlab::Git::Repository, :seed_helper do context "where provides 'after' timestamp" do options = { after: Time.iso8601('2014-03-03T20:15:01+00:00') } - it "should returns commits on or after that timestamp" do + it "returns commits on or after that timestamp" do commits = repository.log(options) expect(commits.size).to be > 0 @@ -863,7 +863,7 @@ describe Gitlab::Git::Repository, :seed_helper do context "where provides 'before' timestamp" do options = { before: Time.iso8601('2014-03-03T20:15:01+00:00') } - it "should returns commits on or before that timestamp" do + it "returns commits on or before that timestamp" do commits = repository.log(options) expect(commits.size).to be > 0 @@ -1064,14 +1064,14 @@ describe Gitlab::Git::Repository, :seed_helper do end describe '#find_branch' do - it 'should return a Branch for master' do + it 'returns a Branch for master' do branch = repository.find_branch('master') expect(branch).to be_a_kind_of(Gitlab::Git::Branch) expect(branch.name).to eq('master') end - it 'should handle non-existent branch' do + it 'handles non-existent branch' do branch = repository.find_branch('this-is-garbage') expect(branch).to eq(nil) diff --git a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb index 41810a8ec03..705df1f4fe7 100644 --- a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb @@ -197,6 +197,11 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do .to receive(:fetch_as_mirror) .with(project.import_url, refmap: Gitlab::GithubImport.refmap, forced: true, remote_name: 'github') + service = double + expect(Projects::HousekeepingService) + .to receive(:new).with(project, :gc).and_return(service) + expect(service).to receive(:execute) + expect(importer.import_repository).to eq(true) end diff --git a/spec/lib/gitlab/kubernetes/cluster_role_binding_spec.rb b/spec/lib/gitlab/kubernetes/cluster_role_binding_spec.rb index 4a669408025..e1106f7496a 100644 --- a/spec/lib/gitlab/kubernetes/cluster_role_binding_spec.rb +++ b/spec/lib/gitlab/kubernetes/cluster_role_binding_spec.rb @@ -28,7 +28,7 @@ describe Gitlab::Kubernetes::ClusterRoleBinding do subject { cluster_role_binding.generate } - it 'should build a Kubeclient Resource' do + it 'builds a Kubeclient Resource' do is_expected.to eq(resource) end end diff --git a/spec/lib/gitlab/kubernetes/config_map_spec.rb b/spec/lib/gitlab/kubernetes/config_map_spec.rb index fe65d03875f..911d6024804 100644 --- a/spec/lib/gitlab/kubernetes/config_map_spec.rb +++ b/spec/lib/gitlab/kubernetes/config_map_spec.rb @@ -18,7 +18,7 @@ describe Gitlab::Kubernetes::ConfigMap do let(:resource) { ::Kubeclient::Resource.new(metadata: metadata, data: application.files) } subject { config_map.generate } - it 'should build a Kubeclient Resource' do + it 'builds a Kubeclient Resource' do is_expected.to eq(resource) end end diff --git a/spec/lib/gitlab/kubernetes/helm/base_command_spec.rb b/spec/lib/gitlab/kubernetes/helm/base_command_spec.rb index aacae78be43..78a4eb44e38 100644 --- a/spec/lib/gitlab/kubernetes/helm/base_command_spec.rb +++ b/spec/lib/gitlab/kubernetes/helm/base_command_spec.rb @@ -41,7 +41,7 @@ describe Gitlab::Kubernetes::Helm::BaseCommand do describe '#pod_resource' do subject { base_command.pod_resource } - it 'should returns a kubeclient resoure with pod content for application' do + it 'returns a kubeclient resoure with pod content for application' do is_expected.to be_an_instance_of ::Kubeclient::Resource end diff --git a/spec/lib/gitlab/kubernetes/helm/certificate_spec.rb b/spec/lib/gitlab/kubernetes/helm/certificate_spec.rb index 167bee22fc3..04649353976 100644 --- a/spec/lib/gitlab/kubernetes/helm/certificate_spec.rb +++ b/spec/lib/gitlab/kubernetes/helm/certificate_spec.rb @@ -5,7 +5,7 @@ describe Gitlab::Kubernetes::Helm::Certificate do describe '.generate_root' do subject { described_class.generate_root } - it 'should generate a root CA that expires a long way in the future' do + it 'generates a root CA that expires a long way in the future' do expect(subject.cert.not_after).to be > 999.years.from_now end end @@ -13,14 +13,14 @@ describe Gitlab::Kubernetes::Helm::Certificate do describe '#issue' do subject { described_class.generate_root.issue } - it 'should generate a cert that expires soon' do + it 'generates a cert that expires soon' do expect(subject.cert.not_after).to be < 60.minutes.from_now end context 'passing in INFINITE_EXPIRY' do subject { described_class.generate_root.issue(expires_in: described_class::INFINITE_EXPIRY) } - it 'should generate a cert that expires a long way in the future' do + it 'generates a cert that expires a long way in the future' do expect(subject.cert.not_after).to be > 999.years.from_now end end diff --git a/spec/lib/gitlab/kubernetes/helm/pod_spec.rb b/spec/lib/gitlab/kubernetes/helm/pod_spec.rb index 95b6b3fd953..06c8d127951 100644 --- a/spec/lib/gitlab/kubernetes/helm/pod_spec.rb +++ b/spec/lib/gitlab/kubernetes/helm/pod_spec.rb @@ -10,11 +10,11 @@ describe Gitlab::Kubernetes::Helm::Pod do subject { described_class.new(command, namespace, service_account_name: service_account_name) } context 'with a command' do - it 'should generate a Kubeclient::Resource' do + it 'generates a Kubeclient::Resource' do expect(subject.generate).to be_a_kind_of(Kubeclient::Resource) end - it 'should generate the appropriate metadata' do + it 'generates the appropriate metadata' do metadata = subject.generate.metadata expect(metadata.name).to eq("install-#{app.name}") expect(metadata.namespace).to eq('gitlab-managed-apps') @@ -22,12 +22,12 @@ describe Gitlab::Kubernetes::Helm::Pod do expect(metadata.labels['gitlab.org/application']).to eq(app.name) end - it 'should generate a container spec' do + it 'generates a container spec' do spec = subject.generate.spec expect(spec.containers.count).to eq(1) end - it 'should generate the appropriate specifications for the container' do + it 'generates the appropriate specifications for the container' do container = subject.generate.spec.containers.first expect(container.name).to eq('helm') expect(container.image).to eq('registry.gitlab.com/gitlab-org/cluster-integration/helm-install-image/releases/2.12.3-kube-1.11.7') @@ -37,30 +37,30 @@ describe Gitlab::Kubernetes::Helm::Pod do expect(container.args).to match_array(["-c", "$(COMMAND_SCRIPT)"]) end - it 'should include a never restart policy' do + it 'includes a never restart policy' do spec = subject.generate.spec expect(spec.restartPolicy).to eq('Never') end - it 'should include volumes for the container' do + it 'includes volumes for the container' do container = subject.generate.spec.containers.first expect(container.volumeMounts.first['name']).to eq('configuration-volume') expect(container.volumeMounts.first['mountPath']).to eq("/data/helm/#{app.name}/config") end - it 'should include a volume inside the specification' do + it 'includes a volume inside the specification' do spec = subject.generate.spec expect(spec.volumes.first['name']).to eq('configuration-volume') end - it 'should mount configMap specification in the volume' do + it 'mounts configMap specification in the volume' do volume = subject.generate.spec.volumes.first expect(volume.configMap['name']).to eq("values-content-configuration-#{app.name}") expect(volume.configMap['items'].first['key']).to eq(:'values.yaml') expect(volume.configMap['items'].first['path']).to eq(:'values.yaml') end - it 'should have no serviceAccountName' do + it 'has no serviceAccountName' do spec = subject.generate.spec expect(spec.serviceAccountName).to be_nil end @@ -68,7 +68,7 @@ describe Gitlab::Kubernetes::Helm::Pod do context 'with a service_account_name' do let(:service_account_name) { 'sa' } - it 'should use the serviceAccountName provided' do + it 'uses the serviceAccountName provided' do spec = subject.generate.spec expect(spec.serviceAccountName).to eq(service_account_name) end diff --git a/spec/lib/gitlab/kubernetes/role_binding_spec.rb b/spec/lib/gitlab/kubernetes/role_binding_spec.rb index a1a59533bfb..50acee254cb 100644 --- a/spec/lib/gitlab/kubernetes/role_binding_spec.rb +++ b/spec/lib/gitlab/kubernetes/role_binding_spec.rb @@ -42,7 +42,7 @@ describe Gitlab::Kubernetes::RoleBinding, '#generate' do ).generate end - it 'should build a Kubeclient Resource' do + it 'builds a Kubeclient Resource' do is_expected.to eq(resource) end end diff --git a/spec/lib/gitlab/kubernetes/service_account_spec.rb b/spec/lib/gitlab/kubernetes/service_account_spec.rb index 8da9e932dc3..0d525966d18 100644 --- a/spec/lib/gitlab/kubernetes/service_account_spec.rb +++ b/spec/lib/gitlab/kubernetes/service_account_spec.rb @@ -17,7 +17,7 @@ describe Gitlab::Kubernetes::ServiceAccount do subject { service_account.generate } - it 'should build a Kubeclient Resource' do + it 'builds a Kubeclient Resource' do is_expected.to eq(resource) end end diff --git a/spec/lib/gitlab/kubernetes/service_account_token_spec.rb b/spec/lib/gitlab/kubernetes/service_account_token_spec.rb index 0773d3d9aec..0d334bed45f 100644 --- a/spec/lib/gitlab/kubernetes/service_account_token_spec.rb +++ b/spec/lib/gitlab/kubernetes/service_account_token_spec.rb @@ -28,7 +28,7 @@ describe Gitlab::Kubernetes::ServiceAccountToken do subject { service_account_token.generate } - it 'should build a Kubeclient Resource' do + it 'builds a Kubeclient Resource' do is_expected.to eq(resource) end end diff --git a/spec/lib/gitlab/object_hierarchy_spec.rb b/spec/lib/gitlab/object_hierarchy_spec.rb index 4700a7ad2e1..e6e9ae3223e 100644 --- a/spec/lib/gitlab/object_hierarchy_spec.rb +++ b/spec/lib/gitlab/object_hierarchy_spec.rb @@ -81,6 +81,24 @@ describe Gitlab::ObjectHierarchy, :postgresql do expect { relation.update_all(share_with_group_lock: false) } .to raise_error(ActiveRecord::ReadOnlyRecord) end + + context 'when with_depth is true' do + let(:relation) do + described_class.new(Group.where(id: parent.id)).base_and_descendants(with_depth: true) + end + + it 'includes depth in the results' do + object_depths = { + parent.id => 1, + child1.id => 2, + child2.id => 3 + } + + relation.each do |object| + expect(object.depth).to eq(object_depths[object.id]) + end + end + end end describe '#descendants' do @@ -91,6 +109,28 @@ describe Gitlab::ObjectHierarchy, :postgresql do end end + describe '#max_descendants_depth' do + subject { described_class.new(base_relation).max_descendants_depth } + + context 'when base relation is empty' do + let(:base_relation) { Group.where(id: nil) } + + it { expect(subject).to be_nil } + end + + context 'when base has no children' do + let(:base_relation) { Group.where(id: child2) } + + it { expect(subject).to eq(1) } + end + + context 'when base has grandchildren' do + let(:base_relation) { Group.where(id: parent) } + + it { expect(subject).to eq(3) } + end + end + describe '#ancestors' do it 'includes only the ancestors' do relation = described_class.new(Group.where(id: child2)).ancestors diff --git a/spec/lib/gitlab/prometheus/queries/knative_invocation_query_spec.rb b/spec/lib/gitlab/prometheus/queries/knative_invocation_query_spec.rb new file mode 100644 index 00000000000..7f6283715f2 --- /dev/null +++ b/spec/lib/gitlab/prometheus/queries/knative_invocation_query_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Prometheus::Queries::KnativeInvocationQuery do + include PrometheusHelpers + + let(:project) { create(:project) } + let(:serverless_func) { Serverless::Function.new(project, 'test-name', 'test-ns') } + + let(:client) { double('prometheus_client') } + subject { described_class.new(client) } + + context 'verify queries' do + before do + allow(PrometheusMetric).to receive(:find_by_identifier).and_return(create(:prometheus_metric, query: prometheus_istio_query('test-name', 'test-ns'))) + allow(client).to receive(:query_range) + end + + it 'has the query, but no data' do + results = subject.query(serverless_func.id) + + expect(results.queries[0][:query_range]).to eql('floor(sum(rate(istio_revision_request_count{destination_configuration="test-name", destination_namespace="test-ns"}[1m])*30))') + end + end +end diff --git a/spec/lib/gitlab/prometheus_client_spec.rb b/spec/lib/gitlab/prometheus_client_spec.rb index 2517ee71f24..f15ae83a02c 100644 --- a/spec/lib/gitlab/prometheus_client_spec.rb +++ b/spec/lib/gitlab/prometheus_client_spec.rb @@ -60,15 +60,13 @@ describe Gitlab::PrometheusClient do end describe 'failure to reach a provided prometheus url' do - let(:prometheus_url) {"https://prometheus.invalid.example.com"} + let(:prometheus_url) {"https://prometheus.invalid.example.com/api/v1/query?query=1"} - subject { described_class.new(RestClient::Resource.new(prometheus_url)) } - - context 'exceptions are raised' do + shared_examples 'exceptions are raised' do it 'raises a Gitlab::PrometheusClient::Error error when a SocketError is rescued' do req_stub = stub_prometheus_request_with_exception(prometheus_url, SocketError) - expect { subject.send(:get, '/', {}) } + expect { subject } .to raise_error(Gitlab::PrometheusClient::Error, "Can't connect to #{prometheus_url}") expect(req_stub).to have_been_requested end @@ -76,7 +74,7 @@ describe Gitlab::PrometheusClient do it 'raises a Gitlab::PrometheusClient::Error error when a SSLError is rescued' do req_stub = stub_prometheus_request_with_exception(prometheus_url, OpenSSL::SSL::SSLError) - expect { subject.send(:get, '/', {}) } + expect { subject } .to raise_error(Gitlab::PrometheusClient::Error, "#{prometheus_url} contains invalid SSL data") expect(req_stub).to have_been_requested end @@ -84,11 +82,23 @@ describe Gitlab::PrometheusClient do it 'raises a Gitlab::PrometheusClient::Error error when a RestClient::Exception is rescued' do req_stub = stub_prometheus_request_with_exception(prometheus_url, RestClient::Exception) - expect { subject.send(:get, '/', {}) } + expect { subject } .to raise_error(Gitlab::PrometheusClient::Error, "Network connection error") expect(req_stub).to have_been_requested end end + + context 'ping' do + subject { described_class.new(RestClient::Resource.new(prometheus_url)).ping } + + it_behaves_like 'exceptions are raised' + end + + context 'proxy' do + subject { described_class.new(RestClient::Resource.new(prometheus_url)).proxy('query', { query: '1' }) } + + it_behaves_like 'exceptions are raised' + end end describe '#query' do @@ -258,4 +268,59 @@ describe Gitlab::PrometheusClient do it { is_expected.to eq(step) } end end + + describe 'proxy' do + context 'get API' do + let(:prometheus_query) { prometheus_cpu_query('env-slug') } + let(:query_url) { prometheus_query_url(prometheus_query) } + + around do |example| + Timecop.freeze { example.run } + end + + context 'when response status code is 200' do + it 'returns response object' do + req_stub = stub_prometheus_request(query_url, body: prometheus_value_body('vector')) + + response = subject.proxy('query', { query: prometheus_query }) + json_response = JSON.parse(response.body) + + expect(response.code).to eq(200) + expect(json_response).to eq({ + 'status' => 'success', + 'data' => { + 'resultType' => 'vector', + 'result' => [{ "metric" => {}, "value" => [1488772511.004, "0.000041021495238095323"] }] + } + }) + expect(req_stub).to have_been_requested + end + end + + context 'when response status code is not 200' do + it 'returns response object' do + req_stub = stub_prometheus_request(query_url, status: 400, body: { error: 'error' }) + + response = subject.proxy('query', { query: prometheus_query }) + json_response = JSON.parse(response.body) + + expect(req_stub).to have_been_requested + expect(response.code).to eq(400) + expect(json_response).to eq('error' => 'error') + end + end + + context 'when RestClient::Exception is raised' do + before do + stub_prometheus_request_with_exception(query_url, RestClient::Exception) + end + + it 'raises PrometheusClient::Error' do + expect { subject.proxy('query', { query: prometheus_query }) }.to( + raise_error(Gitlab::PrometheusClient::Error, 'Network connection error') + ) + end + end + end + end end diff --git a/spec/lib/gitlab/repo_path_spec.rb b/spec/lib/gitlab/repo_path_spec.rb index 4c7ca4e2b57..8fbda929064 100644 --- a/spec/lib/gitlab/repo_path_spec.rb +++ b/spec/lib/gitlab/repo_path_spec.rb @@ -44,8 +44,10 @@ describe ::Gitlab::RepoPath do end end - it "returns nil for non existent paths" do - expect(described_class.parse("path/non-existent.git")).to eq(nil) + it "returns the default type for non existent paths" do + _project, type, _redirected = described_class.parse("path/non-existent.git") + + expect(type).to eq(Gitlab::GlRepository.default_type) end end diff --git a/spec/lib/gitlab/search_results_spec.rb b/spec/lib/gitlab/search_results_spec.rb index 4b57eecff93..312aa3be490 100644 --- a/spec/lib/gitlab/search_results_spec.rb +++ b/spec/lib/gitlab/search_results_spec.rb @@ -97,7 +97,7 @@ describe Gitlab::SearchResults do results.objects('merge_requests') end - it 'it skips project filter if default project context is used' do + it 'skips project filter if default project context is used' do allow(results).to receive(:default_project_filter).and_return(true) expect(results).not_to receive(:project_ids_relation) @@ -113,7 +113,7 @@ describe Gitlab::SearchResults do results.objects('issues') end - it 'it skips project filter if default project context is used' do + it 'skips project filter if default project context is used' do allow(results).to receive(:default_project_filter).and_return(true) expect(results).not_to receive(:project_ids_relation) diff --git a/spec/lib/gitlab/tracing/rails/action_view_subscriber_spec.rb b/spec/lib/gitlab/tracing/rails/action_view_subscriber_spec.rb index c9d1a06b3e6..0bbaf5968ed 100644 --- a/spec/lib/gitlab/tracing/rails/action_view_subscriber_spec.rb +++ b/spec/lib/gitlab/tracing/rails/action_view_subscriber_spec.rb @@ -7,19 +7,19 @@ describe Gitlab::Tracing::Rails::ActionViewSubscriber do using RSpec::Parameterized::TableSyntax shared_examples 'an actionview notification' do - it 'should notify the tracer when the hash contains null values' do + it 'notifies the tracer when the hash contains null values' do expect(subject).to receive(:postnotify_span).with(notification_name, start, finish, tags: expected_tags, exception: exception) subject.public_send(notify_method, start, finish, payload) end - it 'should notify the tracer when the payload is missing values' do + it 'notifies the tracer when the payload is missing values' do expect(subject).to receive(:postnotify_span).with(notification_name, start, finish, tags: expected_tags, exception: exception) subject.public_send(notify_method, start, finish, payload.compact) end - it 'should not throw exceptions when with the default tracer' do + it 'does not throw exceptions when with the default tracer' do expect { subject.public_send(notify_method, start, finish, payload) }.not_to raise_error end end diff --git a/spec/lib/gitlab/tracing/rails/active_record_subscriber_spec.rb b/spec/lib/gitlab/tracing/rails/active_record_subscriber_spec.rb index 3d066843148..7bd0875fa68 100644 --- a/spec/lib/gitlab/tracing/rails/active_record_subscriber_spec.rb +++ b/spec/lib/gitlab/tracing/rails/active_record_subscriber_spec.rb @@ -53,19 +53,19 @@ describe Gitlab::Tracing::Rails::ActiveRecordSubscriber do } end - it 'should notify the tracer when the hash contains null values' do + it 'notifies the tracer when the hash contains null values' do expect(subject).to receive(:postnotify_span).with(operation_name, start, finish, tags: expected_tags, exception: exception) subject.notify(start, finish, payload) end - it 'should notify the tracer when the payload is missing values' do + it 'notifies the tracer when the payload is missing values' do expect(subject).to receive(:postnotify_span).with(operation_name, start, finish, tags: expected_tags, exception: exception) subject.notify(start, finish, payload.compact) end - it 'should not throw exceptions when with the default tracer' do + it 'does not throw exceptions when with the default tracer' do expect { subject.notify(start, finish, payload) }.not_to raise_error end end diff --git a/spec/lib/gitlab/tracing_spec.rb b/spec/lib/gitlab/tracing_spec.rb index 566b5050e47..db75ce2a998 100644 --- a/spec/lib/gitlab/tracing_spec.rb +++ b/spec/lib/gitlab/tracing_spec.rb @@ -14,7 +14,7 @@ describe Gitlab::Tracing do end with_them do - it 'should return the correct state for .enabled?' do + it 'returns the correct state for .enabled?' do expect(described_class).to receive(:connection_string).and_return(connection_string) expect(described_class.enabled?).to eq(enabled_state) @@ -33,7 +33,7 @@ describe Gitlab::Tracing do end with_them do - it 'should return the correct state for .tracing_url_enabled?' do + it 'returns the correct state for .tracing_url_enabled?' do expect(described_class).to receive(:enabled?).and_return(enabled?) allow(described_class).to receive(:tracing_url_template).and_return(tracing_url_template) @@ -56,7 +56,7 @@ describe Gitlab::Tracing do end with_them do - it 'should return the correct state for .tracing_url' do + it 'returns the correct state for .tracing_url' do expect(described_class).to receive(:tracing_url_enabled?).and_return(tracing_url_enabled?) allow(described_class).to receive(:tracing_url_template).and_return(tracing_url_template) allow(Gitlab::CorrelationId).to receive(:current_id).and_return(correlation_id) diff --git a/spec/lib/gitlab/url_sanitizer_spec.rb b/spec/lib/gitlab/url_sanitizer_spec.rb index 6e98a999766..5861e6955a6 100644 --- a/spec/lib/gitlab/url_sanitizer_spec.rb +++ b/spec/lib/gitlab/url_sanitizer_spec.rb @@ -161,7 +161,7 @@ describe Gitlab::UrlSanitizer do end context 'when credentials contains special chars' do - it 'should parse the URL without errors' do + it 'parses the URL without errors' do url_sanitizer = described_class.new("https://foo:b?r@github.com/me/project.git") expect(url_sanitizer.sanitized_url).to eq("https://github.com/me/project.git") diff --git a/spec/lib/sentry/client_spec.rb b/spec/lib/sentry/client_spec.rb index 3333f8307ae..cb14204b99a 100644 --- a/spec/lib/sentry/client_spec.rb +++ b/spec/lib/sentry/client_spec.rb @@ -61,13 +61,37 @@ describe Sentry::Client do end end + shared_examples 'maps exceptions' do + exceptions = { + HTTParty::Error => 'Error when connecting to Sentry', + Net::OpenTimeout => 'Connection to Sentry timed out', + SocketError => 'Received SocketError when trying to connect to Sentry', + OpenSSL::SSL::SSLError => 'Sentry returned invalid SSL data', + Errno::ECONNREFUSED => 'Connection refused', + StandardError => 'Sentry request failed due to StandardError' + } + + exceptions.each do |exception, message| + context "#{exception}" do + before do + stub_request(:get, sentry_request_url).to_raise(exception) + end + + it do + expect { subject } + .to raise_exception(Sentry::Client::Error, message) + end + end + end + end + describe '#list_issues' do let(:issue_status) { 'unresolved' } let(:limit) { 20 } - let(:sentry_api_response) { issues_sample_response } + let(:sentry_request_url) { sentry_url + '/issues/?limit=20&query=is:unresolved' } - let!(:sentry_api_request) { stub_sentry_request(sentry_url + '/issues/?limit=20&query=is:unresolved', body: sentry_api_response) } + let!(:sentry_api_request) { stub_sentry_request(sentry_request_url, body: sentry_api_response) } subject { client.list_issues(issue_status: issue_status, limit: limit) } @@ -121,16 +145,14 @@ describe Sentry::Client do # Sentry API returns 404 if there are extra slashes in the URL! context 'extra slashes in URL' do let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects//sentry-org/sentry-project/' } - let(:client) { described_class.new(sentry_url, token) } - let!(:valid_req_stub) do - stub_sentry_request( - 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project/' \ + let(:sentry_request_url) do + 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project/' \ 'issues/?limit=20&query=is:unresolved' - ) end it 'removes extra slashes in api url' do + expect(client.url).to eq(sentry_url) expect(Gitlab::HTTP).to receive(:get).with( URI('https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project/issues/'), anything @@ -138,7 +160,7 @@ describe Sentry::Client do subject - expect(valid_req_stub).to have_been_requested + expect(sentry_api_request).to have_been_requested end end @@ -169,6 +191,8 @@ describe Sentry::Client do expect { subject }.to raise_error(Sentry::Client::MissingKeysError, 'Sentry API response is missing keys. key not found: "id"') end end + + it_behaves_like 'maps exceptions' end describe '#list_projects' do @@ -260,12 +284,18 @@ describe Sentry::Client do expect(valid_req_stub).to have_been_requested end end + + context 'when exception is raised' do + let(:sentry_request_url) { sentry_list_projects_url } + + it_behaves_like 'maps exceptions' + end end private def stub_sentry_request(url, body: {}, status: 200, headers: {}) - WebMock.stub_request(:get, url) + stub_request(:get, url) .to_return( status: status, headers: { 'Content-Type' => 'application/json' }.merge(headers), |