diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-11-16 16:05:03 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-11-16 16:05:03 +0100 |
commit | d2d64393ed0e64fd63981d5d02fee52fa16a081c (patch) | |
tree | f3e105279a5c0c77cd09a2d7d5757bdf21536d8e /spec/lib | |
parent | d64183e1fa26ab77107e3a2a20be1fe4df3a1875 (diff) | |
parent | b7aae9a6cde71dfc448d8da34ebe38104068387c (diff) | |
download | gitlab-ce-d2d64393ed0e64fd63981d5d02fee52fa16a081c.tar.gz |
Merge remote-tracking branch 'origin/master' into chat-name-authorize
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/artifacts_spec.rb (renamed from spec/lib/gitlab/ci/config/node/artifacts_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/attributable_spec.rb (renamed from spec/lib/gitlab/ci/config/node/attributable_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/boolean_spec.rb (renamed from spec/lib/gitlab/ci/config/node/boolean_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/cache_spec.rb (renamed from spec/lib/gitlab/ci/config/node/cache_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/commands_spec.rb (renamed from spec/lib/gitlab/ci/config/node/commands_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/configurable_spec.rb | 67 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/environment_spec.rb (renamed from spec/lib/gitlab/ci/config/node/environment_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/factory_spec.rb (renamed from spec/lib/gitlab/ci/config/node/factory_spec.rb) | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/global_spec.rb (renamed from spec/lib/gitlab/ci/config/node/global_spec.rb) | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/hidden_spec.rb (renamed from spec/lib/gitlab/ci/config/node/hidden_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/image_spec.rb (renamed from spec/lib/gitlab/ci/config/node/image_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/job_spec.rb (renamed from spec/lib/gitlab/ci/config/node/job_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/jobs_spec.rb (renamed from spec/lib/gitlab/ci/config/node/jobs_spec.rb) | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/key_spec.rb (renamed from spec/lib/gitlab/ci/config/node/key_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/paths_spec.rb (renamed from spec/lib/gitlab/ci/config/node/paths_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/script_spec.rb (renamed from spec/lib/gitlab/ci/config/node/script_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/services_spec.rb (renamed from spec/lib/gitlab/ci/config/node/services_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/stage_spec.rb (renamed from spec/lib/gitlab/ci/config/node/stage_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/stages_spec.rb (renamed from spec/lib/gitlab/ci/config/node/stages_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/trigger_spec.rb (renamed from spec/lib/gitlab/ci/config/node/trigger_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/undefined_spec.rb (renamed from spec/lib/gitlab/ci/config/node/undefined_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/unspecified_spec.rb (renamed from spec/lib/gitlab/ci/config/node/unspecified_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/validatable_spec.rb (renamed from spec/lib/gitlab/ci/config/node/validatable_spec.rb) | 26 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/validator_spec.rb (renamed from spec/lib/gitlab/ci/config/node/validator_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/variables_spec.rb (renamed from spec/lib/gitlab/ci/config/node/variables_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/configurable_spec.rb | 67 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/file_spec.rb | 24 | ||||
-rw-r--r-- | spec/lib/gitlab/ldap/config_spec.rb | 81 | ||||
-rw-r--r-- | spec/lib/gitlab/o_auth/user_spec.rb | 23 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_throttler_spec.rb | 28 |
30 files changed, 270 insertions, 116 deletions
diff --git a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb b/spec/lib/gitlab/ci/config/entry/artifacts_spec.rb index c09a0a9c793..5c31423fdee 100644 --- a/spec/lib/gitlab/ci/config/node/artifacts_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/artifacts_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Artifacts do +describe Gitlab::Ci::Config::Entry::Artifacts do let(:entry) { described_class.new(config) } describe 'validation' do diff --git a/spec/lib/gitlab/ci/config/node/attributable_spec.rb b/spec/lib/gitlab/ci/config/entry/attributable_spec.rb index 24d9daafd88..fde03c51e2c 100644 --- a/spec/lib/gitlab/ci/config/node/attributable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/attributable_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Attributable do +describe Gitlab::Ci::Config::Entry::Attributable do let(:node) { Class.new } let(:instance) { node.new } diff --git a/spec/lib/gitlab/ci/config/node/boolean_spec.rb b/spec/lib/gitlab/ci/config/entry/boolean_spec.rb index deafa8bf8a7..5f067cad93c 100644 --- a/spec/lib/gitlab/ci/config/node/boolean_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/boolean_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Boolean do +describe Gitlab::Ci::Config::Entry::Boolean do let(:entry) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/cache_spec.rb b/spec/lib/gitlab/ci/config/entry/cache_spec.rb index e251210949c..70a327c5183 100644 --- a/spec/lib/gitlab/ci/config/node/cache_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/cache_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Cache do +describe Gitlab::Ci::Config::Entry::Cache do let(:entry) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/commands_spec.rb b/spec/lib/gitlab/ci/config/entry/commands_spec.rb index e373c40706f..b8b0825a1c7 100644 --- a/spec/lib/gitlab/ci/config/node/commands_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/commands_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Commands do +describe Gitlab::Ci::Config::Entry::Commands do let(:entry) { described_class.new(config) } context 'when entry config value is an array' do diff --git a/spec/lib/gitlab/ci/config/entry/configurable_spec.rb b/spec/lib/gitlab/ci/config/entry/configurable_spec.rb new file mode 100644 index 00000000000..ae7e628b5b5 --- /dev/null +++ b/spec/lib/gitlab/ci/config/entry/configurable_spec.rb @@ -0,0 +1,67 @@ +require 'spec_helper' + +describe Gitlab::Ci::Config::Entry::Configurable do + let(:entry) { Class.new } + + before do + entry.include(described_class) + end + + describe 'validations' do + let(:validator) { entry.validator.new(instance) } + + before do + entry.class_eval do + attr_reader :config + + def initialize(config) + @config = config + end + end + + validator.validate + end + + context 'when entry validator is invalid' do + let(:instance) { entry.new('ls') } + + it 'returns invalid validator' do + expect(validator).to be_invalid + end + end + + context 'when entry instance is valid' do + let(:instance) { entry.new(key: 'value') } + + it 'returns valid validator' do + expect(validator).to be_valid + end + end + end + + describe 'configured entries' do + before do + entry.class_eval do + entry :object, Object, description: 'test object' + end + end + + describe '.nodes' do + it 'has valid nodes' do + expect(entry.nodes).to include :object + end + + it 'creates a node factory' do + expect(entry.nodes[:object]) + .to be_an_instance_of Gitlab::Ci::Config::Entry::Factory + end + + it 'returns a duplicated factory object' do + first_factory = entry.nodes[:object] + second_factory = entry.nodes[:object] + + expect(first_factory).not_to be_equal(second_factory) + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/node/environment_spec.rb b/spec/lib/gitlab/ci/config/entry/environment_spec.rb index df925ff1afd..d97806295fb 100644 --- a/spec/lib/gitlab/ci/config/node/environment_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/environment_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Environment do +describe Gitlab::Ci::Config::Entry::Environment do let(:entry) { described_class.new(config) } before { entry.compose! } diff --git a/spec/lib/gitlab/ci/config/node/factory_spec.rb b/spec/lib/gitlab/ci/config/entry/factory_spec.rb index a699089c563..00dad5d9591 100644 --- a/spec/lib/gitlab/ci/config/node/factory_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/factory_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Factory do +describe Gitlab::Ci::Config::Entry::Factory do describe '#create!' do - let(:factory) { described_class.new(node) } - let(:node) { Gitlab::Ci::Config::Node::Script } + let(:factory) { described_class.new(entry) } + let(:entry) { Gitlab::Ci::Config::Entry::Script } context 'when setting a concrete value' do it 'creates entry with valid value' do @@ -54,7 +54,7 @@ describe Gitlab::Ci::Config::Node::Factory do context 'when not setting a value' do it 'raises error' do expect { factory.create! }.to raise_error( - Gitlab::Ci::Config::Node::Factory::InvalidFactory + Gitlab::Ci::Config::Entry::Factory::InvalidFactory ) end end @@ -66,12 +66,12 @@ describe Gitlab::Ci::Config::Node::Factory do .create! expect(entry) - .to be_an_instance_of Gitlab::Ci::Config::Node::Unspecified + .to be_an_instance_of Gitlab::Ci::Config::Entry::Unspecified end end context 'when passing metadata' do - let(:node) { spy('node') } + let(:entry) { spy('entry') } it 'passes metadata as a parameter' do factory @@ -79,7 +79,7 @@ describe Gitlab::Ci::Config::Node::Factory do .metadata(some: 'hash') .create! - expect(node).to have_received(:new) + expect(entry).to have_received(:new) .with('some value', { some: 'hash' }) end end diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/entry/global_spec.rb index 12232ff7e2f..c7726adfd27 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/global_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Global do +describe Gitlab::Ci::Config::Entry::Global do let(:global) { described_class.new(hash) } describe '.nodes' do @@ -40,9 +40,9 @@ describe Gitlab::Ci::Config::Node::Global do it 'creates node object using valid class' do expect(global.descendants.first) - .to be_an_instance_of Gitlab::Ci::Config::Node::Script + .to be_an_instance_of Gitlab::Ci::Config::Entry::Script expect(global.descendants.second) - .to be_an_instance_of Gitlab::Ci::Config::Node::Image + .to be_an_instance_of Gitlab::Ci::Config::Entry::Image end it 'sets correct description for nodes' do @@ -181,7 +181,7 @@ describe Gitlab::Ci::Config::Node::Global do it 'contains unspecified nodes' do expect(global.descendants.first) - .to be_an_instance_of Gitlab::Ci::Config::Node::Unspecified + .to be_an_instance_of Gitlab::Ci::Config::Entry::Unspecified end end @@ -284,7 +284,7 @@ describe Gitlab::Ci::Config::Node::Global do context 'when node exists' do it 'returns correct entry' do expect(global[:cache]) - .to be_an_instance_of Gitlab::Ci::Config::Node::Cache + .to be_an_instance_of Gitlab::Ci::Config::Entry::Cache expect(global[:jobs][:rspec][:script].value).to eq ['ls'] end end diff --git a/spec/lib/gitlab/ci/config/node/hidden_spec.rb b/spec/lib/gitlab/ci/config/entry/hidden_spec.rb index 61e2a554419..459362761e6 100644 --- a/spec/lib/gitlab/ci/config/node/hidden_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/hidden_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Hidden do +describe Gitlab::Ci::Config::Entry::Hidden do let(:entry) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/image_spec.rb b/spec/lib/gitlab/ci/config/entry/image_spec.rb index d11bb39f328..3c99cb0a1ee 100644 --- a/spec/lib/gitlab/ci/config/node/image_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/image_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Image do +describe Gitlab::Ci::Config::Entry::Image do let(:entry) { described_class.new(config) } describe 'validation' do diff --git a/spec/lib/gitlab/ci/config/node/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb index 91f676dae03..c05711b6338 100644 --- a/spec/lib/gitlab/ci/config/node/job_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Job do +describe Gitlab::Ci::Config::Entry::Job do let(:entry) { described_class.new(config, name: :rspec) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/jobs_spec.rb b/spec/lib/gitlab/ci/config/entry/jobs_spec.rb index 929809339ef..aaebf783962 100644 --- a/spec/lib/gitlab/ci/config/node/jobs_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/jobs_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Jobs do +describe Gitlab::Ci::Config::Entry::Jobs do let(:entry) { described_class.new(config) } describe 'validations' do @@ -74,9 +74,9 @@ describe Gitlab::Ci::Config::Node::Jobs do it 'creates valid descendant nodes' do expect(entry.descendants.count).to eq 3 expect(entry.descendants.first(2)) - .to all(be_an_instance_of(Gitlab::Ci::Config::Node::Job)) + .to all(be_an_instance_of(Gitlab::Ci::Config::Entry::Job)) expect(entry.descendants.last) - .to be_an_instance_of(Gitlab::Ci::Config::Node::Hidden) + .to be_an_instance_of(Gitlab::Ci::Config::Entry::Hidden) end end diff --git a/spec/lib/gitlab/ci/config/node/key_spec.rb b/spec/lib/gitlab/ci/config/entry/key_spec.rb index 8cda43173fe..a55e5b4b8ac 100644 --- a/spec/lib/gitlab/ci/config/node/key_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/key_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Key do +describe Gitlab::Ci::Config::Entry::Key do let(:entry) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/paths_spec.rb b/spec/lib/gitlab/ci/config/entry/paths_spec.rb index 6fd744b3975..e60c9aaf661 100644 --- a/spec/lib/gitlab/ci/config/node/paths_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/paths_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Paths do +describe Gitlab::Ci::Config::Entry::Paths do let(:entry) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/script_spec.rb b/spec/lib/gitlab/ci/config/entry/script_spec.rb index 219a7e981d3..aa99cee2690 100644 --- a/spec/lib/gitlab/ci/config/node/script_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/script_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Script do +describe Gitlab::Ci::Config::Entry::Script do let(:entry) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/services_spec.rb b/spec/lib/gitlab/ci/config/entry/services_spec.rb index be0fe46befd..66fad3b6b16 100644 --- a/spec/lib/gitlab/ci/config/node/services_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/services_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Services do +describe Gitlab::Ci::Config::Entry::Services do let(:entry) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/stage_spec.rb b/spec/lib/gitlab/ci/config/entry/stage_spec.rb index fb9ec70762a..70c8a0a355a 100644 --- a/spec/lib/gitlab/ci/config/node/stage_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/stage_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Stage do +describe Gitlab::Ci::Config::Entry::Stage do let(:stage) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/stages_spec.rb b/spec/lib/gitlab/ci/config/entry/stages_spec.rb index 1a3818d8997..182c8d867c7 100644 --- a/spec/lib/gitlab/ci/config/node/stages_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/stages_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Stages do +describe Gitlab::Ci::Config::Entry::Stages do let(:entry) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/trigger_spec.rb b/spec/lib/gitlab/ci/config/entry/trigger_spec.rb index a4a3e36754e..e4ee44f1274 100644 --- a/spec/lib/gitlab/ci/config/node/trigger_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/trigger_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Trigger do +describe Gitlab::Ci::Config::Entry::Trigger do let(:entry) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/undefined_spec.rb b/spec/lib/gitlab/ci/config/entry/undefined_spec.rb index 6bde8602963..fdf48d84192 100644 --- a/spec/lib/gitlab/ci/config/node/undefined_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/undefined_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Undefined do +describe Gitlab::Ci::Config::Entry::Undefined do let(:entry) { described_class.new } describe '#leaf?' do diff --git a/spec/lib/gitlab/ci/config/node/unspecified_spec.rb b/spec/lib/gitlab/ci/config/entry/unspecified_spec.rb index ba3ceef24ce..66f88fa35b6 100644 --- a/spec/lib/gitlab/ci/config/node/unspecified_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/unspecified_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Unspecified do +describe Gitlab::Ci::Config::Entry::Unspecified do let(:unspecified) { described_class.new(entry) } let(:entry) { spy('Entry') } diff --git a/spec/lib/gitlab/ci/config/node/validatable_spec.rb b/spec/lib/gitlab/ci/config/entry/validatable_spec.rb index 64b77fd6e03..d1856801827 100644 --- a/spec/lib/gitlab/ci/config/node/validatable_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/validatable_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Validatable do - let(:node) { Class.new } +describe Gitlab::Ci::Config::Entry::Validatable do + let(:entry) { Class.new } before do - node.include(described_class) + entry.include(described_class) end describe '.validator' do before do - node.class_eval do + entry.class_eval do attr_accessor :test_attribute validations do @@ -19,34 +19,34 @@ describe Gitlab::Ci::Config::Node::Validatable do end it 'returns validator' do - expect(node.validator.superclass) - .to be Gitlab::Ci::Config::Node::Validator + expect(entry.validator.superclass) + .to be Gitlab::Ci::Config::Entry::Validator end it 'returns only one validator to mitigate leaks' do - expect { node.validator }.not_to change { node.validator } + expect { entry.validator }.not_to change { entry.validator } end - context 'when validating node instance' do - let(:node_instance) { node.new } + context 'when validating entry instance' do + let(:entry_instance) { entry.new } context 'when attribute is valid' do before do - node_instance.test_attribute = 'valid' + entry_instance.test_attribute = 'valid' end it 'instance of validator is valid' do - expect(node.validator.new(node_instance)).to be_valid + expect(entry.validator.new(entry_instance)).to be_valid end end context 'when attribute is not valid' do before do - node_instance.test_attribute = nil + entry_instance.test_attribute = nil end it 'instance of validator is invalid' do - expect(node.validator.new(node_instance)).to be_invalid + expect(entry.validator.new(entry_instance)).to be_invalid end end end diff --git a/spec/lib/gitlab/ci/config/node/validator_spec.rb b/spec/lib/gitlab/ci/config/entry/validator_spec.rb index 090fd63b844..ad7e6f07d3c 100644 --- a/spec/lib/gitlab/ci/config/node/validator_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/validator_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Validator do +describe Gitlab::Ci::Config::Entry::Validator do let(:validator) { Class.new(described_class) } let(:validator_instance) { validator.new(node) } let(:node) { spy('node') } diff --git a/spec/lib/gitlab/ci/config/node/variables_spec.rb b/spec/lib/gitlab/ci/config/entry/variables_spec.rb index 4b6d971ec71..58327d08904 100644 --- a/spec/lib/gitlab/ci/config/node/variables_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/variables_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Ci::Config::Node::Variables do +describe Gitlab::Ci::Config::Entry::Variables do let(:entry) { described_class.new(config) } describe 'validations' do diff --git a/spec/lib/gitlab/ci/config/node/configurable_spec.rb b/spec/lib/gitlab/ci/config/node/configurable_spec.rb deleted file mode 100644 index c468ecf957b..00000000000 --- a/spec/lib/gitlab/ci/config/node/configurable_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Ci::Config::Node::Configurable do - let(:node) { Class.new } - - before do - node.include(described_class) - end - - describe 'validations' do - let(:validator) { node.validator.new(instance) } - - before do - node.class_eval do - attr_reader :config - - def initialize(config) - @config = config - end - end - - validator.validate - end - - context 'when node validator is invalid' do - let(:instance) { node.new('ls') } - - it 'returns invalid validator' do - expect(validator).to be_invalid - end - end - - context 'when node instance is valid' do - let(:instance) { node.new(key: 'value') } - - it 'returns valid validator' do - expect(validator).to be_valid - end - end - end - - describe 'configured nodes' do - before do - node.class_eval do - node :object, Object, description: 'test object' - end - end - - describe '.nodes' do - it 'has valid nodes' do - expect(node.nodes).to include :object - end - - it 'creates a node factory' do - expect(node.nodes[:object]) - .to be_an_instance_of Gitlab::Ci::Config::Node::Factory - end - - it 'returns a duplicated factory object' do - first_factory = node.nodes[:object] - second_factory = node.nodes[:object] - - expect(first_factory).not_to be_equal(second_factory) - end - end - end -end diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb index 0650cb291e5..38475792d93 100644 --- a/spec/lib/gitlab/diff/file_spec.rb +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -46,4 +46,28 @@ describe Gitlab::Diff::File, lib: true do expect(diff_file.collapsed?).to eq(false) end end + + describe '#old_content_commit' do + it 'returns base commit' do + old_content_commit = diff_file.old_content_commit + + expect(old_content_commit.id).to eq('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') + end + end + + describe '#old_blob' do + it 'returns blob of commit of base commit' do + old_data = diff_file.old_blob.data + + expect(old_data).to include('raise "System commands must be given as an array of strings"') + end + end + + describe '#blob' do + it 'returns blob of new commit' do + data = diff_file.blob.data + + expect(data).to include('raise RuntimeError, "System commands must be given as an array of strings"') + end + end end diff --git a/spec/lib/gitlab/ldap/config_spec.rb b/spec/lib/gitlab/ldap/config_spec.rb index f5ebe703083..1a6803e01c3 100644 --- a/spec/lib/gitlab/ldap/config_spec.rb +++ b/spec/lib/gitlab/ldap/config_spec.rb @@ -19,6 +19,87 @@ describe Gitlab::LDAP::Config, lib: true do end end + describe '#adapter_options' do + it 'constructs basic options' do + stub_ldap_config( + options: { + 'host' => 'ldap.example.com', + 'port' => 386, + 'method' => 'plain' + } + ) + + expect(config.adapter_options).to eq( + host: 'ldap.example.com', + port: 386, + encryption: nil + ) + end + + it 'includes authentication options when auth is configured' do + stub_ldap_config( + options: { + 'host' => 'ldap.example.com', + 'port' => 686, + 'method' => 'ssl', + 'bind_dn' => 'uid=admin,dc=example,dc=com', + 'password' => 'super_secret' + } + ) + + expect(config.adapter_options).to eq( + host: 'ldap.example.com', + port: 686, + encryption: :simple_tls, + auth: { + method: :simple, + username: 'uid=admin,dc=example,dc=com', + password: 'super_secret' + } + ) + end + end + + describe '#omniauth_options' do + it 'constructs basic options' do + stub_ldap_config( + options: { + 'host' => 'ldap.example.com', + 'port' => 386, + 'base' => 'ou=users,dc=example,dc=com', + 'method' => 'plain', + 'uid' => 'uid' + } + ) + + expect(config.omniauth_options).to include( + host: 'ldap.example.com', + port: 386, + base: 'ou=users,dc=example,dc=com', + method: 'plain', + filter: '(uid=%{username})' + ) + expect(config.omniauth_options.keys).not_to include(:bind_dn, :password) + end + + it 'includes authentication options when auth is configured' do + stub_ldap_config( + options: { + 'uid' => 'sAMAccountName', + 'user_filter' => '(memberOf=cn=group1,ou=groups,dc=example,dc=com)', + 'bind_dn' => 'uid=admin,dc=example,dc=com', + 'password' => 'super_secret' + } + ) + + expect(config.omniauth_options).to include( + filter: '(&(sAMAccountName=%{username})(memberOf=cn=group1,ou=groups,dc=example,dc=com))', + bind_dn: 'uid=admin,dc=example,dc=com', + password: 'super_secret' + ) + end + end + describe '#has_auth?' do it 'is true when password is set' do stub_ldap_config( diff --git a/spec/lib/gitlab/o_auth/user_spec.rb b/spec/lib/gitlab/o_auth/user_spec.rb index 78c669e8fa5..fc9e1cb430a 100644 --- a/spec/lib/gitlab/o_auth/user_spec.rb +++ b/spec/lib/gitlab/o_auth/user_spec.rb @@ -137,11 +137,12 @@ describe Gitlab::OAuth::User, lib: true do allow(ldap_user).to receive(:username) { uid } allow(ldap_user).to receive(:email) { ['johndoe@example.com', 'john2@example.com'] } allow(ldap_user).to receive(:dn) { 'uid=user1,ou=People,dc=example' } - allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(ldap_user) end context "and no account for the LDAP user" do it "creates a user with dual LDAP and omniauth identities" do + allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(ldap_user) + oauth_user.save expect(gl_user).to be_valid @@ -159,6 +160,8 @@ describe Gitlab::OAuth::User, lib: true do context "and LDAP user has an account already" do let!(:existing_user) { create(:omniauth_user, email: 'john@example.com', extern_uid: 'uid=user1,ou=People,dc=example', provider: 'ldapmain', username: 'john') } it "adds the omniauth identity to the LDAP account" do + allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(ldap_user) + oauth_user.save expect(gl_user).to be_valid @@ -172,6 +175,24 @@ describe Gitlab::OAuth::User, lib: true do ]) end end + + context 'when an LDAP person is not found by uid' do + it 'tries to find an LDAP person by DN and adds the omniauth identity to the user' do + allow(Gitlab::LDAP::Person).to receive(:find_by_uid).and_return(nil) + allow(Gitlab::LDAP::Person).to receive(:find_by_dn).and_return(ldap_user) + + oauth_user.save + + identities_as_hash = gl_user.identities.map { |id| { provider: id.provider, extern_uid: id.extern_uid } } + expect(identities_as_hash) + .to match_array( + [ + { provider: 'ldapmain', extern_uid: 'uid=user1,ou=People,dc=example' }, + { provider: 'twitter', extern_uid: uid } + ] + ) + end + end end context "and no corresponding LDAP person" do diff --git a/spec/lib/gitlab/sidekiq_throttler_spec.rb b/spec/lib/gitlab/sidekiq_throttler_spec.rb new file mode 100644 index 00000000000..ff32e0e699d --- /dev/null +++ b/spec/lib/gitlab/sidekiq_throttler_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe Gitlab::SidekiqThrottler do + before do + Sidekiq.options[:concurrency] = 35 + + stub_application_setting( + sidekiq_throttling_enabled: true, + sidekiq_throttling_factor: 0.1, + sidekiq_throttling_queues: %w[build project_cache] + ) + end + + describe '#execute!' do + it 'sets limits on the selected queues' do + Gitlab::SidekiqThrottler.execute! + + expect(Sidekiq::Queue['build'].limit).to eq 4 + expect(Sidekiq::Queue['project_cache'].limit).to eq 4 + end + + it 'does not set limits on other queues' do + Gitlab::SidekiqThrottler.execute! + + expect(Sidekiq::Queue['merge'].limit).to be_nil + end + end +end |