diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-27 15:06:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-27 15:06:45 +0000 |
commit | a98649b71085bcd21af674a47d6a746336c56a65 (patch) | |
tree | 1e518ce4f61a8d7260ba9d6d3b8db8906251d6a0 /spec/lib/gitlab/ci/config/entry/need_spec.rb | |
parent | a4484fd22dd0d055a10fe084b82349e42f7363e1 (diff) | |
download | gitlab-ce-a98649b71085bcd21af674a47d6a746336c56a65.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/ci/config/entry/need_spec.rb')
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/need_spec.rb | 168 |
1 files changed, 157 insertions, 11 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/need_spec.rb b/spec/lib/gitlab/ci/config/entry/need_spec.rb index d119e604900..92b71c5f6cc 100644 --- a/spec/lib/gitlab/ci/config/entry/need_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/need_spec.rb @@ -5,31 +5,177 @@ require 'spec_helper' describe ::Gitlab::Ci::Config::Entry::Need do subject(:need) { described_class.new(config) } - context 'when job is specified' do - let(:config) { 'job_name' } + shared_examples 'job type' do + describe '#type' do + subject(:need_type) { need.type } - describe '#valid?' do - it { is_expected.to be_valid } + it { is_expected.to eq(:job) } + end + end + + context 'with simple config' do + context 'when job is specified' do + let(:config) { 'job_name' } + + describe '#valid?' do + it { is_expected.to be_valid } + end + + describe '#value' do + it 'returns job needs configuration' do + expect(need.value).to eq(name: 'job_name', artifacts: true) + end + end + + it_behaves_like 'job type' + end + + context 'when need is empty' do + let(:config) { '' } + + describe '#valid?' do + it { is_expected.not_to be_valid } + end + + describe '#errors' do + it 'is returns an error about an empty config' do + expect(need.errors) + .to contain_exactly("job string config can't be blank") + end + end + + it_behaves_like 'job type' end + end + + context 'with complex config' do + context 'with job name and artifacts true' do + let(:config) { { job: 'job_name', artifacts: true } } + + describe '#valid?' do + it { is_expected.to be_valid } + end + + describe '#value' do + it 'returns job needs configuration' do + expect(need.value).to eq(name: 'job_name', artifacts: true) + end + end + + it_behaves_like 'job type' + end + + context 'with job name and artifacts false' do + let(:config) { { job: 'job_name', artifacts: false } } + + describe '#valid?' do + it { is_expected.to be_valid } + end + + describe '#value' do + it 'returns job needs configuration' do + expect(need.value).to eq(name: 'job_name', artifacts: false) + end + end + + it_behaves_like 'job type' + end + + context 'with job name and artifacts nil' do + let(:config) { { job: 'job_name', artifacts: nil } } - describe '#value' do - it 'returns job needs configuration' do - expect(need.value).to eq(name: 'job_name') + describe '#valid?' do + it { is_expected.to be_valid } end + + describe '#value' do + it 'returns job needs configuration' do + expect(need.value).to eq(name: 'job_name', artifacts: true) + end + end + + it_behaves_like 'job type' + end + + context 'without artifacts key' do + let(:config) { { job: 'job_name' } } + + describe '#valid?' do + it { is_expected.to be_valid } + end + + describe '#value' do + it 'returns job needs configuration' do + expect(need.value).to eq(name: 'job_name', artifacts: true) + end + end + + it_behaves_like 'job type' + end + + context 'when job name is empty' do + let(:config) { { job: '', artifacts: true } } + + describe '#valid?' do + it { is_expected.not_to be_valid } + end + + describe '#errors' do + it 'is returns an error about an empty config' do + expect(need.errors) + .to contain_exactly("job hash job can't be blank") + end + end + + it_behaves_like 'job type' + end + + context 'when job name is not a string' do + let(:config) { { job: :job_name, artifacts: false } } + + describe '#valid?' do + it { is_expected.not_to be_valid } + end + + describe '#errors' do + it 'is returns an error about job type' do + expect(need.errors) + .to contain_exactly('job hash job should be a string') + end + end + + it_behaves_like 'job type' + end + + context 'when job has unknown keys' do + let(:config) { { job: 'job_name', artifacts: false, some: :key } } + + describe '#valid?' do + it { is_expected.not_to be_valid } + end + + describe '#errors' do + it 'is returns an error about job type' do + expect(need.errors) + .to contain_exactly('job hash config contains unknown keys: some') + end + end + + it_behaves_like 'job type' end end - context 'when need is empty' do - let(:config) { '' } + context 'when need config is not a string or a hash' do + let(:config) { :job_name } describe '#valid?' do it { is_expected.not_to be_valid } end describe '#errors' do - it 'is returns an error about an empty config' do + it 'is returns an error about job type' do expect(need.errors) - .to contain_exactly("job config can't be blank") + .to contain_exactly('unknown strategy has an unsupported type') end end end |