diff --git a/.fixtures.yml b/.fixtures.yml index a28e653cb..c0dc882ce 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,4 +1,8 @@ fixtures: + repositories: + facts: 'git://github.com/puppetlabs/puppetlabs-facts.git' + puppet_agent: 'git://github.com/puppetlabs/puppetlabs-puppet_agent.git' + provision: 'git://github.com/puppetlabs/provision.git' symlinks: stdlib: "#{source_dir}" - test: "#{source_dir}/spec/fixtures/test" + test: "#{source_dir}/spec/fixtures/test" \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index 413a6442f..ee74e8cbb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -26,7 +26,7 @@ GetText: GetText/DecorateString: Description: We don't want to decorate test output. Exclude: - - spec/* + - spec/**/* RSpec/BeforeAfterAll: Description: Beware of using after(:all) as it may cause state to leak between tests. A necessary evil in acceptance testing. diff --git a/.sync.yml b/.sync.yml index 5e57126c2..eb3e7c1c6 100644 --- a/.sync.yml +++ b/.sync.yml @@ -11,25 +11,12 @@ inherit_from: .rubocop_todo.yml .travis.yml: - docker_sets: - - set: docker/centos-7 - - set: docker/ubuntu-14.04 - docker_defaults: - bundler_args: "" - secure: "" - branches: - - release + unmanaged: true + +appveyor.yml: + unmanaged: true Gemfile: - required: - ':system_tests': - - gem: 'puppet-module-posix-system-r#{minor_version}' - platforms: ruby - - gem: 'puppet-module-win-system-r#{minor_version}' - platforms: - - mswin - - mingw - - x64_mingw optional: ':development': - gem: 'github_changelog_generator' diff --git a/.travis.yml b/.travis.yml index bf22cd04c..0cf1b18ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ --- +dist: trusty language: ruby cache: bundler before_install: @@ -12,48 +13,97 @@ script: bundler_args: --without system_tests rvm: - 2.5.3 -stages: - - static - - spec - - acceptance - - - if: tag =~ ^v\d - name: deploy +env: + global: + - PUPPET_GEM_VERSION="~> 6.0" matrix: fast_finish: true include: - - bundler_args: + bundler_args: dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/centos-7 BEAKER_TESTMODE=apply + env: PLATFORMS=debian_puppet5 rvm: 2.5.3 - script: bundle exec rake beaker + before_script: + - bundle exec rake 'litmus:provision_list[waffle_debian]' + - bundle exec rake 'litmus:install_agent[puppet5]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel services: docker - stage: acceptance sudo: required - - bundler_args: + bundler_args: dist: trusty - env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_set=docker/ubuntu-14.04 BEAKER_TESTMODE=apply + env: PLATFORMS=debian_puppet6 rvm: 2.5.3 - script: bundle exec rake beaker + before_script: + - bundle exec rake 'litmus:provision_list[waffle_debian]' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel services: docker - stage: acceptance sudo: required - - env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint" - stage: static + bundler_args: + dist: trusty + env: PLATFORMS=el6_puppet5 + rvm: 2.5.3 + before_script: + - bundle exec rake 'litmus:provision_list[waffle_el6]' + - bundle exec rake 'litmus:install_agent[puppet5]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel + services: docker + sudo: required - - env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec - rvm: 2.4.5 - stage: spec + bundler_args: + dist: trusty + env: PLATFORMS=el6_puppet6 + rvm: 2.5.3 + before_script: + - bundle exec rake 'litmus:provision_list[waffle_el6]' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel + services: docker + sudo: required + - + bundler_args: + dist: trusty + env: PLATFORMS=el7_puppet5 + rvm: 2.5.3 + before_script: + - bundle exec rake 'litmus:provision_list[waffle_el7]' + - bundle exec rake 'litmus:install_agent[puppet5]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel + services: docker + sudo: required - - env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec + bundler_args: + dist: trusty + env: PLATFORMS=el7_puppet6 rvm: 2.5.3 - stage: spec + before_script: + - bundle exec rake 'litmus:provision_list[waffle_el7]' + - bundle exec rake 'litmus:install_agent[puppet6]' + - bundle exec rake litmus:install_module + script: + - bundle exec rake litmus:acceptance:parallel + services: docker + sudo: required + - + env: CHECK="syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop" + - + env: CHECK=parallel_spec - - env: DEPLOY_TO_FORGE=yes - stage: deploy + env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec + rvm: 2.4.5 branches: only: - master @@ -61,3 +111,12 @@ branches: - release notifications: email: false +deploy: + provider: puppetforge + user: puppet + password: + secure: "" + on: + tags: true + all_branches: true + condition: "$DEPLOY_TO_FORGE = yes" \ No newline at end of file diff --git a/Gemfile b/Gemfile index 60f245f4c..030b78b73 100644 --- a/Gemfile +++ b/Gemfile @@ -29,10 +29,6 @@ group :development do gem "puppet-module-win-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "github_changelog_generator", require: false, git: 'https://github.com/skywinder/github-changelog-generator', ref: '20ee04ba1234e9e83eb2ffb5056e23d641c7a018' if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') end -group :system_tests do - gem "puppet-module-posix-system-r#{minor_version}", require: false, platforms: [:ruby] - gem "puppet-module-win-system-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw] -end puppet_version = ENV['PUPPET_GEM_VERSION'] facter_version = ENV['FACTER_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index a5a3479cb..f11fbe9d5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,4 @@ +require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? diff --git a/appveyor.yml b/appveyor.yml index ec389492f..ef7b5481e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,6 +34,27 @@ environment: PUPPET_GEM_VERSION: ~> 6.0 RUBY_VERSION: 25-x64 CHECK: parallel_spec + - + RUBY_VERSION: 25-x64 + ACCEPTANCE: yes + TARGET_HOST: localhost + - + RUBY_VERSION: 25-x64 + ACCEPTANCE: yes + TARGET_HOST: localhost + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 +for: +- + matrix: + only: + - ACCEPTANCE: yes + install: + - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% + - bundle install --jobs 4 --retry 2 + - type Gemfile.lock + test_script: + - bundle exec rake spec_prep + - bundle exec rake litmus:acceptance:localhost matrix: fast_finish: true install: diff --git a/distelli-manifest.yml b/distelli-manifest.yml new file mode 100644 index 000000000..796132dd5 --- /dev/null +++ b/distelli-manifest.yml @@ -0,0 +1,25 @@ +team-modules/puppetlabs-stdlib: + PreBuild: + - source /opt/rh/rh-ruby25/enable + - echo "--- LETS update BUNDLER ---" + - bundle install --path vendor/bundle --jobs 3 + Build: + - echo "--- PROVISIONING ---" + - source /opt/rh/rh-ruby25/enable + - bundle exec rake litmus:provision_list[release_checks] + - cat inventory.yaml + - echo "--- AGENT INSTALLATION ---" + - bundle exec rake litmus:install_agent + - echo "--- MODULE INSTALLATION ---" + - bundle exec rake litmus:install_module + - echo "--- TESTS RUNNING ---" + - bundle exec rake litmus:acceptance:parallel + AfterBuildSuccess: + - source /opt/rh/rh-ruby25/enable + - bundle exec rake litmus:tear_down + AfterBuildFailure: + - source /opt/rh/rh-ruby25/enable + - bundle exec rake litmus:tear_down + CommitData: + - RepoType: Git + - RepoPath: . \ No newline at end of file diff --git a/metadata.json b/metadata.json index f63595d7f..53bbff563 100644 --- a/metadata.json +++ b/metadata.json @@ -105,5 +105,5 @@ "description": "Standard Library for Puppet Modules", "pdk-version": "1.10.0", "template-url": "https://github.com/puppetlabs/pdk-templates#master", - "template-ref": "heads/master-0-g7827fc2" + "template-ref": "heads/master-0-g2b33205" } diff --git a/provision.yaml b/provision.yaml new file mode 100644 index 000000000..2ceec208b --- /dev/null +++ b/provision.yaml @@ -0,0 +1,16 @@ +--- +default: + provisioner: docker + images: ['waffleimage/centos7'] +waffle_debian: + provisioner: docker + images: ['waffleimage/debian8', 'waffleimage/debian9', 'waffleimage/ubuntu14.04', 'waffleimage/ubuntu16.04', 'waffleimage/ubuntu18.04'] +waffle_el6: + provisioner: docker + images: ['waffleimage/centos6', 'waffleimage/scientificlinux6'] +waffle_el7: + provisioner: docker + images: ['waffleimage/centos7', 'waffleimage/oraclelinux7', 'waffleimage/scientificlinux7'] +release_checks: + provisioner: vmpooler + images: ['redhat-5-x86_64', 'redhat-6-x86_64', 'redhat-7-x86_64', 'redhat-8-x86_64', 'centos-5-x86_64', 'centos-6-x86_64', 'centos-7-x86_64', 'oracle-5-x86_64', 'oracle-6-x86_64', 'oracle-7-x86_64', 'scientific-6-x86_64', 'scientific-7-x86_64', 'debian-8-x86_64', 'debian-9-x86_64', 'sles-11-x86_64', 'sles-12-x86_64', 'ubuntu-1404-x86_64', 'ubuntu-1604-x86_64', 'ubuntu-1804-x86_64', 'win-2008-x86_64', 'win-2008r2-x86_64', 'win-2012-x86_64', 'win-2012r2-x86_64', 'win-2016-x86_64', 'win-2019-x86_64', 'win-7-x86_64', 'win-81-x86_64', 'win-10-pro-x86_64'] diff --git a/spec/acceptance/anchor_spec.rb b/spec/acceptance/anchor_spec.rb index 3cf0c929e..fda167425 100644 --- a/spec/acceptance/anchor_spec.rb +++ b/spec/acceptance/anchor_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper_acceptance' describe 'anchor type' do - describe 'success' do - pp = <<-DOC + let(:pp) do + <<-MANIFEST class anchored { anchor { 'anchored::begin': } ~> anchor { 'anchored::end': } @@ -15,11 +15,12 @@ class anchorrefresh { } include anchorrefresh - DOC - it 'effects proper chaining of resources' do - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{Anchor\[final\]: Triggered 'refresh'}) - end + MANIFEST + end + + it 'applies manifest, anchors resources in correct order' do + apply_manifest(pp) do |r| + expect(r.stdout).to match(%r{Anchor\[final\]: Triggered 'refresh'}) end end end diff --git a/spec/acceptance/build_csv.rb b/spec/acceptance/build_csv.rb deleted file mode 100644 index 9059858d8..000000000 --- a/spec/acceptance/build_csv.rb +++ /dev/null @@ -1,89 +0,0 @@ -# vim: set sw=2 sts=2 et tw=80 : -require 'rspec' - -# XXX Super ugly hack to keep from starting beaker nodes -module Kernel - # make an alias of the original require - alias original_require require - # rewrite require - def require(name) - original_require name if name != 'spec_helper_acceptance' - end -end -UNSUPPORTED_PLATFORMS = [].freeze -def fact(*_args) - [] -end -# XXX End hax - -# Get a list of functions for test coverage -function_list = Dir[File.join(File.dirname(__FILE__), '..', '..', 'lib', 'puppet', 'parser', 'functions', '*.rb')].map do |function_rb| - File.basename(function_rb, '.rb') -end - -## Configure rspec to parse tests -options = RSpec::Core::ConfigurationOptions.new(['spec/acceptance']) -configuration = RSpec.configuration -world = RSpec.world -options.parse_options -options.configure(configuration) -configuration.load_spec_files - -## Collect up tests and example groups into a hash -def get_tests(children) - children.each_with_object({}) do |c, memo| - memo[c.description] = {} - memo[c.description]['groups'] = get_tests(c.children) unless c.children.empty? - unless c.examples.empty? - memo[c.description]['tests'] = c.examples.map { |e| - e.description unless e.pending? - }.compact - end - next if c.examples.empty? - memo[c.description]['pending_tests'] = c.examples.map { |e| - e.description if e.pending? - }.compact - end -end - -def count_test_types_in(type, group) - return 0 if group.nil? - group.reduce(0) do |m, (k, v)| - m += v.length if k == type - m += count_tests_in(v) if v.is_a?(Hash) - m - end -end - -def count_tests_in(group) - count_test_types_in('tests', group) -end - -def count_pending_tests_in(group) - count_test_types_in('pending_tests', group) -end - -# Convert tests hash to csv format -def to_csv(function_list, tests) - function_list.map { |function_name| - v = tests["#{function_name} function"] - if v - positive_tests = count_tests_in(v['groups']['success']) - negative_tests = count_tests_in(v['groups']['failure']) - pending_tests = - count_pending_tests_in(v['groups']['failure']) + - count_pending_tests_in(v['groups']['failure']) - else - positive_tests = 0 - negative_tests = 0 - pending_tests = 0 - end - '%-25s, %-9d, %-9d, %-9d' % [function_name, positive_tests, negative_tests, pending_tests] - }.compact -end - -tests = get_tests(world.example_groups) -csv = to_csv(function_list, tests) -percentage_tested = "#{tests.count * 100 / function_list.count}%" -printf("%-25s, %-9s, %-9s, %-9s\n", "#{percentage_tested} have tests.", 'Positive', 'Negative', 'Pending') -puts csv diff --git a/spec/acceptance/file_line_spec.rb b/spec/acceptance/file_line_spec.rb new file mode 100644 index 000000000..009889dfb --- /dev/null +++ b/spec/acceptance/file_line_spec.rb @@ -0,0 +1,89 @@ +require 'spec_helper_acceptance' + +test_file = (os[:family] == 'windows') ? 'C:\Users\Administrator\file_line_test.txt' : '/tmp/file_line_test.txt' + +describe 'file_line type' do + before(:each) do + pp_test_file = <<-MANIFEST + file { '#{test_file}': + ensure => present, + content => 'a wild test file has appeared!', + } + MANIFEST + apply_manifest(pp_test_file) + end + + context 'ensure line' do + let(:pp) do + <<-MANIFEST + file_line { 'test_ensure': + path => '#{test_file}', + line => 'test file uses attack!', + } + MANIFEST + end + + it 'applies manifest, adds line' do + idempotent_apply(pp) + expect(file(test_file)).to be_file + expect(file(test_file).content).to match(%r{test file uses attack!}) + end + end + + context 'matches and replaces line' do + let(:pp) do + <<-MANIFEST + file_line { 'test_match': + path => '#{test_file}', + line => 'a tame test file has appeared!', + match => '^a wild', + } + MANIFEST + end + + it 'applies manifest, replaces line' do + idempotent_apply(pp) + expect(file(test_file)).to be_file + expect(file(test_file).content).to match(%r{a tame test file has appeared!}) + end + end + + context 'remove line' do + context 'using match' do + let(:pp) do + <<-MANIFEST + file_line { 'test_absent_match': + ensure => absent, + path => '#{test_file}', + match => '^a wild', + match_for_absence => true, + } + MANIFEST + end + + it 'applies manifest, removes line' do + idempotent_apply(pp) + expect(file(test_file)).to be_file + expect(file(test_file).content).to be_empty + end + end + + context 'using line' do + let(:pp) do + <<-MANIFEST + file_line { 'test_absent_line': + ensure => absent, + path => '#{test_file}', + line => 'a wild test file has appeared!', + } + MANIFEST + end + + it 'applies manifest, removes line' do + idempotent_apply(pp) + expect(file(test_file)).to be_file + expect(file(test_file).content).to be_empty + end + end + end +end diff --git a/spec/acceptance/has_interface_with_spec.rb b/spec/acceptance/has_interface_with_spec.rb deleted file mode 100644 index d16dc1ddd..000000000 --- a/spec/acceptance/has_interface_with_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'has_interface_with function', :unless => ((fact('osfamily') == 'windows') || (fact('osfamily') == 'AIX')) do - describe 'success' do - pp1 = <<-DOC - $a = $::ipaddress - $o = has_interface_with('ipaddress', $a) - notice(inline_template('has_interface_with is <%= @o.inspect %>')) - DOC - it 'has_interface_with existing ipaddress' do - apply_manifest(pp1, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{has_interface_with is true}) - end - end - - pp2 = <<-DOC - $a = '128.0.0.1' - $o = has_interface_with('ipaddress', $a) - notice(inline_template('has_interface_with is <%= @o.inspect %>')) - DOC - it 'has_interface_with absent ipaddress' do - apply_manifest(pp2, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{has_interface_with is false}) - end - end - - pp3 = <<-DOC - if $osfamily == 'Solaris' or $osfamily == 'Darwin' { - $a = 'lo0' - }elsif $osfamily == 'windows' { - $a = $::kernelmajversion ? { - /6\.(2|3|4)/ => 'Ethernet0', - /6\.(0|1)/ => 'Local_Area_Connection', - /5\.(1|2)/ => undef, #Broken current in facter - } - }else { - $a = 'lo' - } - $o = has_interface_with($a) - notice(inline_template('has_interface_with is <%= @o.inspect %>')) - DOC - it 'has_interface_with existing interface' do - apply_manifest(pp3, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{has_interface_with is true}) - end - end - end - describe 'failure' do - it 'handles no arguments' - it 'handles non strings' - end -end diff --git a/spec/acceptance/is_a_spec.rb b/spec/acceptance/is_a_spec.rb deleted file mode 100644 index 449e3e78c..000000000 --- a/spec/acceptance/is_a_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'spec_helper_acceptance' - -if return_puppet_version =~ %r{^4} - describe 'is_a function' do - pp1 = <<-DOC - if 'hello world'.is_a(String) { - notify { 'output correct': } - } - DOC - it 'matches a string' do - apply_manifest(pp1, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{Notice: output correct}) - end - end - - pp2 = <<-DOC - if 5.is_a(String) { - notify { 'output wrong': } - } - DOC - it 'does not match a integer as string' do - apply_manifest(pp2, :catch_failures => true) do |r| - expect(r.stdout).not_to match(%r{Notice: output wrong}) - end - end - end -end diff --git a/spec/acceptance/is_mac_address_spec.rb b/spec/acceptance/is_mac_address_spec.rb deleted file mode 100644 index 8e96abffd..000000000 --- a/spec/acceptance/is_mac_address_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'is_mac_address function' do - describe 'success' do - pp1 = <<-DOC - $a = '00:a0:1f:12:7f:a0' - $b = true - $o = is_mac_address($a) - if $o == $b { - notify { 'output correct': } - } - DOC - it 'is_mac_addresss a mac' do - apply_manifest(pp1, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{Notice: output correct}) - end - end - - pp2 = <<-DOC - $a = '00:a0:1f:12:7f:g0' - $b = false - $o = is_mac_address($a) - if $o == $b { - notify { 'output correct': } - } - DOC - it 'is_mac_addresss a mac out of range' do - apply_manifest(pp2, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{Notice: output correct}) - end - end - - pp3 = <<-DOC - $a = '80:00:02:09:fe:80:00:00:00:00:00:00:00:24:65:ff:ff:91:a3:12' - $b = true - $o = is_mac_address($a) - if $o == $b { - notify { 'output correct': } - } - DOC - it 'is_mac_addresss a 20-octet mac' do - apply_manifest(pp3, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{Notice: output correct}) - end - end - end - describe 'failure' do - it 'handles improper argument counts' - end -end diff --git a/spec/acceptance/pw_hash_spec.rb b/spec/acceptance/pw_hash_spec.rb deleted file mode 100644 index 9c0d716c6..000000000 --- a/spec/acceptance/pw_hash_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'spec_helper_acceptance' - -# Windows and OS X do not have useful implementations of crypt(3) -describe 'pw_hash function', :unless => ['windows', 'Darwin', 'SLES'].include?(fact('operatingsystem')) do - describe 'success' do - pp1 = <<-DOC - $o = pw_hash('password', 'sha-512', 'salt') - notice(inline_template('pw_hash is <%= @o.inspect %>')) - DOC - it 'hashes passwords' do - apply_manifest(pp1, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{pw_hash is "\$6\$salt\$IxDD3jeSOb5eB1CX5LBsqZFVkJdido3OUILO5Ifz5iwMuTS4XMS130MTSuDDl3aCI6WouIL9AjRbLCelDCy\.g\."}) - end - end - - pp2 = <<-DOC - $o = pw_hash('', 'sha-512', 'salt') - notice(inline_template('pw_hash is <%= @o.inspect %>')) - DOC - it 'returns nil if no password is provided' do - apply_manifest(pp2, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{pw_hash is nil}) - end - end - end - describe 'failure' do - it 'handles less than three arguments' - it 'handles more than three arguments' - it 'handles non strings' - end -end diff --git a/spec/acceptance/size_spec.rb b/spec/acceptance/size_spec.rb deleted file mode 100644 index e84e66523..000000000 --- a/spec/acceptance/size_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'size function', :if => Puppet::Util::Package.versioncmp(return_puppet_version, '6.0.0') < 0 do - describe 'success' do - pp1 = <<-DOC - $a = 'discombobulate' - $o = size($a) - notice(inline_template('size is <%= @o.inspect %>')) - DOC - it 'single string size' do - apply_manifest(pp1, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{size is 14}) - end - end - - pp2 = <<-DOC - $a = '' - $o = size($a) - notice(inline_template('size is <%= @o.inspect %>')) - DOC - it 'with empty string' do - apply_manifest(pp2, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{size is 0}) - end - end - - pp3 = <<-DOC - $a = undef - $o = size($a) - notice(inline_template('size is <%= @o.inspect %>')) - DOC - it 'with undef' do - apply_manifest(pp3, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{size is 0}) - end - end - - pp4 = <<-DOC - $a = ['discombobulate', 'moo'] - $o = size($a) - notice(inline_template('size is <%= @o.inspect %>')) - DOC - it 'strings in array' do - apply_manifest(pp4, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{size is 2}) - end - end - end - describe 'failure' do - it 'handles no arguments' - it 'handles non strings or arrays' - end -end diff --git a/spec/acceptance/strftime_spec.rb b/spec/acceptance/strftime_spec.rb deleted file mode 100644 index 4ba2c6aa6..000000000 --- a/spec/acceptance/strftime_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'strftime function', :if => Puppet::Util::Package.versioncmp(Puppet.version, '4.8.0') < 0 do - describe 'success' do - pp = <<-DOC - $o = strftime('%C') - notice(inline_template('strftime is <%= @o.inspect %>')) - DOC - it 'gives the Century' do - apply_manifest(pp, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{strftime is "20"}) - end - end - it 'takes a timezone argument' - end - describe 'failure' do - it 'handles no arguments' - it 'handles invalid format strings' - end -end diff --git a/spec/acceptance/type3x_spec.rb b/spec/acceptance/type3x_spec.rb deleted file mode 100644 index 4b755488c..000000000 --- a/spec/acceptance/type3x_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'type3x function' do - describe 'success' do - { - %{type3x({ 'a' => 'hash' })} => 'Hash', - %{type3x(['array'])} => 'Array', - %{type3x(false)} => 'Boolean', - %{type3x('asdf')} => 'String', - %{type3x(242)} => 'Integer', - %{type3x(3.14)} => 'Float', - }.each do |pp, type| - it "with type #{type}" do - apply_manifest(pp, :catch_failures => true) - end - end - end - - describe 'failure' do - pp_fail = <<-MANIFEST - type3x('one','two') - MANIFEST - it 'handles improper number of arguments' do - expect(apply_manifest(pp_fail, :expect_failures => true).stderr).to match(%r{Wrong number of arguments}) - end - end -end diff --git a/spec/acceptance/type_spec.rb b/spec/acceptance/type_spec.rb deleted file mode 100644 index 7b6e1fbb8..000000000 --- a/spec/acceptance/type_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'type function' do - describe 'success' do - pp1 = <<-DOC - $a = ["the","public","art","galleries"] - # Anagram: Large picture halls, I bet - $o = type($a) - notice(inline_template('type is <%= @o.to_s %>')) - DOC - it 'types arrays' do - apply_manifest(pp1, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{type is Tuple\[String.*, String.*, String.*, String.*\]}) - end - end - - pp2 = <<-DOC - $a = "blowzy night-frumps vex'd jack q" - $o = type($a) - notice(inline_template('type is <%= @o.to_s %>')) - DOC - it 'types strings' do - apply_manifest(pp2, :catch_failures => true) do |r| - expect(r.stdout).to match(%r{type is String}) - end - end - it 'types hashes' - it 'types integers' - it 'types floats' - it 'types booleans' - end - describe 'failure' do - it 'handles no arguments' - end -end diff --git a/spec/acceptance/validate_augeas_spec.rb b/spec/acceptance/validate_augeas_spec.rb deleted file mode 100644 index 9a59f38cb..000000000 --- a/spec/acceptance/validate_augeas_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'validate_augeas function', :unless => (fact('osfamily') == 'windows') do - describe 'prep' do - it 'installs augeas for tests' - end - describe 'success' do - context 'with valid inputs with no 3rd argument' do - { - 'root:x:0:0:root:/root:/bin/bash\n' => 'Passwd.lns', - 'proc /proc proc nodev,noexec,nosuid 0 0\n' => 'Fstab.lns', - }.each do |line, lens| - pp1 = <<-DOC - $line = "#{line}" - $lens = "#{lens}" - validate_augeas($line, $lens) - DOC - it "validates a single argument for #{lens}" do - apply_manifest(pp1, :catch_failures => true) - end - end - end - - context 'with valid inputs with 3rd and 4th arguments' do - line = 'root:x:0:0:root:/root:/bin/barsh\n' - lens = 'Passwd.lns' - restriction = '$file/*[shell="/bin/barsh"]' - pp2 = <<-DOC - $line = "#{line}" - $lens = "#{lens}" - $restriction = ['#{restriction}'] - validate_augeas($line, $lens, $restriction, "my custom failure message") - DOC - it 'validates a restricted value' do - expect(apply_manifest(pp2, :expect_failures => true).stderr).to match(%r{my custom failure message}) - end - end - - context 'with invalid inputs' do - { - 'root:x:0:0:root' => 'Passwd.lns', - '127.0.1.1' => 'Hosts.lns', - }.each do |line, lens| - pp3 = <<-DOC - $line = "#{line}" - $lens = "#{lens}" - validate_augeas($line, $lens) - DOC - it "validates a single argument for #{lens}" do - apply_manifest(pp3, :expect_failures => true) - end - end - end - context 'with garbage inputs' do - it 'raises an error on invalid inputs' - end - end - describe 'failure' do - it 'handles improper number of arguments' - end -end diff --git a/spec/acceptance/validate_cmd_spec.rb b/spec/acceptance/validate_cmd_spec.rb deleted file mode 100644 index a846b5355..000000000 --- a/spec/acceptance/validate_cmd_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'validate_cmd function' do - describe 'success' do - pp1 = <<-DOC - $one = 'foo' - if $::osfamily == 'windows' { - $two = 'echo' #shell built-in - } else { - $two = '/bin/echo' - } - validate_cmd($one,$two) - DOC - it 'validates a true command' do - apply_manifest(pp1, :catch_failures => true) - end - - pp2 = <<-DOC - $one = 'foo' - if $::osfamily == 'windows' { - $two = 'C:/aoeu' - } else { - $two = '/bin/aoeu' - } - validate_cmd($one,$two) - DOC - it 'validates a fail command' do - apply_manifest(pp2, :expect_failures => true) - end - - pp3 = <<-DOC - $one = 'foo' - if $::osfamily == 'windows' { - $two = 'C:/aoeu' - } else { - $two = '/bin/aoeu' - } - validate_cmd($one,$two,"aoeu is dvorak") - DOC - it 'validates a fail command with a custom error message' do - apply_manifest(pp3, :expect_failures => true) do |output| - expect(output.stderr).to match(%r{aoeu is dvorak}) - end - end - end - describe 'failure' do - it 'handles improper number of arguments' - it 'handles improper argument types' - end -end diff --git a/spec/functions/load_module_metadata_spec.rb b/spec/functions/load_module_metadata_spec.rb index c5ea78a48..a97b6b4ac 100644 --- a/spec/functions/load_module_metadata_spec.rb +++ b/spec/functions/load_module_metadata_spec.rb @@ -9,6 +9,8 @@ before :each do allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"name": "puppetlabs-stdlib"}') allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}') + # Additional modules used by litmus which are identified while running these dues to being in fixtures + allow(File).to receive(:read).with(%r{\/(provision|puppet_agent|facts)\/metadata.json}, :encoding => 'utf-8') end context 'when calling with valid utf8 and double byte character arguments' do diff --git a/spec/functions/loadjson_spec.rb b/spec/functions/loadjson_spec.rb index e6e60f437..c0c630b7b 100644 --- a/spec/functions/loadjson_spec.rb +++ b/spec/functions/loadjson_spec.rb @@ -8,6 +8,8 @@ before :each do allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"name": "puppetlabs-stdlib"}') allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}') + # Additional modules used by litmus which are identified while running these dues to being in fixtures + allow(File).to receive(:read).with(%r{\/(provision|puppet_agent|facts)\/metadata.json}, :encoding => 'utf-8') end context 'when a non-existing file is specified' do diff --git a/spec/functions/strftime_spec.rb b/spec/functions/strftime_spec.rb index 73c5c968b..92a6893ba 100644 --- a/spec/functions/strftime_spec.rb +++ b/spec/functions/strftime_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'strftime', :if => Puppet::Util::Package.versioncmp(Puppet.version, '4.8.0') < 0 do +describe 'strftime' do it 'exists' do expect(Puppet::Parser::Functions.function('strftime')).to eq('function_strftime') end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 6becf0d4e..4b4871eb9 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -1,25 +1,59 @@ -require 'beaker-pe' -require 'beaker-puppet' -require 'puppet' -require 'beaker-rspec' -require 'beaker/puppet_install_helper' -require 'beaker/module_install_helper' +# frozen_string_literal: true -run_puppet_install_helper -configure_type_defaults_on(hosts) -install_ca_certs unless ENV['PUPPET_INSTALL_TYPE'] =~ %r{pe}i -install_module_on(hosts) -install_module_dependencies_on(hosts) +require 'serverspec' +require 'puppet_litmus' +require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb')) +include PuppetLitmus -RSpec.configure do |c| - # Readable test descriptions - c.formatter = :documentation - - # Configure all nodes in nodeset - c.before :suite do +if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost' + puts 'Running tests against this machine !' + if Gem.win_platform? + set :backend, :cmd + else + set :backend, :exec end -end +else + # load inventory + inventory_hash = inventory_hash_from_inventory_file + node_config = config_from_node(inventory_hash, ENV['TARGET_HOST']) -def return_puppet_version - (on default, puppet('--version')).output.chomp + if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes') + host = ENV['TARGET_HOST'] + set :backend, :docker + set :docker_container, host + elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes') + set :backend, :ssh + options = Net::SSH::Config.for(host) + options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil? + options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil? + options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil? + options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil? + options[:verify_host_key] = Net::SSH::Verifiers::Null.new unless node_config.dig('ssh', 'host-key-check').nil? + host = if ENV['TARGET_HOST'].include?(':') + ENV['TARGET_HOST'].split(':').first + else + ENV['TARGET_HOST'] + end + set :host, options[:host_name] || host + set :ssh_options, options + set :request_pty, true + elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes') + require 'winrm' + # rubocop:disable Style/HashSyntax + set :backend, :winrm + set :os, family: 'windows' + user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil? + pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil? + endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman" + + opts = { + user: user, + password: pass, + endpoint: endpoint, + operation_timeout: 300, + } + # rubocop:enable Style/HashSyntax + winrm = WinRM::Connection.new opts + Specinfra.configuration.winrm = winrm + end end