Sha256: 21f034c28309977b8a9a4d54c98b2e85ff270ec6d0d7833d7a23863e01e3962f

Contents?: true

Size: 1.75 KB

Versions: 9

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require_relative 'acceptance/context'

FALSEY_VALUES = %w[f false no n 0].freeze

shared_context 'libvirt_acceptance' do
  include_context 'acceptance'

  # The skeleton paths that will be used to configure environments.
  let(:skeleton_paths) do
    root = File.expand_path('../acceptance/support-skeletons', __dir__)
    config.skeleton_paths.dup.unshift(root)
  end

  let(:config) do
    c = VagrantPlugins::VagrantLibvirt::Spec::Acceptance::Configuration.new
    c.clean_on_fail = FALSEY_VALUES.include?(ENV.fetch('VAGRANT_SPEC_SKIP_CLEANUP', 'false').to_s.downcase)

    c
  end

  before(:each) do
    # allow execution environment to cache boxes used
    symlink_boxes(ENV.fetch('VAGRANT_HOME', nil), environment)
  end

  after(:each) do
    # ensure we remove the symlink
    boxes_symlink = File.join(environment.homedir, 'boxes')
    File.delete(boxes_symlink) if File.symlink?(boxes_symlink)
  end

  around do |example|
    vagrant_cwd = ENV.delete('VAGRANT_CWD')
    env_provider_before = ENV.fetch('VAGRANT_DEFAULT_PROVIDER', nil)
    ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt'

    begin
      example.run
    ensure
      ENV['VAGRANT_CWD'] = vagrant_cwd if vagrant_cwd
      if env_provider_before.nil?
        ENV.delete('VAGRANT_DEFAULT_PROVIDER')
      else
        ENV['VAGRANT_DEFAULT_PROVIDER'] = env_provider_before
      end
    end
  end

  def duplicate_environment(env, *args)
    dup_env = new_environment(*args)
    symlink_boxes(env.homedir, dup_env)

    dup_env
  end

  def symlink_boxes(vagrant_home, target_env)
    return if vagrant_home.nil?

    # allow use the same boxes location as source environment
    File.symlink File.realpath(File.join(vagrant_home, 'boxes')), File.join(target_env.homedir, 'boxes')
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
vagrant-libvirt-0.10.8 spec/support/libvirt_acceptance_context.rb
vagrant-libvirt-0.10.7 spec/support/libvirt_acceptance_context.rb
vagrant-libvirt-0.10.6 spec/support/libvirt_acceptance_context.rb
vagrant-libvirt-0.10.5 spec/support/libvirt_acceptance_context.rb
vagrant-libvirt-0.10.4 spec/support/libvirt_acceptance_context.rb
vagrant-libvirt-0.10.3 spec/support/libvirt_acceptance_context.rb
vagrant-libvirt-0.10.2 spec/support/libvirt_acceptance_context.rb
vagrant-libvirt-0.10.1 spec/support/libvirt_acceptance_context.rb
vagrant-libvirt-0.10.0 spec/support/libvirt_acceptance_context.rb