Skip to content

Commit

Permalink
Merge pull request #402 from rodjek/pdk-575
Browse files Browse the repository at this point in the history
(PDK-575) Run puppet parser validate with an dummy empty puppet.conf
  • Loading branch information
bmjen authored Feb 1, 2018
2 parents c4c6671 + 6c86948 commit dd74bb2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/pdk/validate/puppet/puppet_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def self.spinner_text(_targets = nil)
end

def self.parse_options(_options, targets)
%w[parser validate].concat(targets)
['parser', 'validate', '--config', null_file].concat(targets)
end

def self.null_file
Gem.win_platform? ? 'NUL' : '/dev/null'
end

def self.parse_output(report, result, targets)
Expand Down
26 changes: 25 additions & 1 deletion spec/unit/pdk/validate/puppet_syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
let(:options) { {} }
let(:targets) { %w[target1 target2.pp] }

before(:each) do
allow(Gem).to receive(:win_platform?).and_return(false)
end

it 'invokes `puppet parser validate`' do
expect(command_args.first(2)).to eq(%w[parser validate])
end
Expand All @@ -36,7 +40,7 @@
let(:options) { { auto_correct: true } }

it 'has no effect' do
expect(command_args).to eq(%w[parser validate].concat(targets))
expect(command_args).to eq(%w[parser validate --config /dev/null].concat(targets))
end
end
end
Expand Down Expand Up @@ -91,4 +95,24 @@ def mock_validate(file, line, column, message, severity)
end
end
end

describe '.null_file' do
subject { described_class.null_file }

context 'on a Windows host' do
before(:each) do
allow(Gem).to receive(:win_platform?).and_return(true)
end

it { is_expected.to eq('NUL') }
end

context 'on a POSIX host' do
before(:each) do
allow(Gem).to receive(:win_platform?).and_return(false)
end

it { is_expected.to eq('/dev/null') }
end
end
end

0 comments on commit dd74bb2

Please sign in to comment.