From e0fe36d50b0542d1b73a9778e474644a7f59ed4d Mon Sep 17 00:00:00 2001 From: david22swan Date: Thu, 24 Oct 2024 10:53:28 +0100 Subject: [PATCH 1/4] (CAT-2121) Update tests to account for validate changes --- spec/acceptance/report_spec.rb | 20 ++++++------- spec/acceptance/validate_puppet_spec.rb | 37 +++++++++++++------------ 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/spec/acceptance/report_spec.rb b/spec/acceptance/report_spec.rb index ec1a865b9..33816885a 100644 --- a/spec/acceptance/report_spec.rb +++ b/spec/acceptance/report_spec.rb @@ -9,7 +9,7 @@ before(:all) do File.open(init_pp, 'w') do |f| f.puts <<~EOS - class report {} + class report EOS end end @@ -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 } @@ -44,7 +44,7 @@ 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) } @@ -52,7 +52,7 @@ class report {} 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 @@ -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 diff --git a/spec/acceptance/validate_puppet_spec.rb b/spec/acceptance/validate_puppet_spec.rb index 27452cc73..4df2d9f8d 100644 --- a/spec/acceptance/validate_puppet_spec.rb +++ b/spec/acceptance/validate_puppet_spec.rb @@ -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) } @@ -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 @@ -189,8 +192,8 @@ 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(:stdout) { is_expected.to match(/\(warning\):.*class not documented.*\(#{Regexp.escape(init_pp)}.+\)/i) } + its(:exit_status) { is_expected.to eq(1) } + 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) } @@ -221,7 +224,7 @@ class foo { its(:content) do is_expected.to have_junit_testcase.in_testsuite('puppet-lint').with_attributes( - 'classname' => 'puppet-lint.documentation', + 'classname' => 'puppet-lint.strict_indent', 'name' => a_string_starting_with(init_pp) ).that_failed end @@ -289,11 +292,11 @@ class foo { end end - context 'with a parsable file and some style errors' do + context 'with a parsable file and some errors' do before(:all) do File.open(example_pp, 'w') do |f| f.puts '# some documentation' - f.puts 'class foo::bar {}' + f.puts 'class foo::bar' end end @@ -303,7 +306,7 @@ class foo { describe command('pdk validate puppet --format text:stdout --format junit:report.xml') do its(:exit_status) { is_expected.not_to eq(0) } - its(:stdout) { is_expected.to match(/autoload module layout.*\(#{Regexp.escape(example_pp)}.+\)/i) } + its(:stdout) { is_expected.to match(/Syntax error at end of input.*\(#{Regexp.escape(example_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) } @@ -312,15 +315,15 @@ class foo { its(:content) { is_expected.to contain_valid_junit_xml } its(:content) do - is_expected.to have_junit_testsuite('puppet-lint').with_attributes( + is_expected.to have_junit_testsuite('puppet-syntax').with_attributes( 'failures' => eq(1), 'tests' => eq(1) ) end its(:content) do - is_expected.to have_junit_testcase.in_testsuite('puppet-lint').with_attributes( - 'classname' => 'puppet-lint.autoloader_layout', + is_expected.to have_junit_testcase.in_testsuite('puppet-syntax').with_attributes( + 'classname' => 'puppet-syntax', 'name' => a_string_starting_with(example_pp) ).that_failed end @@ -388,7 +391,7 @@ class foo { before(:all) do FileUtils.mkdir_p(another_problem_dir) File.open(another_problem_pp, 'w') do |f| - f.puts 'class foo::bar::whoops {}' + f.puts 'class foo::bar::whoops' end end @@ -408,15 +411,15 @@ class foo { its(:content) { is_expected.to contain_valid_junit_xml } its(:content) do - is_expected.to have_junit_testsuite('puppet-lint').with_attributes( - 'failures' => eq(2), - 'tests' => eq(2) + is_expected.to have_junit_testsuite('puppet-syntax').with_attributes( + 'failures' => eq(1), + 'tests' => eq(1) ) end its(:content) do - is_expected.to have_junit_testcase.in_testsuite('puppet-lint').with_attributes( - 'classname' => a_string_starting_with('puppet-lint'), + is_expected.to have_junit_testcase.in_testsuite('puppet-syntax').with_attributes( + 'classname' => a_string_starting_with('puppet-syntax'), 'name' => a_string_starting_with(another_problem_pp) ).that_failed end From 33f0125d472e224d61231825e2d4199bb8f978a6 Mon Sep 17 00:00:00 2001 From: david22swan Date: Fri, 25 Oct 2024 12:59:35 +0100 Subject: [PATCH 2/4] (maint) Remove json pin A fix for the issue requiring the pin has been released --- pdk.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/pdk.gemspec b/pdk.gemspec index 4f32e3d89..2bbc26432 100644 --- a/pdk.gemspec +++ b/pdk.gemspec @@ -47,7 +47,6 @@ Gem::Specification.new do |spec| # Other deps spec.add_runtime_dependency 'deep_merge', '~> 1.2.2' spec.add_runtime_dependency 'diff-lcs', '>= 1.5.0' - spec.add_runtime_dependency 'json', '~> 2.6.3' spec.add_runtime_dependency 'json_pure', '~> 2.6.3' spec.add_runtime_dependency 'pathspec', '~> 1.1' spec.add_runtime_dependency 'puppet_forge', '~> 5.0' From c3b82b56d3b05520b4c6547a40722ed3cb88fcde Mon Sep 17 00:00:00 2001 From: david22swan Date: Fri, 25 Oct 2024 13:18:17 +0100 Subject: [PATCH 3/4] (CAT-2121) Further update tests --- spec/acceptance/validate_all_spec.rb | 3 ++- spec/acceptance/validate_puppet_spec.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/validate_all_spec.rb b/spec/acceptance/validate_all_spec.rb index 247ec5ff9..a7deac4e0 100644 --- a/spec/acceptance/validate_all_spec.rb +++ b/spec/acceptance/validate_all_spec.rb @@ -107,12 +107,13 @@ class pdk_in_gemfile {} end describe command('pdk validate') do - its(:exit_status) { is_expected.to eq(0) } + its(:exit_status) { is_expected.to eq(1) } its(:stderr) { is_expected.to match(/Running all available validators/i) } its(:stderr) { is_expected.to match(/Checking metadata syntax/i) } its(:stderr) { is_expected.to match(/Checking module metadata style/i) } its(:stderr) { is_expected.to match(/Checking Puppet manifest syntax/i) } its(:stderr) { is_expected.to match(/Checking Ruby code style/i) } + its(:stdout) { is_expected.to match(/\(warning\):.*indent should be 0 chars and is 2/i) } end end end diff --git a/spec/acceptance/validate_puppet_spec.rb b/spec/acceptance/validate_puppet_spec.rb index 4df2d9f8d..2288eaf7b 100644 --- a/spec/acceptance/validate_puppet_spec.rb +++ b/spec/acceptance/validate_puppet_spec.rb @@ -306,7 +306,7 @@ class foo { describe command('pdk validate puppet --format text:stdout --format junit:report.xml') do its(:exit_status) { is_expected.not_to eq(0) } - its(:stdout) { is_expected.to match(/Syntax error at end of input.*\(#{Regexp.escape(example_pp)}.+\)/i) } + its(:stdout) { is_expected.to match(/Syntax error at end of input/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) } From 6b2290c7edd9f452636713223230f668bf62db69 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 28 Oct 2024 10:58:57 +0000 Subject: [PATCH 4/4] (CAT2121) Update tests for windows --- spec/acceptance/report_spec.rb | 8 ++++---- spec/acceptance/validate_all_spec.rb | 2 +- spec/acceptance/validate_puppet_spec.rb | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/acceptance/report_spec.rb b/spec/acceptance/report_spec.rb index 33816885a..6b6d59031 100644 --- a/spec/acceptance/report_spec.rb +++ b/spec/acceptance/report_spec.rb @@ -18,7 +18,7 @@ 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(1) } + its(:exit_status) { is_expected.to eq(1) | eq(256) } 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) } @@ -32,7 +32,7 @@ class report # 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(1) } + its(:exit_status) { is_expected.to eq(1) | eq(256) } 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(/\(ERROR\):.*Could not parse for environment production.*\(#{Regexp.escape(init_pp)}.*\)/i) } @@ -44,7 +44,7 @@ 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(1) } + its(:exit_status) { is_expected.to eq(1) | eq(256) } 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) } @@ -63,7 +63,7 @@ class report context 'when not run interactively' do describe command('pdk validate puppet manifests/init.pp') do - its(:exit_status) { is_expected.to eq(1) } + its(:exit_status) { is_expected.to eq(1) | eq(256) } 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(/\(ERROR\):.*Could not parse for environment production.*\(#{Regexp.escape(init_pp)}.*\)/i) } diff --git a/spec/acceptance/validate_all_spec.rb b/spec/acceptance/validate_all_spec.rb index a7deac4e0..a6c87f54a 100644 --- a/spec/acceptance/validate_all_spec.rb +++ b/spec/acceptance/validate_all_spec.rb @@ -107,7 +107,7 @@ class pdk_in_gemfile {} end describe command('pdk validate') do - its(:exit_status) { is_expected.to eq(1) } + its(:exit_status) { is_expected.to eq(1) | eq(256) } its(:stderr) { is_expected.to match(/Running all available validators/i) } its(:stderr) { is_expected.to match(/Checking metadata syntax/i) } its(:stderr) { is_expected.to match(/Checking module metadata style/i) } diff --git a/spec/acceptance/validate_puppet_spec.rb b/spec/acceptance/validate_puppet_spec.rb index 2288eaf7b..118eb5f2f 100644 --- a/spec/acceptance/validate_puppet_spec.rb +++ b/spec/acceptance/validate_puppet_spec.rb @@ -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(1) } + its(:exit_status) { is_expected.to eq(1) | eq(256) } 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) } @@ -153,7 +153,6 @@ class foo { describe command('pdk validate puppet manifests\test') do its(:exit_status) { is_expected.to eq(0) } - its(:stdout) { is_expected.to match(/\(warning\):.*class not documented.*\(#{Regexp.escape(File.join('manifests', 'test', 'test.pp'))}.+\)/i) } end end @@ -192,7 +191,7 @@ class pdk_in_gemfile {} end describe command('pdk validate puppet --format text:stdout --format junit:report.xml') do - its(:exit_status) { is_expected.to eq(1) } + its(:exit_status) { is_expected.to eq(1) | eq(256) } 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) }