diff options
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/inherit/default_spec.rb | 42 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/inherit/variables_spec.rb | 42 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/job_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/processable_spec.rb | 57 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 48 | ||||
-rw-r--r-- | spec/lib/gitlab/middleware/go_spec.rb | 11 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb | 11 |
7 files changed, 181 insertions, 32 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/inherit/default_spec.rb b/spec/lib/gitlab/ci/config/entry/inherit/default_spec.rb new file mode 100644 index 00000000000..073f93ce542 --- /dev/null +++ b/spec/lib/gitlab/ci/config/entry/inherit/default_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ::Gitlab::Ci::Config::Entry::Inherit::Default do + using RSpec::Parameterized::TableSyntax + + subject { described_class.new(config) } + + context 'validations' do + where(:config, :valid) do + true | true + false | true + %w[image] | true + %w[unknown] | false + %i[image] | false + [true] | false + "string" | false + end + + with_them do + it do + expect(subject.valid?).to eq(valid) + end + end + end + + describe '#inherit?' do + where(:config, :inherit) do + true | true + false | false + %w[image] | true + %w[before_script] | false + end + + with_them do + it do + expect(subject.inherit?('image')).to eq(inherit) + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/entry/inherit/variables_spec.rb b/spec/lib/gitlab/ci/config/entry/inherit/variables_spec.rb new file mode 100644 index 00000000000..06deed11c15 --- /dev/null +++ b/spec/lib/gitlab/ci/config/entry/inherit/variables_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ::Gitlab::Ci::Config::Entry::Inherit::Variables do + using RSpec::Parameterized::TableSyntax + + subject { described_class.new(config) } + + context 'validations' do + where(:config, :valid) do + true | true + false | true + %w[A] | true + %w[A B] | true + %i[image] | true + [true] | false + "string" | false + end + + with_them do + it do + expect(subject.valid?).to eq(valid) + end + end + end + + describe '#inherit?' do + where(:config, :inherit) do + true | true + false | false + %w[A] | true + %w[B] | false + end + + with_them do + it do + expect(subject.inherit?('A')).to eq(inherit) + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb index 7df0eccb3ed..b6279485426 100644 --- a/spec/lib/gitlab/ci/config/entry/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -18,7 +18,7 @@ describe Gitlab::Ci::Config::Entry::Job do end before do - allow(entry).to receive_message_chain(:inherit_entry, :default_value).and_return(true) + allow(entry).to receive_message_chain(:inherit_entry, :default_entry, :inherit?).and_return(true) end end diff --git a/spec/lib/gitlab/ci/config/entry/processable_spec.rb b/spec/lib/gitlab/ci/config/entry/processable_spec.rb index 5c2c6520f25..8447a29c772 100644 --- a/spec/lib/gitlab/ci/config/entry/processable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/processable_spec.rb @@ -269,13 +269,13 @@ describe Gitlab::Ci::Config::Entry::Processable do context 'when root yaml variables are used' do let(:variables) do Gitlab::Ci::Config::Entry::Variables.new( - A: 'root', C: 'root' + A: 'root', C: 'root', D: 'root' ).value end it 'does return all variables and overwrite them' do expect(entry.value).to include( - variables: { 'A' => 'job', 'B' => 'job', 'C' => 'root' } + variables: { 'A' => 'job', 'B' => 'job', 'C' => 'root', 'D' => 'root' } ) end @@ -293,32 +293,61 @@ describe Gitlab::Ci::Config::Entry::Processable do ) end end + + context 'when inherit of only specific variable is enabled' do + let(:config) do + { + variables: { A: 'job', B: 'job' }, + inherit: { variables: ['D'] } + } + end + + it 'does return only job variables' do + expect(entry.value).to include( + variables: { 'A' => 'job', 'B' => 'job', 'D' => 'root' } + ) + end + end end end context 'of default:tags' do using RSpec::Parameterized::TableSyntax - where(:default_tags, :tags, :inherit_default, :result) do - nil | %w[a b] | nil | %w[a b] - nil | %w[a b] | true | %w[a b] - nil | %w[a b] | false | %w[a b] - %w[b c] | %w[a b] | nil | %w[a b] - %w[b c] | %w[a b] | true | %w[a b] - %w[b c] | %w[a b] | false | %w[a b] - %w[b c] | nil | nil | %w[b c] - %w[b c] | nil | true | %w[b c] - %w[b c] | nil | false | nil + where(:name, :default_tags, :tags, :inherit_default, :result) do + "only local tags" | nil | %w[a b] | nil | %w[a b] + "only local tags" | nil | %w[a b] | true | %w[a b] + "only local tags" | nil | %w[a b] | false | %w[a b] + "global and local tags" | %w[b c] | %w[a b] | nil | %w[a b] + "global and local tags" | %w[b c] | %w[a b] | true | %w[a b] + "global and local tags" | %w[b c] | %w[a b] | false | %w[a b] + "only global tags" | %w[b c] | nil | nil | %w[b c] + "only global tags" | %w[b c] | nil | true | %w[b c] + "only global tags" | %w[b c] | nil | false | nil + "only global tags" | %w[b c] | nil | %w[image] | nil + "only global tags" | %w[b c] | nil | %w[tags] | %w[b c] end with_them do - let(:config) { { tags: tags, inherit: { default: inherit_default } } } - let(:default_specified_tags) { double('tags', 'specified?' => true, 'valid?' => true, 'value' => default_tags) } + let(:config) do + { tags: tags, + inherit: { default: inherit_default } } + end + + let(:default_specified_tags) do + double('tags', + 'specified?' => true, + 'valid?' => true, + 'value' => default_tags, + 'errors' => []) + end before do allow(default).to receive('[]').with(:tags).and_return(default_specified_tags) entry.compose!(deps) + + expect(entry).to be_valid end it { expect(entry.tags_value).to eq(result) } diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 5c85a136972..af0a85f6c4e 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -515,6 +515,8 @@ module Gitlab nil | ["global script"] { default: false } | nil { default: true } | ["global script"] + { default: %w[before_script] } | ["global script"] + { default: %w[image] } | nil end with_them do @@ -527,26 +529,28 @@ module Gitlab it { expect(subject[:options][:before_script]).to eq(result) } end - end - context "in default context" do - using RSpec::Parameterized::TableSyntax + context "in default context" do + using RSpec::Parameterized::TableSyntax - where(:inherit, :result) do - nil | ["global script"] - { default: false } | nil - { default: true } | ["global script"] - end - - with_them do - let(:config) do - { - default: { before_script: ["global script"] }, - test: { script: ["script"], inherit: inherit } - } + where(:inherit, :result) do + nil | ["global script"] + { default: false } | nil + { default: true } | ["global script"] + { default: %w[before_script] } | ["global script"] + { default: %w[image] } | nil end - it { expect(subject[:options][:before_script]).to eq(result) } + with_them do + let(:config) do + { + default: { before_script: ["global script"] }, + test: { script: ["script"], inherit: inherit } + } + end + + it { expect(subject[:options][:before_script]).to eq(result) } + end end end @@ -845,6 +849,18 @@ module Gitlab ) end end + + context 'when specific variables are to inherited' do + let(:inherit) { { variables: %w[VAR1 VAR4] } } + + it 'returns all unique variables and inherits only specified variables' do + expect(subject).to contain_exactly( + { key: 'VAR4', value: 'global4', public: true }, + { key: 'VAR1', value: 'value1', public: true }, + { key: 'VAR2', value: 'value2', public: true } + ) + end + end end context 'when job variables are defined' do diff --git a/spec/lib/gitlab/middleware/go_spec.rb b/spec/lib/gitlab/middleware/go_spec.rb index 99c2a364dfc..43a489f6df0 100644 --- a/spec/lib/gitlab/middleware/go_spec.rb +++ b/spec/lib/gitlab/middleware/go_spec.rb @@ -89,6 +89,13 @@ describe Gitlab::Middleware::Go do it 'returns the full project path' do expect_response_with_path(go, enabled_protocol, project.full_path, project.default_branch) end + + context 'with an empty ssh_user' do + it 'returns the full project path' do + allow(Gitlab.config.gitlab_shell).to receive(:ssh_user).and_return('') + expect_response_with_path(go, enabled_protocol, project.full_path, project.default_branch) + end + end end context 'without access to the project' do @@ -234,7 +241,9 @@ describe Gitlab::Middleware::Go do def expect_response_with_path(response, protocol, path, branch) repository_url = case protocol when :ssh - "ssh://#{Gitlab.config.gitlab.user}@#{Gitlab.config.gitlab.host}/#{path}.git" + shell = Gitlab.config.gitlab_shell + user = "#{shell.ssh_user}@" unless shell.ssh_user.empty? + "ssh://#{user}#{shell.ssh_host}/#{path}.git" when :http, nil "http://#{Gitlab.config.gitlab.host}/#{path}.git" end diff --git a/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb b/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb index 47442f4ee86..d815534e873 100644 --- a/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware/server_metrics_spec.rb @@ -20,6 +20,8 @@ describe Gitlab::SidekiqMiddleware::ServerMetrics do let(:queue_duration_seconds) { double('queue duration seconds metric') } let(:completion_seconds_metric) { double('completion seconds metric') } let(:user_execution_seconds_metric) { double('user execution seconds metric') } + let(:db_seconds_metric) { double('db seconds metric') } + let(:gitaly_seconds_metric) { double('gitaly seconds metric') } let(:failed_total_metric) { double('failed total metric') } let(:retried_total_metric) { double('retried total metric') } let(:running_jobs_metric) { double('running jobs metric') } @@ -28,6 +30,8 @@ describe Gitlab::SidekiqMiddleware::ServerMetrics do allow(Gitlab::Metrics).to receive(:histogram).with(:sidekiq_jobs_queue_duration_seconds, anything, anything, anything).and_return(queue_duration_seconds) allow(Gitlab::Metrics).to receive(:histogram).with(:sidekiq_jobs_completion_seconds, anything, anything, anything).and_return(completion_seconds_metric) allow(Gitlab::Metrics).to receive(:histogram).with(:sidekiq_jobs_cpu_seconds, anything, anything, anything).and_return(user_execution_seconds_metric) + allow(Gitlab::Metrics).to receive(:histogram).with(:sidekiq_jobs_db_seconds, anything, anything, anything).and_return(db_seconds_metric) + allow(Gitlab::Metrics).to receive(:histogram).with(:sidekiq_jobs_gitaly_seconds, anything, anything, anything).and_return(gitaly_seconds_metric) allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_jobs_failed_total, anything).and_return(failed_total_metric) allow(Gitlab::Metrics).to receive(:counter).with(:sidekiq_jobs_retried_total, anything).and_return(retried_total_metric) allow(Gitlab::Metrics).to receive(:gauge).with(:sidekiq_running_jobs, anything, {}, :all).and_return(running_jobs_metric) @@ -55,16 +59,23 @@ describe Gitlab::SidekiqMiddleware::ServerMetrics do let(:queue_duration_for_job) { 0.01 } + let(:db_duration) { 3 } + let(:gitaly_duration) { 4 } + before do allow(subject).to receive(:get_thread_cputime).and_return(thread_cputime_before, thread_cputime_after) allow(Gitlab::Metrics::System).to receive(:monotonic_time).and_return(monotonic_time_before, monotonic_time_after) allow(Gitlab::InstrumentationHelper).to receive(:queue_duration_for_job).with(job).and_return(queue_duration_for_job) + allow(ActiveRecord::LogSubscriber).to receive(:runtime).and_return(db_duration * 1000) + allow(Gitlab::GitalyClient).to receive(:query_time).and_return(gitaly_duration) expect(running_jobs_metric).to receive(:increment).with(labels, 1) expect(running_jobs_metric).to receive(:increment).with(labels, -1) expect(queue_duration_seconds).to receive(:observe).with(labels, queue_duration_for_job) if queue_duration_for_job expect(user_execution_seconds_metric).to receive(:observe).with(labels_with_job_status, thread_cputime_duration) + expect(db_seconds_metric).to receive(:observe).with(labels_with_job_status, db_duration) + expect(gitaly_seconds_metric).to receive(:observe).with(labels_with_job_status, gitaly_duration) expect(completion_seconds_metric).to receive(:observe).with(labels_with_job_status, monotonic_time_duration) end |