Commit 0f590750 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix/ci-linter-undefined-error' into 'master'

Fix undefined error in CI linter

## What does this MR do?

This MR fixes undefined error in CI linter.

## Does this MR meet the acceptance criteria?

- [x] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- [x] Tests added for this feature/bug
  
## What are the relevant issue numbers?

Closes #24759

See merge request !7650
parents 60c2d590 50e1bed4
---
title: Fix undefined error in CI linter
merge_request: 7650
author:
...@@ -108,7 +108,7 @@ module Gitlab ...@@ -108,7 +108,7 @@ module Gitlab
self.class.nodes.each_key do |key| self.class.nodes.each_key do |key|
global_entry = deps[key] global_entry = deps[key]
job_entry = @entries[key] job_entry = self[key]
if global_entry.specified? && !job_entry.specified? if global_entry.specified? && !job_entry.specified?
@entries[key] = global_entry @entries[key] = global_entry
......
...@@ -13,7 +13,7 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -13,7 +13,7 @@ describe Gitlab::Ci::Config::Entry::Global do
end end
end end
context 'when hash is valid' do context 'when configuration is valid' do
context 'when some entries defined' do context 'when some entries defined' do
let(:hash) do let(:hash) do
{ before_script: ['ls', 'pwd'], { before_script: ['ls', 'pwd'],
...@@ -225,9 +225,10 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -225,9 +225,10 @@ describe Gitlab::Ci::Config::Entry::Global do
end end
end end
context 'when hash is not valid' do context 'when configuration is not valid' do
before { global.compose! } before { global.compose! }
context 'when before script is not an array' do
let(:hash) do let(:hash) do
{ before_script: 'ls' } { before_script: 'ls' }
end end
...@@ -252,6 +253,20 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -252,6 +253,20 @@ describe Gitlab::Ci::Config::Entry::Global do
end end
end end
context 'when job does not have commands' do
let(:hash) do
{ before_script: ['echo 123'], rspec: { stage: 'test' } }
end
describe '#errors' do
it 'reports errors about missing script' do
expect(global.errors)
.to include "jobs:rspec script can't be blank"
end
end
end
end
context 'when value is not a hash' do context 'when value is not a hash' do
let(:hash) { [] } let(:hash) { [] }
...@@ -281,7 +296,7 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -281,7 +296,7 @@ describe Gitlab::Ci::Config::Entry::Global do
{ cache: { key: 'a' }, rspec: { script: 'ls' } } { cache: { key: 'a' }, rspec: { script: 'ls' } }
end end
context 'when node exists' do context 'when entry exists' do
it 'returns correct entry' do it 'returns correct entry' do
expect(global[:cache]) expect(global[:cache])
.to be_an_instance_of Gitlab::Ci::Config::Entry::Cache .to be_an_instance_of Gitlab::Ci::Config::Entry::Cache
...@@ -289,7 +304,7 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -289,7 +304,7 @@ describe Gitlab::Ci::Config::Entry::Global do
end end
end end
context 'when node does not exist' do context 'when entry does not exist' do
it 'always return unspecified node' do it 'always return unspecified node' do
expect(global[:some][:unknown][:node]) expect(global[:some][:unknown][:node])
.not_to be_specified .not_to be_specified
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment