Clean up test load paths
This commit is contained in:
parent
830c7bcad1
commit
42a5e02db4
|
@ -3,16 +3,14 @@ require "rspec/autorun"
|
|||
|
||||
require "log4r"
|
||||
|
||||
# Add this directory to the load path, since it just makes
|
||||
# everything else so much easier.
|
||||
$:.unshift File.expand_path("../", __FILE__)
|
||||
# Add the test directory to the load path
|
||||
$:.unshift File.expand_path("../../", __FILE__)
|
||||
|
||||
# Load in the supporting files for our tests
|
||||
require "support/shared/base_context"
|
||||
require "support/config"
|
||||
require "support/virtualbox"
|
||||
require "support/matchers/match_output"
|
||||
require "acceptance/support/shared/base_context"
|
||||
require "acceptance/support/config"
|
||||
require "acceptance/support/virtualbox"
|
||||
require "acceptance/support/matchers/match_output"
|
||||
|
||||
# Do not buffer output
|
||||
$stdout.sync = true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require File.expand_path("../base", __FILE__)
|
||||
require "support/shared/command_examples"
|
||||
require "acceptance/support/shared/command_examples"
|
||||
|
||||
describe "vagrant destroy" do
|
||||
include_context "acceptance"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require File.expand_path("../base", __FILE__)
|
||||
require "support/shared/command_examples"
|
||||
require "acceptance/support/shared/command_examples"
|
||||
|
||||
describe "vagrant halt" do
|
||||
include_context "acceptance"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require File.expand_path("../base", __FILE__)
|
||||
require "support/shared/command_examples"
|
||||
require "acceptance/support/shared/command_examples"
|
||||
|
||||
describe "vagrant resume" do
|
||||
include_context "acceptance"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require File.expand_path("../base", __FILE__)
|
||||
require "support/shared/command_examples"
|
||||
require "acceptance/support/shared/command_examples"
|
||||
|
||||
describe "vagrant ssh" do
|
||||
include_context "acceptance"
|
||||
|
|
|
@ -1,45 +1,22 @@
|
|||
require "fileutils"
|
||||
require "pathname"
|
||||
|
||||
require "log4r"
|
||||
require "childprocess"
|
||||
|
||||
require "support/tempdir"
|
||||
require "support/virtualbox"
|
||||
require "acceptance/support/virtualbox"
|
||||
require "support/isolated_environment"
|
||||
|
||||
module Acceptance
|
||||
# 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.
|
||||
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.
|
||||
class IsolatedEnvironment < ::IsolatedEnvironment
|
||||
def initialize(apps=nil, env=nil)
|
||||
super()
|
||||
|
||||
@logger = Log4r::Logger.new("acceptance::isolated_environment")
|
||||
|
||||
@apps = apps || {}
|
||||
@env = env || {}
|
||||
|
||||
# Create a temporary directory for our work
|
||||
@tempdir = Tempdir.new("vagrant")
|
||||
@logger.info("Initialize isolated environment: #{@tempdir.path}")
|
||||
|
||||
# Setup the home and working directories
|
||||
@homedir = Pathname.new(File.join(@tempdir.path, "home"))
|
||||
@workdir = Pathname.new(File.join(@tempdir.path, "work"))
|
||||
|
||||
@homedir.mkdir
|
||||
@workdir.mkdir
|
||||
|
||||
# Set the home directory and virtualbox home directory environmental
|
||||
# variables so that Vagrant and VirtualBox see the proper paths here.
|
||||
@env["HOME"] = @homedir.to_s
|
||||
|
@ -149,9 +126,8 @@ module Acceptance
|
|||
# environment.
|
||||
delete_virtual_machines if VirtualBox.find_vboxsvc
|
||||
|
||||
# Delete the temporary directory
|
||||
@logger.info("Removing isolated environment: #{@tempdir.path}")
|
||||
FileUtils.rm_rf(@tempdir.path)
|
||||
# Let the parent handle cleaning up
|
||||
super
|
||||
end
|
||||
|
||||
def delete_virtual_machines
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require "support/output"
|
||||
require "acceptance/support/output"
|
||||
|
||||
# This creates a matcher that is used to match against certain
|
||||
# Vagrant output. Vagrant output is not what is being tested,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require "support/isolated_environment"
|
||||
require "support/output"
|
||||
require "support/virtualbox"
|
||||
require "acceptance/support/isolated_environment"
|
||||
require "acceptance/support/output"
|
||||
require "acceptance/support/virtualbox"
|
||||
|
||||
shared_context "acceptance" do
|
||||
# Setup variables for the loggers of this test. These can be used to
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require File.expand_path("../base", __FILE__)
|
||||
require "support/shared/command_examples"
|
||||
require "acceptance/support/shared/command_examples"
|
||||
|
||||
describe "vagrant suspend" do
|
||||
include_context "acceptance"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require File.expand_path("../base", __FILE__)
|
||||
require "support/shared/command_examples"
|
||||
require "acceptance/support/shared/command_examples"
|
||||
|
||||
describe "vagrant up", "basics" do
|
||||
include_context "acceptance"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require File.expand_path("../base", __FILE__)
|
||||
require "support/shared/command_examples"
|
||||
require "acceptance/support/shared/command_examples"
|
||||
|
||||
describe "vagrant up", "with a box URL set" do
|
||||
include_context "acceptance"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require File.expand_path("../base", __FILE__)
|
||||
require "support/matchers/have_color"
|
||||
require "acceptance/support/matchers/have_color"
|
||||
|
||||
describe "vagrant and color output" do
|
||||
include_context "acceptance"
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
require "fileutils"
|
||||
require "pathname"
|
||||
|
||||
require "log4r"
|
||||
|
||||
require "support/tempdir"
|
||||
|
||||
# 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("isolated_environment")
|
||||
|
||||
# Create a temporary directory for our work
|
||||
@tempdir = Tempdir.new("vagrant")
|
||||
@logger.info("Initialize isolated environment: #{@tempdir.path}")
|
||||
|
||||
# Setup the home and working directories
|
||||
@homedir = Pathname.new(File.join(@tempdir.path, "home"))
|
||||
@workdir = Pathname.new(File.join(@tempdir.path, "work"))
|
||||
|
||||
@homedir.mkdir
|
||||
@workdir.mkdir
|
||||
end
|
||||
|
||||
# This closes the environment by cleaning it up.
|
||||
def close
|
||||
@logger.info("Removing isolated environment: #{@tempdir.path}")
|
||||
FileUtils.rm_rf(@tempdir.path)
|
||||
end
|
||||
end
|
|
@ -5,13 +5,11 @@ require "rspec/autorun"
|
|||
# classes to test.
|
||||
require "vagrant"
|
||||
|
||||
# Add this directory to the load path, since it just makes
|
||||
# everything else easier.
|
||||
$:.unshift File.expand_path("../", __FILE__)
|
||||
# Add the test directory to the load path
|
||||
$:.unshift File.expand_path("../../", __FILE__)
|
||||
|
||||
# Load in helpers
|
||||
require "support/shared/base_context"
|
||||
require "unit/support/shared/base_context"
|
||||
|
||||
# Do not buffer output
|
||||
$stdout.sync = true
|
||||
|
|
|
@ -3,42 +3,10 @@ require "pathname"
|
|||
|
||||
require "log4r"
|
||||
|
||||
require "support/tempdir"
|
||||
require "support/isolated_environment"
|
||||
|
||||
module Unit
|
||||
# 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(apps=nil, env=nil)
|
||||
@logger = Log4r::Logger.new("unit::isolated_environment")
|
||||
|
||||
# Create a temporary directory for our work
|
||||
@tempdir = Tempdir.new("vagrant")
|
||||
@logger.info("Initialize isolated environment: #{@tempdir.path}")
|
||||
|
||||
# Setup the home and working directories
|
||||
@homedir = Pathname.new(File.join(@tempdir.path, "home"))
|
||||
@workdir = Pathname.new(File.join(@tempdir.path, "work"))
|
||||
|
||||
@homedir.mkdir
|
||||
@workdir.mkdir
|
||||
end
|
||||
|
||||
class IsolatedEnvironment < ::IsolatedEnvironment
|
||||
def create_vagrant_env
|
||||
Vagrant::Environment.new(:cwd => @workdir, :home_path => @homedir)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require "tempfile"
|
||||
|
||||
require "support/isolated_environment"
|
||||
require "unit/support/isolated_environment"
|
||||
|
||||
shared_context "unit" do
|
||||
# This creates an isolated environment so that Vagrant doesn't
|
||||
|
|
Loading…
Reference in New Issue