From bbea4a6a7618e525ec91f3608a6e54c0b70b19f0 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Thu, 20 May 2021 17:57:55 +0200 Subject: [PATCH] Remove beaker integration Today there's both beaker and litmus. The spec helper shouldn't be opinionated. For beaker integration, I'd prefer to make this easy to consume. beaker-rspec[1] can provide useful helpers. There is already beaker-rspec/rake_task[2] which feels like a more native place. In Voxpupuli there's also voxpupuli-acceptance[3] which is a potential place. [1] https://github.com/voxpupuli/beaker-rspec [2] https://github.com/voxpupuli/beaker-rspec/blob/master/lib/beaker-rspec/rake_task.rb [3] https://github.com/voxpupuli/voxpupuli-acceptance --- lib/puppetlabs_spec_helper/rake_tasks.rb | 1 - lib/puppetlabs_spec_helper/tasks/beaker.rb | 115 ------------------ spec/acceptance/smoke_spec.rb | 1 - .../tasks/beaker_spec.rb | 52 -------- 4 files changed, 169 deletions(-) delete mode 100644 lib/puppetlabs_spec_helper/tasks/beaker.rb delete mode 100644 spec/unit/puppetlabs_spec_helper/tasks/beaker_spec.rb diff --git a/lib/puppetlabs_spec_helper/rake_tasks.rb b/lib/puppetlabs_spec_helper/rake_tasks.rb index e9102a9a..447dd50c 100644 --- a/lib/puppetlabs_spec_helper/rake_tasks.rb +++ b/lib/puppetlabs_spec_helper/rake_tasks.rb @@ -6,7 +6,6 @@ require 'tmpdir' require 'pathname' require 'puppetlabs_spec_helper/version' -require 'puppetlabs_spec_helper/tasks/beaker' require 'puppetlabs_spec_helper/tasks/fixtures' require 'puppetlabs_spec_helper/tasks/check_symlinks' require 'English' diff --git a/lib/puppetlabs_spec_helper/tasks/beaker.rb b/lib/puppetlabs_spec_helper/tasks/beaker.rb deleted file mode 100644 index 7d788ce7..00000000 --- a/lib/puppetlabs_spec_helper/tasks/beaker.rb +++ /dev/null @@ -1,115 +0,0 @@ -# frozen_string_literal: true - -require 'rspec/core/rake_task' - -module PuppetlabsSpecHelper; end -module PuppetlabsSpecHelper::Tasks; end -module PuppetlabsSpecHelper::Tasks::BeakerHelpers - # This is a helper for the self-symlink entry of fixtures.yml - def source_dir - Dir.pwd - end - - # cache the repositories and return a hash object - def repositories - @repositories ||= fixtures('repositories') - @repositories - end - - # get the array of Beaker set names - # @return [Array] - def beaker_node_sets - return @beaker_nodes if @beaker_nodes - - @beaker_nodes = Dir['spec/acceptance/nodesets/*.yml'].sort.map do |node_set| - node_set.slice!('.yml') - File.basename(node_set) - end - end - - # Use "vagrant ssh" to login to the given node in the node set - # @param set [String] The name of the node set (yml file) - # @param node [String] The name of the node in the set. For multi-node sets. - def vagrant_ssh(set, node = nil) - vagrant_yml_dir = File.join '.vagrant', 'beaker_vagrant_files', "#{set}.yml" - vagrant_file = File.join vagrant_yml_dir, 'Vagrantfile' - unless File.file? vagrant_file - puts "There is no Vagrantfile at: '#{vagrant_file}'. Perhaps, the node is not created or is destroyed." - exit 1 - end - Dir.chdir(vagrant_yml_dir) do - command = 'vagrant ssh' - command += " #{node}" if node - # Vagrant is not distributed as a normal gem - # and we should protect it from the current Ruby environment - env = { - 'RUBYLIB' => nil, - 'GEM_PATH' => nil, - 'BUNDLE_BIN_PATH' => nil, - } - system env, command - end - end -end -include PuppetlabsSpecHelper::Tasks::BeakerHelpers # legacy support code # rubocop:disable Style/MixinUsage - -desc 'Run beaker acceptance tests' -RSpec::Core::RakeTask.new(:beaker) do |t| - SetupBeaker.setup_beaker(t) -end - -class SetupBeaker - def self.setup_beaker(task) - task.rspec_opts = [] - task.pattern = 'spec/acceptance' - # TEST_TIERS env variable is a comma separated list of tiers to run. e.g. low, medium, high - if ENV['TEST_TIERS'] - test_tiers = ENV['TEST_TIERS'].split(',') - test_tiers_allowed = ENV.fetch('TEST_TIERS_ALLOWED', 'low,medium,high').split(',') - raise 'TEST_TIERS env variable must have at least 1 tier specified. Either low, medium or high or one of the tiers listed in TEST_TIERS_ALLOWED (comma separated).' if test_tiers.count == 0 - - test_tiers.each do |tier| - tier_to_add = tier.strip.downcase - raise "#{tier_to_add} not a valid test tier." unless test_tiers_allowed.include?(tier_to_add) - - tiers = "--tag tier_#{tier_to_add}" - task.rspec_opts.push(tiers) - end - else - puts 'TEST_TIERS env variable not defined. Defaulting to run all tests.' - end - task - end -end - -desc 'List available beaker nodesets' -task 'beaker:sets' do - beaker_node_sets.each do |set| - puts set - end -end - -# alias for compatibility -task 'beaker_nodes' => 'beaker:sets' - -desc 'Try to use vagrant to login to the Beaker node' -task 'beaker:ssh', [:set, :node] do |_task, args| - set = args[:set] || ENV['BEAKER_set'] || ENV['RS_SET'] || 'default' - node = args[:node] - vagrant_ssh set, node -end - -beaker_node_sets.each do |set| - desc "Run the Beaker acceptance tests for the node set '#{set}'" - task "beaker:#{set}" do - ENV['BEAKER_set'] = set - Rake::Task['beaker'].reenable - Rake::Task['beaker'].invoke - end - - desc "Use vagrant to login to a node from the set '#{set}'" - task "beaker:ssh:#{set}", [:node] do |_task, args| - node = args[:node] - vagrant_ssh set, node - end -end diff --git a/spec/acceptance/smoke_spec.rb b/spec/acceptance/smoke_spec.rb index e9c6ab8c..5c924fd1 100644 --- a/spec/acceptance/smoke_spec.rb +++ b/spec/acceptance/smoke_spec.rb @@ -9,7 +9,6 @@ @output, @status = Open3.capture2e('rake', '--rakefile', 'spec/acceptance/fixtures/Rakefile', '-T') end - it { expect(@output).to match %r{beaker} } it { expect(@output).to match %r{spec_prep} } it { expect(@status).to be_success } end diff --git a/spec/unit/puppetlabs_spec_helper/tasks/beaker_spec.rb b/spec/unit/puppetlabs_spec_helper/tasks/beaker_spec.rb deleted file mode 100644 index d51b680c..00000000 --- a/spec/unit/puppetlabs_spec_helper/tasks/beaker_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require 'puppetlabs_spec_helper/tasks/beaker' - -describe SetupBeaker do - describe '.setup_beaker' do - let(:task) { RSpec::Core::RakeTask.new } - - it 'can set tag for low tier' do - allow(ENV).to receive(:[]).and_return('low') - expect(described_class.setup_beaker(task).rspec_opts.to_s).to match(%r{--tag tier_low}) - end - - it 'can set tag for high, medium and low tier' do - allow(ENV).to receive(:[]).and_return('high, medium, low') - expect(described_class.setup_beaker(task).rspec_opts.to_s).to match(%r{--tag tier_high} && %r{--tag tier_medium} && %r{--tag tier_low}) - end - - it 'does not set a tag when ENV[TEST_TIERS] is nil' do - allow(ENV).to receive(:[]).and_return(nil) - expect(described_class.setup_beaker(task).rspec_opts.to_s).not_to match(%r{--tag}) - end - - it 'errors when tier specified does not exist' do - allow(ENV).to receive(:[]).and_return('expect_error') - expect { described_class.setup_beaker(task) }.to raise_error(RuntimeError, %r{not a valid test tier}) - end - - it 'errors when tiers are quoted' do - allow(ENV).to receive(:[]).and_return('"high", "medium", "low"') - expect { described_class.setup_beaker(task) }.to raise_error(RuntimeError, %r{not a valid test tier}) - end - - it 'errors when tiers are not in the allowe list' do - allow(ENV).to receive(:[]).and_return('foobar') - expect { described_class.setup_beaker(task) }.to raise_error(RuntimeError, %r{not a valid test tier}) - end - - it 'Override TEST_TIERS_ALLOWED' do - allow(ENV).to receive(:fetch).with('TEST_TIERS_ALLOWED', 'low,medium,high').and_return('dev,rnd') - allow(ENV).to receive(:[]).with('TEST_TIERS').and_return('dev') - expect(described_class.setup_beaker(task).rspec_opts.to_s).to match(%r{--tag tier_dev}) - end - - it 'Override TEST_TIERS_ALLOWED and error if tier not avalible' do - allow(ENV).to receive(:fetch).with('TEST_TIERS_ALLOWED', 'low,medium,high').and_return('dev,rnd') - allow(ENV).to receive(:[]).with('TEST_TIERS').and_return('foobar') - expect { described_class.setup_beaker(task) }.to raise_error(RuntimeError, %r{not a valid test tier}) - end - end -end