Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MAINT) Fixup error in log output when parsing invalid .sync.yml #498

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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