Sha256: dd23b6ede70a356d1f5aa5c130721b33354731598b37024f3afdf5fe1ed82506

Contents?: true

Size: 1.4 KB

Versions: 20

Compression:

Stored size: 1.4 KB

Contents

require "fileutils"
require "pathname"
require "tmpdir"

require "log4r"

# This class manages an isolated environment for Vagrant to
# run in. It creates a temporary directory to act as the
# working directory as well as sets a custom home directory.
#
# This class also provides various helpers to create Vagrantfiles,
# boxes, etc.
class IsolatedEnvironment
  attr_reader :homedir
  attr_reader :workdir

  # Initializes an isolated environment. You can pass in some
  # options here to configure runing custom applications in place
  # of others as well as specifying environmental variables.
  #
  # @param [Hash] apps A mapping of application name (such as "vagrant")
  #   to an alternate full path to the binary to run.
  # @param [Hash] env Additional environmental variables to inject
  #   into the execution environments.
  def initialize
    @logger = Log4r::Logger.new("test::isolated_environment")

    # Create a temporary directory for our work
    @tempdir = Dir.mktmpdir("vagrant")
    @logger.info("Initialize isolated environment: #{@tempdir}")

    # Setup the home and working directories
    @homedir = Pathname.new(File.join(@tempdir, "home"))
    @workdir = Pathname.new(File.join(@tempdir, "work"))

    @homedir.mkdir
    @workdir.mkdir
  end

  # This closes the environment by cleaning it up.
  def close
    @logger.info("Removing isolated environment: #{@tempdir}")
    FileUtils.rm_rf(@tempdir)
  end
end

Version data entries

20 entries across 17 versions & 3 rubygems

Version Path
vagrant-skytap-0.2.3 spec/support/isolated_environment.rb
vagrant-skytap-0.2.2 spec/support/isolated_environment.rb
vagrant-skytap-0.2.1 spec/support/isolated_environment.rb
vagrant-skytap-0.2.0 spec/support/isolated_environment.rb
vagrant-skytap-0.1.11 spec/support/isolated_environment.rb
vagrant-skytap-0.1.10 spec/support/isolated_environment.rb
vagrant-skytap-0.1.9 spec/support/isolated_environment.rb
vagrant-skytap-0.1.8 spec/support/isolated_environment.rb
vagrant-skytap-0.1.7 spec/support/isolated_environment.rb
vagrant-skytap-0.1.6 spec/support/isolated_environment.rb
vagrant-skytap-0.1.5 spec/support/isolated_environment.rb
vagrant-skytap-0.1.4 spec/support/isolated_environment.rb
vagrant-skytap-0.1.3 spec/support/isolated_environment.rb
vagrant-skytap-0.1.2 spec/support/isolated_environment.rb
vagrant-skytap-0.1.1a spec/support/isolated_environment.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-272fb27e0536/test/support/isolated_environment.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-1cf2a8db4ccb/test/support/isolated_environment.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-b421af58e8b3/test/support/isolated_environment.rb
vagrant-cloudstack-1.1.0 vendor/bundle/bundler/gems/vagrant-309e896975d1/test/support/isolated_environment.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/bundler/gems/vagrant-1e28f1ac31e7/test/support/isolated_environment.rb