Skip to content

Commit

Permalink
(CAT-2121) Update tests to account for validate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
david22swan committed Oct 25, 2024
1 parent 66644df commit c2772ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
20 changes: 10 additions & 10 deletions spec/acceptance/report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
before(:all) do
File.open(init_pp, 'w') do |f|
f.puts <<~EOS
class report {}
class report
EOS
end
end
Expand All @@ -18,24 +18,24 @@ class report {}
include_context 'with a fake TTY'
# Tests writing reports to a file
describe command('pdk validate puppet manifests/init.pp --format=text:report.txt') do
its(:exit_status) { is_expected.to eq(0) }
its(:exit_status) { is_expected.to eq(1) }
its(:stdout) { is_expected.to have_no_output }
its(:stderr) { is_expected.to match(/Checking Puppet manifest syntax/i) }
its(:stderr) { is_expected.to match(/Checking Puppet manifest style/i) }

describe file('report.txt') do
it { is_expected.to exist }
# pdk (WARNING): puppet-lint: class not documented (manifests/init.pp:1:1)
its(:content) { is_expected.to match(/\(warning\):.*class not documented.*\(#{Regexp.escape(init_pp)}.*\)/i) }
# pdk (ERROR): puppet-syntax: Could not parse for environment production: Syntax error at end of input (manifests/init.pp)
its(:content) { is_expected.to match(/\(ERROR\):.*Could not parse for environment production.*\(#{Regexp.escape(init_pp)}.*\)/i) }
end
end

# Tests writing reports to stdout doesn't actually write a file named stdout
describe command('pdk validate puppet manifests/init.pp --format=text:stdout') do
its(:exit_status) { is_expected.to eq(0) }
its(:exit_status) { is_expected.to eq(1) }
its(:stderr) { is_expected.to match(/Checking Puppet manifest syntax/i) }
its(:stderr) { is_expected.to match(/Checking Puppet manifest style/i) }
its(:stdout) { is_expected.to match(/\(warning\):.*class not documented.*\(#{Regexp.escape(init_pp)}.*\)/i) }
its(:stdout) { is_expected.to match(/\(ERROR\):.*Could not parse for environment production.*\(#{Regexp.escape(init_pp)}.*\)/i) }

describe file('stdout') do
it { is_expected.not_to exist }
Expand All @@ -44,15 +44,15 @@ class report {}

# Tests writing reports to stderr doesn't actually write a file named stderr
describe command('pdk validate puppet manifests/init.pp --format=text:stderr') do
its(:exit_status) { is_expected.to eq(0) }
its(:exit_status) { is_expected.to eq(1) }
its(:stdout) { is_expected.to have_no_output }
its(:stderr) { is_expected.to match(/Checking Puppet manifest syntax/i) }
its(:stderr) { is_expected.to match(/Checking Puppet manifest style/i) }

its(:stderr) do
# Due to spinners writing at arbitrary cursor locations, we can't depend on the text
# being at a the beginning of a line.
is_expected.to match(/\(warning\):.*class not documented.*\(#{Regexp.escape(init_pp)}.*\)/i)
is_expected.to match(/\(ERROR\):.*Could not parse for environment production.*\(#{Regexp.escape(init_pp)}.*\)/i)
end

describe file('stderr') do
Expand All @@ -63,10 +63,10 @@ class report {}

context 'when not run interactively' do
describe command('pdk validate puppet manifests/init.pp') do
its(:exit_status) { is_expected.to eq(0) }
its(:exit_status) { is_expected.to eq(1) }
its(:stderr) { is_expected.to match(/using ruby \d+\.\d+\.\d+/i) }
its(:stderr) { is_expected.to match(/using puppet \d+\.\d+\.\d+/i) }
its(:stdout) { is_expected.to match(/\(warning\):.*class not documented.*\(#{Regexp.escape(init_pp)}.*\)/i) }
its(:stdout) { is_expected.to match(/\(ERROR\):.*Could not parse for environment production.*\(#{Regexp.escape(init_pp)}.*\)/i) }
end
end
end
Expand Down
9 changes: 6 additions & 3 deletions spec/acceptance/validate_puppet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class foo {
end

describe command('pdk validate puppet --format text:stdout --format junit:report.xml') do
its(:exit_status) { is_expected.to eq(0) }
its(:exit_status) { is_expected.to eq(1) }
its(:stderr) { is_expected.not_to match(epp_spinner_text) }
its(:stderr) { is_expected.to match(syntax_spinner_text) }
its(:stderr) { is_expected.to match(lint_spinner_text) }
Expand Down Expand Up @@ -180,7 +180,10 @@ class foo {
context 'with a parsable file and some style warnings' do
before(:all) do
File.open(init_pp, 'w') do |f|
f.puts 'class foo {}'
f.puts <<-EOS.gsub(/^ {10}/, '')
# pdk_in_gemfile
class pdk_in_gemfile {}
EOS
end
end

Expand All @@ -190,7 +193,7 @@ class foo {

describe command('pdk validate puppet --format text:stdout --format junit:report.xml') do
its(:exit_status) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(/\(warning\):.*class not documented.*\(#{Regexp.escape(init_pp)}.+\)/i) }
its(:stdout) { is_expected.to match(/\(warning\):.*indent should be 0 chars and is 2.*\(#{Regexp.escape(init_pp)}.+\)/i) }
its(:stderr) { is_expected.not_to match(epp_spinner_text) }
its(:stderr) { is_expected.to match(syntax_spinner_text) }
its(:stderr) { is_expected.to match(lint_spinner_text) }
Expand Down

0 comments on commit c2772ea

Please sign in to comment.