Skip to content

Commit

Permalink
Merge pull request #498 from scotje/maint_fixup_yaml_parse_error_log
Browse files Browse the repository at this point in the history
(MAINT) Fixup error in log output when parsing invalid .sync.yml
  • Loading branch information
rodjek committed May 3, 2018
2 parents e8a6373 + 4c7182f commit aaa81b2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/pdk/module/templatedir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def read_config(loc)
begin
YAML.safe_load(File.read(loc), [], [], true)
rescue StandardError => e
PDK.logger.warn(_("'%{file}' is not a valid YAML file: %{message}") % { file: config_path, message: e.message })
PDK.logger.warn(_("'%{file}' is not a valid YAML file: %{message}") % { file: loc, message: e.message })
{}
end
else
Expand Down
37 changes: 35 additions & 2 deletions spec/unit/pdk/module/template_dir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
allow(YAML).to receive(:safe_load).with(config_defaults, [], [], true).and_return config_hash
end

context 'when the module has a .sync.yml file' do
context 'when the module has a valid .sync.yml file' do
let(:yaml_text) do
<<-EOF
appveyor.yml:
Expand Down Expand Up @@ -228,14 +228,47 @@
end

it 'absorbs config' do
expect(template_dir.config_for(path_or_url)).to eq('module_metadata' => { 'name' => 'foo-bar', 'version' => '0.1.0' },
expect(template_dir.config_for(path_or_url)).to eq('module_metadata' => module_metadata,
'appveyor.yml' => { 'environment' => { 'PUPPET_GEM_VERSION' => '~> 5.0' } },
'.travis.yml' => { 'extras' => [{ 'rvm' => '2.1.9' }] },
'foo' => { 'attr' => [{ 'val' => 1 }, { 'val' => 3 }] },
'.project' => { 'delete' => true },
'.gitlab-ci.yml' => { 'unmanaged' => true })
end
end

context 'when the module has an invalid .sync.yml file' do
let(:yaml_text) do
<<-EOF
appveyor.yml:
environment:
PUPPET_GEM_VERSION: "~> 5.0
EOF
end

let(:config_hash) do
YAML.load(config_defaults) # rubocop:disable Security/YAMLLoad
end

before(:each) do
allow(File).to receive(:file?).with('/path/to/module/.sync.yml').and_return true
allow(File).to receive(:readable?).with('/path/to/module/.sync.yml').and_return true
allow(File).to receive(:read).with('/path/to/module/.sync.yml').and_return yaml_text
allow(YAML).to receive(:safe_load).with(yaml_text, [], [], true).and_call_original
allow(PDK::Util).to receive(:module_root).and_return('/path/to/module')
end

it 'logs a warning' do
expect(logger).to receive(:warn).with(%r{not a valid yaml file}i)

template_dir.config_for(path_or_url)
end

it 'returns default config' do
expected = { 'module_metadata' => module_metadata }.merge(config_hash)
expect(template_dir.config_for(path_or_url)).to eq(expected)
end
end
end

describe '.metadata' do
Expand Down

0 comments on commit aaa81b2

Please sign in to comment.