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

(PDK-575) Run puppet parser validate with an dummy empty puppet.conf #402

Merged
merged 1 commit into from
Feb 1, 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
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the purpose of this existing auto_correct test assertion to make sure that some option is not being added? If so should we maybe just assert that the option is absent rather than having to update this test every time the invocation changes?

Also should we have a new test that explicitly checks for the --config param?

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