From 30dd638e3c7a7d59c23dcc550a82ce4a777d1e52 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 19 Apr 2012 21:45:17 -0700 Subject: [PATCH] Remove legacy unit tests. --- test/unit_legacy/locales/en.yml | 8 - test/unit_legacy/test_helper.rb | 32 -- .../vagrant/action/box/destroy_test.rb | 18 - .../vagrant/action/box/download_test.rb | 125 ---- .../vagrant/action/box/package_test.rb | 25 - .../vagrant/action/box/unpackage_test.rb | 84 --- .../vagrant/action/box/verify_test.rb | 30 - .../vagrant/action/env/set_test.rb | 24 - .../vagrant/action/general/package_test.rb | 268 --------- .../vagrant/action/general/validate_test.rb | 31 - .../vagrant/action/vm/boot_test.rb | 66 --- .../action/vm/check_accessible_test.rb | 61 -- .../vagrant/action/vm/check_box_test.rb | 61 -- .../action/vm/check_guest_additions_test.rb | 9 - .../action/vm/clean_machine_folder_test.rb | 84 --- .../action/vm/clear_forwarded_ports_test.rb | 52 -- .../action/vm/clear_nfs_exports_test.rb | 22 - .../action/vm/clear_shared_folders_test.rb | 40 -- .../vagrant/action/vm/customize_test.rb | 37 -- .../vagrant/action/vm/destroy_test.rb | 25 - .../destroy_unused_network_interfaces_test.rb | 49 -- .../vagrant/action/vm/discard_state_test.rb | 45 -- .../vagrant/action/vm/export_test.rb | 107 ---- .../action/vm/forward_ports_helpers_test.rb | 77 --- .../vagrant/action/vm/forward_ports_test.rb | 197 ------- .../vagrant/action/vm/halt_test.rb | 79 --- .../vagrant/action/vm/host_name_test.rb | 36 -- .../vagrant/action/vm/import_test.rb | 66 --- .../action/vm/match_mac_address_test.rb | 40 -- .../vagrant/action/vm/modify_test.rb | 38 -- .../vagrant/action/vm/network_test.rb | 286 ---------- .../vagrant/action/vm/nfs_helpers_test.rb | 26 - .../unit_legacy/vagrant/action/vm/nfs_test.rb | 260 --------- .../vagrant/action/vm/package_test.rb | 25 - .../action/vm/package_vagrantfile_test.rb | 46 -- .../vagrant/action/vm/provision_test.rb | 65 --- .../action/vm/provisioner_cleanup_test.rb | 56 -- .../vagrant/action/vm/resume_test.rb | 35 -- .../vagrant/action/vm/share_folders_test.rb | 144 ----- .../vagrant/action/vm/suspend_test.rb | 35 -- test/unit_legacy/vagrant/action_test.rb | 89 --- .../vagrant/box_collection_test.rb | 45 -- test/unit_legacy/vagrant/box_test.rb | 74 --- test/unit_legacy/vagrant/cli_test.rb | 35 -- test/unit_legacy/vagrant/command/base_test.rb | 23 - .../vagrant/command/group_base_test.rb | 15 - .../vagrant/command/helpers_test.rb | 88 --- test/unit_legacy/vagrant/command/init_test.rb | 10 - .../vagrant/command/package_test.rb | 27 - test/unit_legacy/vagrant/config/base_test.rb | 52 -- .../vagrant/config/error_recorder_test.rb | 18 - test/unit_legacy/vagrant/config/ssh_test.rb | 12 - .../vagrant/config/vagrant_test.rb | 35 -- .../vagrant/config/vm/provisioner_test.rb | 92 --- test/unit_legacy/vagrant/config/vm_test.rb | 47 -- test/unit_legacy/vagrant/config_test.rb | 148 ----- .../vagrant/downloaders/http_test.rb | 93 --- test/unit_legacy/vagrant/environment_test.rb | 539 ------------------ test/unit_legacy/vagrant/errors_test.rb | 42 -- test/unit_legacy/vagrant/hosts/base_test.rb | 46 -- test/unit_legacy/vagrant/hosts/bsd_test.rb | 53 -- test/unit_legacy/vagrant/hosts/linux_test.rb | 54 -- test/unit_legacy/vagrant/plugin_test.rb | 9 - .../vagrant/provisioners/base_test.rb | 63 -- .../vagrant/provisioners/chef_client_test.rb | 190 ------ .../vagrant/provisioners/chef_solo_test.rb | 115 ---- .../vagrant/provisioners/chef_test.rb | 209 ------- .../provisioners/puppet_server_test.rb | 68 --- .../vagrant/provisioners/puppet_test.rb | 182 ------ .../vagrant/provisioners/shell_test.rb | 79 --- test/unit_legacy/vagrant/ssh/session_test.rb | 40 -- test/unit_legacy/vagrant/ssh_test.rb | 304 ---------- test/unit_legacy/vagrant/systems/base_test.rb | 18 - .../unit_legacy/vagrant/systems/linux_test.rb | 104 ---- test/unit_legacy/vagrant/util/busy_test.rb | 106 ---- test/unit_legacy/vagrant/util/counter_test.rb | 29 - .../unit_legacy/vagrant/util/platform_test.rb | 18 - .../vagrant/util/stacked_proc_runner_test.rb | 43 -- .../vagrant/util/template_renderer_test.rb | 145 ----- test/unit_legacy/vagrant/vm_test.rb | 300 ---------- 80 files changed, 6473 deletions(-) delete mode 100644 test/unit_legacy/locales/en.yml delete mode 100644 test/unit_legacy/test_helper.rb delete mode 100644 test/unit_legacy/vagrant/action/box/destroy_test.rb delete mode 100644 test/unit_legacy/vagrant/action/box/download_test.rb delete mode 100644 test/unit_legacy/vagrant/action/box/package_test.rb delete mode 100644 test/unit_legacy/vagrant/action/box/unpackage_test.rb delete mode 100644 test/unit_legacy/vagrant/action/box/verify_test.rb delete mode 100644 test/unit_legacy/vagrant/action/env/set_test.rb delete mode 100644 test/unit_legacy/vagrant/action/general/package_test.rb delete mode 100644 test/unit_legacy/vagrant/action/general/validate_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/boot_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/check_accessible_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/check_box_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/check_guest_additions_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/clean_machine_folder_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/clear_forwarded_ports_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/clear_nfs_exports_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/clear_shared_folders_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/customize_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/destroy_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/destroy_unused_network_interfaces_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/discard_state_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/export_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/forward_ports_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/halt_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/host_name_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/import_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/match_mac_address_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/modify_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/network_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/nfs_helpers_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/nfs_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/package_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/package_vagrantfile_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/provision_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/provisioner_cleanup_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/resume_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/share_folders_test.rb delete mode 100644 test/unit_legacy/vagrant/action/vm/suspend_test.rb delete mode 100644 test/unit_legacy/vagrant/action_test.rb delete mode 100644 test/unit_legacy/vagrant/box_collection_test.rb delete mode 100644 test/unit_legacy/vagrant/box_test.rb delete mode 100644 test/unit_legacy/vagrant/cli_test.rb delete mode 100644 test/unit_legacy/vagrant/command/base_test.rb delete mode 100644 test/unit_legacy/vagrant/command/group_base_test.rb delete mode 100644 test/unit_legacy/vagrant/command/helpers_test.rb delete mode 100644 test/unit_legacy/vagrant/command/init_test.rb delete mode 100644 test/unit_legacy/vagrant/command/package_test.rb delete mode 100644 test/unit_legacy/vagrant/config/base_test.rb delete mode 100644 test/unit_legacy/vagrant/config/error_recorder_test.rb delete mode 100644 test/unit_legacy/vagrant/config/ssh_test.rb delete mode 100644 test/unit_legacy/vagrant/config/vagrant_test.rb delete mode 100644 test/unit_legacy/vagrant/config/vm/provisioner_test.rb delete mode 100644 test/unit_legacy/vagrant/config/vm_test.rb delete mode 100644 test/unit_legacy/vagrant/config_test.rb delete mode 100644 test/unit_legacy/vagrant/downloaders/http_test.rb delete mode 100644 test/unit_legacy/vagrant/environment_test.rb delete mode 100644 test/unit_legacy/vagrant/errors_test.rb delete mode 100644 test/unit_legacy/vagrant/hosts/base_test.rb delete mode 100644 test/unit_legacy/vagrant/hosts/bsd_test.rb delete mode 100644 test/unit_legacy/vagrant/hosts/linux_test.rb delete mode 100644 test/unit_legacy/vagrant/plugin_test.rb delete mode 100644 test/unit_legacy/vagrant/provisioners/base_test.rb delete mode 100644 test/unit_legacy/vagrant/provisioners/chef_client_test.rb delete mode 100644 test/unit_legacy/vagrant/provisioners/chef_solo_test.rb delete mode 100644 test/unit_legacy/vagrant/provisioners/chef_test.rb delete mode 100644 test/unit_legacy/vagrant/provisioners/puppet_server_test.rb delete mode 100644 test/unit_legacy/vagrant/provisioners/puppet_test.rb delete mode 100644 test/unit_legacy/vagrant/provisioners/shell_test.rb delete mode 100644 test/unit_legacy/vagrant/ssh/session_test.rb delete mode 100644 test/unit_legacy/vagrant/ssh_test.rb delete mode 100644 test/unit_legacy/vagrant/systems/base_test.rb delete mode 100644 test/unit_legacy/vagrant/systems/linux_test.rb delete mode 100644 test/unit_legacy/vagrant/util/busy_test.rb delete mode 100644 test/unit_legacy/vagrant/util/counter_test.rb delete mode 100644 test/unit_legacy/vagrant/util/platform_test.rb delete mode 100644 test/unit_legacy/vagrant/util/stacked_proc_runner_test.rb delete mode 100644 test/unit_legacy/vagrant/util/template_renderer_test.rb delete mode 100644 test/unit_legacy/vagrant/vm_test.rb diff --git a/test/unit_legacy/locales/en.yml b/test/unit_legacy/locales/en.yml deleted file mode 100644 index c57214ace58..00000000000 --- a/test/unit_legacy/locales/en.yml +++ /dev/null @@ -1,8 +0,0 @@ -en: - vagrant: - test: - errors: - test_key: This is a test key - test_key_with_interpolation: This is a test key that says %{key} - alternate: - test_key: This is an alternate diff --git a/test/unit_legacy/test_helper.rb b/test/unit_legacy/test_helper.rb deleted file mode 100644 index f6a20c9b181..00000000000 --- a/test/unit_legacy/test_helper.rb +++ /dev/null @@ -1,32 +0,0 @@ -# Add this folder to the load path for "test_helper" -$:.unshift(File.dirname(__FILE__)) - -require 'vagrant' -require 'contest' -require 'mocha' - -# Try to load ruby debug since its useful if it is available. -# But not a big deal if its not available (probably on a non-MRI -# platform) -begin - require 'ruby-debug' -rescue LoadError -end - -# Do not buffer output for tests -$stdout.sync = true -$stderr.sync = true - -# Set the home directory to some temporary directory -ENV["HOME"] = Vagrant.source_root.join("test", "tmp", "home").to_s - -# Set the log output to nothing -ENV["VAGRANT_LOG"] = "NULL" - -# Add the I18n locale for tests -I18n.load_path << File.expand_path("../locales/en.yml", __FILE__) - -class Test::Unit::TestCase - include Vagrant::TestHelpers -end - diff --git a/test/unit_legacy/vagrant/action/box/destroy_test.rb b/test/unit_legacy/vagrant/action/box/destroy_test.rb deleted file mode 100644 index 0deb96597a8..00000000000 --- a/test/unit_legacy/vagrant/action/box/destroy_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "test_helper" - -class DestroyBoxActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::Box::Destroy - @app, @env = action_env - @env["box"] = Vagrant::Box.new(vagrant_env, "foo") - - @instance = @klass.new(@app, @env) - end - - should "delete the box directory" do - seq = sequence("seq") - FileUtils.expects(:rm_rf).with(@env["box"].directory).in_sequence(seq) - @app.expects(:call).with(@env).once.in_sequence(seq) - @instance.call(@env) - end -end diff --git a/test/unit_legacy/vagrant/action/box/download_test.rb b/test/unit_legacy/vagrant/action/box/download_test.rb deleted file mode 100644 index 69196cabeb5..00000000000 --- a/test/unit_legacy/vagrant/action/box/download_test.rb +++ /dev/null @@ -1,125 +0,0 @@ -require "test_helper" - -class DownloadBoxActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::Box::Download - @app, @env = action_env - @env["box"] = Vagrant::Box.new(vagrant_env, "foo") - @env["box"].uri = "http://google.com" - end - - context "initializing" do - should "initialize download classes" do - @klass.new(@app, @env) - assert_equal [Vagrant::Downloaders::HTTP, Vagrant::Downloaders::File], @env["download.classes"] - end - end - - context "with an instance" do - setup do - @instance = @klass.new(@app, @env) - end - - context "calling" do - should "call the proper methods in sequence" do - seq = sequence("seq") - @instance.expects(:instantiate_downloader).in_sequence(seq).returns(true) - @instance.expects(:download).in_sequence(seq) - @app.expects(:call).with(@env).in_sequence(seq) - @instance.expects(:recover).with(@env).in_sequence(seq) - @instance.call(@env) - end - end - - context "instantiating downloader" do - should "instantiate the proper class" do - instance = mock("instance") - Vagrant::Downloaders::HTTP.expects(:new).with(@env).returns(instance) - instance.expects(:prepare).with(@env["box"].uri).once - assert @instance.instantiate_downloader - end - - should "complain that the file doesn't exist if the URI is invalid for any downloaders" do - @env["box"].uri = "foobar" - assert_raises(Vagrant::Errors::DownloaderFileDoesntExist) { - @instance.instantiate_downloader - } - end - end - - context "downloading" do - setup do - @path = "foo" - - @tempfile = mock("tempfile") - @tempfile.stubs(:path).returns(@path) - - @instance.stubs(:with_tempfile).yields(@tempfile) - @instance.stubs(:download_to) - end - - should "make a tempfile and copy the URI contents to it" do - @instance.expects(:with_tempfile).yields(@tempfile) - @instance.expects(:download_to).with(@tempfile) - @instance.download - end - - should "save the tempfile path" do - @instance.download - assert @env.has_key?("download.temp_path") - assert_equal @tempfile.path, @env["download.temp_path"] - assert_equal @tempfile.path, @instance.temp_path - end - end - - context "tempfile" do - should "create a tempfile in the vagrant tmp directory" do - File.expects(:open).with { |name, bitmask| - name.to_s =~ /#{Vagrant::Action::Box::Download::BASENAME}/ && name.to_s =~ /#{@env.env.tmp_path}/ - }.once - @instance.with_tempfile - end - - should "yield the tempfile object" do - @tempfile = mock("tempfile") - File.expects(:open).yields(@tempfile) - - @instance.with_tempfile do |otherfile| - assert @tempfile.equal?(otherfile) - end - end - end - - context "cleaning up" do - setup do - @temp_path = "foo" - @instance.stubs(:temp_path).returns(@temp_path) - File.stubs(:exist?).returns(true) - end - - should "delete the temporary file if it exists" do - File.expects(:unlink).with(@temp_path).once - @instance.recover(@env) - end - - should "not delete anything if it doesn't exist" do - File.stubs(:exist?).returns(false) - File.expects(:unlink).never - @instance.recover(@env) - end - end - - context "downloading to" do - setup do - @downloader = mock("downloader") - @instance.instance_variable_set(:@downloader, @downloader) - end - - should "call download! on the download with the URI and tempfile" do - tempfile = "foo" - @downloader.expects(:download!).with(@env["box"].uri, tempfile) - @instance.download_to(tempfile) - end - end - end -end diff --git a/test/unit_legacy/vagrant/action/box/package_test.rb b/test/unit_legacy/vagrant/action/box/package_test.rb deleted file mode 100644 index d2d51b129e1..00000000000 --- a/test/unit_legacy/vagrant/action/box/package_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -require "test_helper" - -class PackageBoxActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::Box::Package - @app, @env = action_env - @env["box"] = Vagrant::Box.new(vagrant_env, "foo") - - @instance = @klass.new(@app, @env) - end - - should "be a subclass of general packaging middleware" do - assert @instance.is_a?(Vagrant::Action::General::Package) - end - - should "set the package directory then call parent" do - @instance.expects(:general_call).once.with() do |env| - assert env["package.directory"] - assert_equal env["package.directory"], @env["box"].directory - true - end - - @instance.call(@env) - end -end diff --git a/test/unit_legacy/vagrant/action/box/unpackage_test.rb b/test/unit_legacy/vagrant/action/box/unpackage_test.rb deleted file mode 100644 index 3082a21d52b..00000000000 --- a/test/unit_legacy/vagrant/action/box/unpackage_test.rb +++ /dev/null @@ -1,84 +0,0 @@ -require "test_helper" - -class UnpackageBoxActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::Box::Unpackage - @app, @env = action_env - @env["box"] = Vagrant::Box.new(vagrant_env, "foo") - - @instance = @klass.new(@app, @env) - end - - context "calling" do - should "call the proper chain" do - seq = sequence("sequence") - @instance.expects(:setup_box_directory).in_sequence(seq).returns(true) - @instance.expects(:decompress).in_sequence(seq) - @app.expects(:call).with(@env) - @instance.call(@env) - end - end - - context "cleaning up" do - setup do - @instance.stubs(:box_directory).returns("foo") - File.stubs(:directory?).returns(false) - FileUtils.stubs(:rm_rf) - end - - should "do nothing if box directory is not set" do - @instance.stubs(:box_directory).returns(nil) - File.expects(:directory?).never - FileUtils.expects(:rm_rf).never - @instance.recover(nil) - end - - should "do nothing if not a directory" do - FileUtils.expects(:rm_rf).never - @instance.recover(nil) - end - - should "remove the directory if exists" do - File.expects(:directory?).with(@instance.box_directory).once.returns(true) - FileUtils.expects(:rm_rf).with(@instance.box_directory).once - @instance.recover(nil) - end - end - - context "setting up the box directory" do - setup do - File.stubs(:directory?).returns(false) - FileUtils.stubs(:mkdir_p) - end - - should "error the environment if the box already exists" do - File.expects(:directory?).returns(true) - assert_raises(Vagrant::Errors::BoxAlreadyExists) { - @instance.setup_box_directory - } - end - - should "create the directory" do - FileUtils.expects(:mkdir_p).with(@env["box"].directory).once - @instance.setup_box_directory - end - end - - context "decompressing" do - setup do - @env["download.temp_path"] = "bar" - - Dir.stubs(:chdir).yields - end - - should "change to the box directory" do - Dir.expects(:chdir).with(@env["box"].directory) - @instance.decompress - end - - should "open the tar file within the new directory, and extract it all" do - Archive::Tar::Minitar.expects(:unpack).with(@env["download.temp_path"], @env["box"].directory.to_s).once - @instance.decompress - end - end -end diff --git a/test/unit_legacy/vagrant/action/box/verify_test.rb b/test/unit_legacy/vagrant/action/box/verify_test.rb deleted file mode 100644 index f55f2e034f6..00000000000 --- a/test/unit_legacy/vagrant/action/box/verify_test.rb +++ /dev/null @@ -1,30 +0,0 @@ -require "test_helper" - -class VerifyBoxActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::Box::Verify - @app, @env = action_env - @env["box"] = Vagrant::Box.new(vagrant_env, "foo") - - @instance = @klass.new(@app, @env) - end - - context "calling" do - should "continue fine if verification succeeds" do - seq = sequence("seq") - VirtualBox::Appliance.expects(:new).with(@env["box"].ovf_file.to_s).in_sequence(seq) - @app.expects(:call).with(@env).once.in_sequence(seq) - assert_nothing_raised { - @instance.call(@env) - } - end - - should "halt chain if verification fails" do - VirtualBox::Appliance.expects(:new).with(@env["box"].ovf_file.to_s).raises(Exception) - @app.expects(:call).with(@env).never - assert_raises(Vagrant::Errors::BoxVerificationFailed) { - @instance.call(@env) - } - end - end -end diff --git a/test/unit_legacy/vagrant/action/env/set_test.rb b/test/unit_legacy/vagrant/action/env/set_test.rb deleted file mode 100644 index 8aea4c2b66d..00000000000 --- a/test/unit_legacy/vagrant/action/env/set_test.rb +++ /dev/null @@ -1,24 +0,0 @@ -require "test_helper" - -class SetEnvActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::Env::Set - @app, @env = action_env - @env.clear - end - - should "merge in the given options" do - @klass.new(@app, @env, :foo => :bar) - assert_equal :bar, @env[:foo] - end - - should "not merge in anything if not given" do - @klass.new(@app, @env) - assert @env.empty? - end - - should "just continue the chain" do - @app.expects(:call).with(@env) - @klass.new(@app, @env).call(@env) - end -end diff --git a/test/unit_legacy/vagrant/action/general/package_test.rb b/test/unit_legacy/vagrant/action/general/package_test.rb deleted file mode 100644 index be71bbb6150..00000000000 --- a/test/unit_legacy/vagrant/action/general/package_test.rb +++ /dev/null @@ -1,268 +0,0 @@ -require "test_helper" - -class PackageGeneralActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::General::Package - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - end - - context "initializing" do - setup do - @tar_path = "foo" - File.stubs(:exist?).returns(false) - @klass.any_instance.stubs(:tar_path).returns(@tar_path) - end - - should "initialize fine" do - @klass.new(@app, @env) - end - - should "set the output path to configured by default" do - @klass.new(@app, @env) - assert_equal @env["config"].package.name, @env["package.output"] - end - - should "not set the output path if it is already set" do - @env["package.output"] = "foo" - @klass.new(@app, @env) - assert_equal "foo", @env["package.output"] - end - - should "set the included files to empty by default" do - @klass.new(@app, @env) - assert_equal [], @env["package.include"] - end - - should "not set the include path if it is already set" do - @env["package.include"] = "foo" - @klass.new(@app, @env) - assert_equal "foo", @env["package.include"] - end - end - - context "with an instance" do - setup do - File.stubs(:exist?).returns(false) - File.stubs(:directory?).returns(true) - @instance = @klass.new(@app, @env) - - @env["package.directory"] = "foo" - end - - context "calling" do - should "call the proper methods then continue chain" do - seq = sequence("seq") - @instance.expects(:verify_files_to_copy).in_sequence(seq).returns(true) - @instance.expects(:compress).in_sequence(seq) - @app.expects(:call).with(@env).in_sequence(seq) - @instance.call(@env) - end - - should "halt the chain if the output file already exists" do - File.expects(:exist?).returns(true) - @app.expects(:call).never - assert_raises(Vagrant::Errors::PackageOutputExists) { - @instance.call(@env) - } - end - - should "halt the chain if directory isn't set" do - @env["package.directory"] = nil - @app.expects(:call).never - assert_raises(Vagrant::Errors::PackageRequiresDirectory) { - @instance.call(@env) - } - end - - should "halt the chain if directory doesn't exist" do - File.expects(:directory?).with(@env["package.directory"]).returns(false) - @app.expects(:call).never - assert_raises(Vagrant::Errors::PackageRequiresDirectory) { - @instance.call(@env) - } - end - end - - context "cleaning up" do - setup do - File.stubs(:exist?).returns(false) - File.stubs(:delete) - - @instance.stubs(:tar_path).returns("foo") - end - - should "do nothing if the file doesn't exist" do - File.expects(:exist?).with(@instance.tar_path).returns(false) - File.expects(:delete).never - - @instance.recover(@env) - end - - should "delete the packaged box if it exists" do - File.expects(:exist?).returns(true) - File.expects(:delete).with(@instance.tar_path).once - - @instance.recover(@env) - end - end - - context "files to copy" do - setup do - @env["package.include"] = [] - @package_dir = Pathname.new(@env["package.directory"]).join("include") - end - - should "have included files whole path if relative" do - path = "lib/foo" - @env["package.include"] = [path] - result = @instance.files_to_copy - assert_equal @package_dir.join(path), result[path] - end - - should "have the filename if an absolute path" do - path = "/foo/bar" - @env["package.include"] = [path] - result = @instance.files_to_copy - assert_equal @package_dir.join("bar"), result[path] - end - - should "include the Vagrantfile if specified" do - @env["package.vagrantfile"] = "foo" - result = @instance.files_to_copy - assert_equal @package_dir.join("_Vagrantfile"), result["foo"] - end - end - - context "verifying files to copy" do - setup do - @env["package.include"] = ["foo"] - File.stubs(:exist?).returns(true) - end - - should "error if included file is not found" do - File.expects(:exist?).with("foo").returns(false) - assert_raises(Vagrant::Errors::PackageIncludeMissing) { - @instance.verify_files_to_copy - } - end - - should "return true if all exist" do - assert_nothing_raised { - assert @instance.verify_files_to_copy - } - end - end - - context "copying include files" do - setup do - @env["package.include"] = [] - end - - should "do nothing if no include files are specified" do - assert @env["package.include"].empty? - FileUtils.expects(:mkdir_p).never - FileUtils.expects(:cp).never - @instance.copy_include_files - end - - should "create the include directory and copy files to it" do - @env["package.include"] = ["/foo/bar", "lib/foo"] - seq = sequence("seq") - @instance.files_to_copy.each do |from, to| - FileUtils.expects(:mkdir_p).with(to.parent).in_sequence(seq) - File.expects(:directory?).with(from).returns(false).in_sequence(seq) - FileUtils.expects(:cp).with(from, to).in_sequence(seq) - end - - @instance.copy_include_files - end - - should "create the include directory and recursively copy globbed files to it" do - @env["package.include"] = ["foo*.txt"] - seq = sequence("seq") - @instance.files_to_copy.each do |from, to| - FileUtils.expects(:mkdir_p).with(to.parent).in_sequence(seq) - File.expects(:directory?).with(from).returns(true).in_sequence(seq) - Dir.expects(:glob).with(from).returns(from).in_sequence(seq) - FileUtils.expects(:cp_r).with(from, to.parent).in_sequence(seq) - end - - @instance.copy_include_files - end - end - - context "compression" do - setup do - @env["package.include"] = [] - - @tar_path = "foo" - @instance.stubs(:tar_path).returns(@tar_path) - - @pwd = "bar" - FileUtils.stubs(:pwd).returns(@pwd) - FileUtils.stubs(:cd) - - @file = mock("file") - File.stubs(:open).yields(@file) - - @output = mock("output") - @tar = Archive::Tar::Minitar - Archive::Tar::Minitar::Output.stubs(:open).yields(@output) - @tar.stubs(:pack_file) - - @instance.stubs(:copy_include_files) - end - - should "open the tar file with the tar path properly" do - File.expects(:open).with(@tar_path, Vagrant::Util::Platform.tar_file_options).once - @instance.compress - end - - should "open tar file" do - Archive::Tar::Minitar::Output.expects(:open).with(@file).once - @instance.compress - end - - #---------------------------------------------------------------- - # Methods below this comment test the block yielded by Minitar open - #---------------------------------------------------------------- - should "cd to the directory and append the directory" do - @files = [] - compress_seq = sequence("compress_seq") - - FileUtils.expects(:pwd).once.returns(@pwd).in_sequence(compress_seq) - @instance.expects(:copy_include_files).once.in_sequence(compress_seq) - FileUtils.expects(:cd).with(@env["package.directory"]).in_sequence(compress_seq) - Dir.expects(:glob).returns(@files).in_sequence(compress_seq) - - 5.times do |i| - file = mock("file#{i}") - @tar.expects(:pack_file).with(file, @output).once.in_sequence(compress_seq) - @files << file - end - - FileUtils.expects(:cd).with(@pwd).in_sequence(compress_seq) - @instance.compress - end - - should "pop back to the current directory even if an exception is raised" do - cd_seq = sequence("cd_seq") - FileUtils.expects(:cd).with(@env["package.directory"]).raises(Exception).in_sequence(cd_seq) - FileUtils.expects(:cd).with(@pwd).in_sequence(cd_seq) - - assert_raises(Exception) { - @instance.compress - } - end - end - - context "tar path" do - should "return proper path" do - assert_equal File.join(FileUtils.pwd, @env["package.output"]), @instance.tar_path - end - end - end -end diff --git a/test/unit_legacy/vagrant/action/general/validate_test.rb b/test/unit_legacy/vagrant/action/general/validate_test.rb deleted file mode 100644 index 00814bb7739..00000000000 --- a/test/unit_legacy/vagrant/action/general/validate_test.rb +++ /dev/null @@ -1,31 +0,0 @@ -require "test_helper" - -class ValidateGeneralActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::General::Validate - @app, @env = action_env - end - - should "initialize fine" do - @klass.new(@app, @env) - end - - should "validate and call up" do - @instance = @klass.new(@app, @env) - - seq = sequence("seq") - @env["config"].expects(:validate!).once.in_sequence(seq) - @app.expects(:call).with(@env).once.in_sequence(seq) - @instance.call(@env) - end - - should "not validate if env says not to" do - @env["validate"] = false - @instance = @klass.new(@app, @env) - - seq = sequence("seq") - @env["config"].expects(:validate!).never - @app.expects(:call).with(@env).once.in_sequence(seq) - @instance.call(@env) - end -end diff --git a/test/unit_legacy/vagrant/action/vm/boot_test.rb b/test/unit_legacy/vagrant/action/vm/boot_test.rb deleted file mode 100644 index 481770e4e15..00000000000 --- a/test/unit_legacy/vagrant/action/vm/boot_test.rb +++ /dev/null @@ -1,66 +0,0 @@ -require "test_helper" - -class BootVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Boot - @app, @env = action_env - - @vm = mock("vm") - @vm.stubs(:ssh).returns(mock("ssh")) - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - context "calling" do - should "run the proper methods on success" do - boot_seq = sequence("boot_seq") - @instance.expects(:boot).in_sequence(boot_seq) - @instance.expects(:wait_for_boot).returns(true).in_sequence(boot_seq) - @app.expects(:call).with(@env).once.in_sequence(boot_seq) - @instance.call(@env) - end - - should "error and halt chain if boot failed" do - boot_seq = sequence("boot_seq") - @instance.expects(:boot).in_sequence(boot_seq) - @instance.expects(:wait_for_boot).returns(false).in_sequence(boot_seq) - @app.expects(:call).never - assert_raises(Vagrant::Errors::VMFailedToBoot) { - @instance.call(@env) - } - end - end - - context "booting" do - should "start the VM in specified mode" do - mode = mock("boot_mode") - @env.env.config.vm.boot_mode = mode - @internal_vm.expects(:start).with(mode).once - @instance.boot - end - end - - context "waiting for boot" do - should "repeatedly ping the SSH port and return false with no response" do - seq = sequence('pings') - @vm.ssh.expects(:up?).times(@env.env.config.ssh.max_tries.to_i - 1).returns(false).in_sequence(seq) - @vm.ssh.expects(:up?).once.returns(true).in_sequence(seq) - assert @instance.wait_for_boot - end - - should "return right away if interrupted" do - @env.interrupt! - @vm.ssh.expects(:up?).times(1).returns(false) - assert @instance.wait_for_boot - end - - should "ping the max number of times then just return" do - @vm.ssh.expects(:up?).times(@env.env.config.ssh.max_tries.to_i).returns(false) - assert !@instance.wait_for_boot - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/check_accessible_test.rb b/test/unit_legacy/vagrant/action/vm/check_accessible_test.rb deleted file mode 100644 index 439af966d98..00000000000 --- a/test/unit_legacy/vagrant/action/vm/check_accessible_test.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'test_helper' - -class CheckAccessibleVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::CheckAccessible - end - - context "calling" do - setup do - @app, @env = action_env - @instance = @klass.new(@app, @env) - end - - should "continue up the chain if the VM is nil" do - @env["vm"] = nil - - @app.expects(:call).once - - assert_nothing_raised { - @instance.call(@env) - } - end - - should "continue up the chain if the VM is not created" do - @env["vm"] = mock("vm") - @env["vm"].stubs(:created?).returns(false) - - @app.expects(:call).once - - assert_nothing_raised { - @instance.call(@env) - } - end - - should "continue up the chain if the VM is created and accessible" do - @env["vm"] = mock("vm") - @env["vm"].stubs(:created?).returns(true) - @env["vm"].stubs(:vm).returns(mock("real_vm")) - @env["vm"].vm.stubs(:accessible?).returns(true) - - @app.expects(:call).once - - assert_nothing_raised { - @instance.call(@env) - } - end - - should "fail if the VM is not accessible" do - @env["vm"] = mock("vm") - @env["vm"].stubs(:created?).returns(true) - @env["vm"].stubs(:vm).returns(mock("real_vm")) - @env["vm"].vm.stubs(:accessible?).returns(false) - - @app.expects(:call).never - - assert_raises(Vagrant::Errors::VMInaccessible) { - @instance.call(@env) - } - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/check_box_test.rb b/test/unit_legacy/vagrant/action/vm/check_box_test.rb deleted file mode 100644 index e72ebf9d423..00000000000 --- a/test/unit_legacy/vagrant/action/vm/check_box_test.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'test_helper' - -class CheckBoxVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::CheckBox - end - - context "calling" do - should "raise error if box not specified" do - app, env = action_env(vagrant_env(vagrantfile(<<-vf))) - config.vm.box = nil - vf - - instance = @klass.new(app, env) - app.expects(:call).never - - assert_raises(Vagrant::Errors::BoxNotSpecified) { - instance.call(env) - } - end - - should "error if box does not exist and URL not specified" do - app, env = action_env(vagrant_env(vagrantfile(<<-vf))) - config.vm.box = "yo" - config.vm.box_url = nil - vf - - instance = @klass.new(app, env) - app.expects(:call).never - env.env.boxes.expects(:find).with(env["config"].vm.box).returns(nil) - - assert_raises(Vagrant::Errors::BoxSpecifiedDoesntExist) { - instance.call(env) - } - end - - should "attempt to download box and continue if URL specified" do - app, env = action_env(vagrant_env(vagrantfile(<<-vf))) - config.vm.box = "yo" - config.vm.box_url = "http://google.com" - vf - - # Save this for later because the expecations below clobber it - vms = env.env.vms - - instance = @klass.new(app, env) - seq = sequence("seq") - env.env.boxes.expects(:find).returns(nil) - Vagrant::Box.expects(:add).with(env.env, env["config"].vm.box, env["config"].vm.box_url).in_sequence(seq) - env.env.boxes.expects(:reload!).in_sequence(seq) - vms.each do |name, vm| - vm.env.expects(:reload_config!).in_sequence(seq) - end - app.expects(:call).with(env).once.in_sequence(seq) - - assert_nothing_raised { - instance.call(env) - } - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/check_guest_additions_test.rb b/test/unit_legacy/vagrant/action/vm/check_guest_additions_test.rb deleted file mode 100644 index 449cfe00be5..00000000000 --- a/test/unit_legacy/vagrant/action/vm/check_guest_additions_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "test_helper" - -class CheckGuestAdditionsVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::CheckGuestAdditions - end - - # TODO: This isn't tested. -end diff --git a/test/unit_legacy/vagrant/action/vm/clean_machine_folder_test.rb b/test/unit_legacy/vagrant/action/vm/clean_machine_folder_test.rb deleted file mode 100644 index f6ce54b2c82..00000000000 --- a/test/unit_legacy/vagrant/action/vm/clean_machine_folder_test.rb +++ /dev/null @@ -1,84 +0,0 @@ -require "test_helper" - -class CleanMachineFolderVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::CleanMachineFolder - @app, @env = action_env - - @instance = @klass.new(@app, @env) - end - - context "calling" do - should "clean machine folder then continue chain" do - seq = sequence("seq") - @instance.expects(:clean_machine_folder).in_sequence(seq) - @app.expects(:call).with(@env).in_sequence(seq) - @instance.call(@env) - end - end - - context "cleaning the folder" do - setup do - @machine_folder = "/foo/bar/baz" - @folder = File.join(@machine_folder, "*") - VirtualBox::Global.global.system_properties.stubs(:default_machine_folder).returns(@machine_folder) - File.stubs(:file?).returns(true) - end - - should "ignore all non-directories" do - folders = %W[foo bar baz] - Dir.expects(:[]).with(@folder).returns(folders) - folders.each do |f| - File.expects(:directory?).with(f).returns(false) - end - - FileUtils.expects(:rm_rf).never - - @instance.clean_machine_folder - end - - should "delete directories with only .vbox-prev files" do - folders = { - "sfoo" => %W[foo bar baz.vbox-prev], - "sbar" => %W[foo.vbox-prev] - } - - Dir.expects(:[]).with(@folder).returns(folders.keys) - folders.each do |folder, subfolders| - File.expects(:directory?).with(folder).returns(true) - Dir.expects(:[]).with("#{folder}/**/*").returns(subfolders) - end - - FileUtils.expects(:rm_rf).never - FileUtils.expects(:rm_rf).with("sbar").once - @instance.clean_machine_folder - end - - should "delete directories with only subdirectories" do - folders = { - "sfoo" => %W[foo bar], - "sbar" => %W[foo.vbox-prev] - } - - File.stubs(:file?).returns(false) - Dir.expects(:[]).with(@folder).returns(folders.keys) - folders.each do |folder, subfolders| - File.expects(:directory?).with(folder).returns(true) - Dir.expects(:[]).with("#{folder}/**/*").returns(subfolders) - end - - FileUtils.expects(:rm_rf).never - FileUtils.expects(:rm_rf).with("sfoo").once - FileUtils.expects(:rm_rf).with("sbar").once - - @instance.clean_machine_folder - end - - should "do nothing if folder is < 10 characters" do - VirtualBox::Global.global.system_properties.stubs(:default_machine_folder).returns("foo") - Dir.expects(:[]).never - - @instance.clean_machine_folder - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/clear_forwarded_ports_test.rb b/test/unit_legacy/vagrant/action/vm/clear_forwarded_ports_test.rb deleted file mode 100644 index 91e5ed8bb60..00000000000 --- a/test/unit_legacy/vagrant/action/vm/clear_forwarded_ports_test.rb +++ /dev/null @@ -1,52 +0,0 @@ -require "test_helper" - -class ClearForwardedPortsVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::ClearForwardedPorts - @app, @env = action_env - - @vm = mock("vm") - @vm.stubs(:name).returns("foo") - @env["vm"] = @vm - @env["vm.modify"] = mock("proc") - - @instance = @klass.new(@app, @env) - end - - context "calling" do - def mock_fp - fp = mock("fp") - fp.expects(:destroy).once - fp - end - - def mock_adapter - na = mock("adapter") - engine = mock("engine") - engine.stubs(:forwarded_ports).returns([mock_fp]) - na.stubs(:nat_driver).returns(engine) - na - end - - setup do - VirtualBox.stubs(:version).returns("3.2.8") - @adapters = [] - @internal_vm = mock("internal_vm") - @internal_vm.stubs(:network_adapters).returns(@adapters) - @vm.stubs(:vm).returns(@internal_vm) - end - - should "call the proper methods and continue chain" do - @adapters << mock_adapter - @adapters << mock_adapter - - @env["vm.modify"].expects(:call).with() do |proc| - proc.call(@internal_vm) - true - end - - @app.expects(:call).with(@env) - @instance.call(@env) - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/clear_nfs_exports_test.rb b/test/unit_legacy/vagrant/action/vm/clear_nfs_exports_test.rb deleted file mode 100644 index f2ab8da047d..00000000000 --- a/test/unit_legacy/vagrant/action/vm/clear_nfs_exports_test.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "test_helper" - -class ClearNFSExportsActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::ClearNFSExports - @app, @env = action_env - @env.env.stubs(:host).returns(Vagrant::Hosts::Base.new(@env)) - - @instance = @klass.new(@app, @env) - end - - should "include the NFS helpers module" do - assert @klass.included_modules.include?(Vagrant::Action::VM::NFSHelpers) - end - - should "clear NFS exports then continue chain" do - seq = sequence("seq") - @instance.expects(:clear_nfs_exports).with(@env).in_sequence(seq) - @app.expects(:call).with(@env).in_sequence(seq) - @instance.call(@env) - end -end diff --git a/test/unit_legacy/vagrant/action/vm/clear_shared_folders_test.rb b/test/unit_legacy/vagrant/action/vm/clear_shared_folders_test.rb deleted file mode 100644 index a982c704159..00000000000 --- a/test/unit_legacy/vagrant/action/vm/clear_shared_folders_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require "test_helper" - -class ClearSharedFoldersVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::ClearSharedFolders - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - @env["vm.modify"] = mock("proc") - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - context "calling" do - setup do - @shared_folder = mock("shared_folder") - @shared_folders = [@shared_folder] - @internal_vm.stubs(:shared_folders).returns(@shared_folders) - end - - should "call destroy on each shared folder then reload" do - destroy_seq = sequence("destroy") - @shared_folders.each do |sf| - sf.expects(:destroy).once.in_sequence(destroy_seq) - end - - @env["vm.modify"].expects(:call).with() do |proc| - proc.call(@internal_vm) - true - end - - @app.expects(:call).with(@env).once - @instance.call(@env) - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/customize_test.rb b/test/unit_legacy/vagrant/action/vm/customize_test.rb deleted file mode 100644 index aede1c0db30..00000000000 --- a/test/unit_legacy/vagrant/action/vm/customize_test.rb +++ /dev/null @@ -1,37 +0,0 @@ -require "test_helper" - -class CustomizeVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Customize - @app, @env = action_env - @instance = @klass.new(@app, @env) - - @vm = mock("vm") - @env["vm"] = @vm - @env["vm.modify"] = mock("proc") - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - end - - should "not run anything if no customize blocks exist" do - @env["config"].vm.proc_stack.clear - @env["vm.modify"].expects(:call).never - @app.expects(:call).with(@env).once - @instance.call(@env) - end - - should "run the VM customization procs then save the VM" do - ran = false - @env["config"].vm.customize { |vm| } - @env["config"].vm.expects(:run_procs!).with(@internal_vm) - - @env["vm.modify"].expects(:call).with() do |proc| - proc.call(@internal_vm) - true - end - - @app.expects(:call).with(@env).once - @instance.call(@env) - end -end diff --git a/test/unit_legacy/vagrant/action/vm/destroy_test.rb b/test/unit_legacy/vagrant/action/vm/destroy_test.rb deleted file mode 100644 index da9efbc4150..00000000000 --- a/test/unit_legacy/vagrant/action/vm/destroy_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -require "test_helper" - -class DestroyVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Destroy - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - context "destroying the VM" do - should "destroy VM and attached images" do - @internal_vm.expects(:destroy).once - @env["vm"].expects(:vm=).with(nil).once - @app.expects(:call).with(@env).once - @instance.call(@env) - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/destroy_unused_network_interfaces_test.rb b/test/unit_legacy/vagrant/action/vm/destroy_unused_network_interfaces_test.rb deleted file mode 100644 index 7e4a9c7a0f3..00000000000 --- a/test/unit_legacy/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require "test_helper" - -class DestroyUnusedNetworkInterfacesVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::DestroyUnusedNetworkInterfaces - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - context "calling" do - setup do - @interfaces = [] - global = mock("global") - host = mock("host") - VirtualBox::Global.stubs(:global).returns(global) - global.stubs(:host).returns(host) - host.stubs(:network_interfaces).returns(@interfaces) - end - - def stub_interface(length=5, type=:host_only) - interface = mock("interface") - interface.stubs(:interface_type).returns(type) - interface.stubs(:attached_vms).returns(Array.new(length)) - - @interfaces << interface - interface - end - - should "destroy only the unused network interfaces" do - stub_interface(5) - stub_interface(7) - results = [stub_interface(0), stub_interface(0)] - - results.each do |result| - result.expects(:destroy).once - end - - @app.expects(:call).with(@env).once - @instance.call(@env) - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/discard_state_test.rb b/test/unit_legacy/vagrant/action/vm/discard_state_test.rb deleted file mode 100644 index b0732360e32..00000000000 --- a/test/unit_legacy/vagrant/action/vm/discard_state_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "test_helper" - -class DiscardStateVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::DiscardState - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - context "calling" do - setup do - @vm.stubs(:created?).returns(true) - @internal_vm.stubs(:saved?).returns(false) - end - - should "do nothing if the VM is not created" do - @vm.stubs(:created?).returns(false) - @internal_vm.expects(:discard_state).never - @app.expects(:call).with(@env).once - @instance.call(@env) - end - - should "do nothing if not saved and continue chain" do - @internal_vm.expects(:saved?).returns(false) - @internal_vm.expects(:discard_state).never - @app.expects(:call).with(@env).once - @instance.call(@env) - end - - should "discard state and continue chain" do - seq = sequence("sequence") - @internal_vm.expects(:saved?).returns(true).in_sequence(seq) - @internal_vm.expects(:discard_state).in_sequence(seq) - @app.expects(:call).with(@env).once.in_sequence(seq) - @instance.call(@env) - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/export_test.rb b/test/unit_legacy/vagrant/action/vm/export_test.rb deleted file mode 100644 index f95b1d7d58c..00000000000 --- a/test/unit_legacy/vagrant/action/vm/export_test.rb +++ /dev/null @@ -1,107 +0,0 @@ -require "test_helper" - -class ExportVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Export - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - context "calling" do - setup do - @internal_vm.stubs(:powered_off?).returns(true) - end - - should "call the proper methods then continue chain" do - seq = sequence("seq") - @instance.expects(:setup_temp_dir).in_sequence(seq) - @instance.expects(:export).in_sequence(seq) - @app.expects(:call).with(@env).in_sequence(seq) - @instance.expects(:recover).in_sequence(seq).with(@env) - - @instance.call(@env) - end - - should "halt the chain if not powered off" do - @internal_vm.stubs(:powered_off?).returns(false) - @instance.expects(:setup_temp_dir).never - @instance.expects(:export).never - @app.expects(:call).with(@env).never - @instance.expects(:recover).never - - assert_raises(Vagrant::Errors::VMPowerOffToPackage) { - @instance.call(@env) - } - end - end - - context "cleaning up" do - setup do - @temp_dir = "foo" - @instance.stubs(:temp_dir).returns(@temp_dir) - File.stubs(:exist?).returns(true) - end - - should "delete the temporary file if it exists" do - File.expects(:unlink).with(@temp_dir).once - @instance.recover(nil) - end - - should "not delete anything if it doesn't exist" do - File.stubs(:exist?).returns(false) - File.expects(:unlink).never - @instance.recover(nil) - end - end - - context "setting up the temporary directory" do - setup do - @time_now = Time.now.to_i.to_s - Time.stubs(:now).returns(@time_now) - - @temp_dir = @env.env.tmp_path.join(@time_now) - FileUtils.stubs(:mkpath) - end - - should "create the temporary directory using the current time" do - FileUtils.expects(:mkpath).with(@temp_dir).once - @instance.setup_temp_dir - end - - should "set to the environment" do - @instance.setup_temp_dir - assert_equal @temp_dir, @env["export.temp_dir"] - assert_equal @temp_dir, @instance.temp_dir - end - end - - context "exporting" do - setup do - @ovf_path = mock("ovf_path") - @instance.stubs(:ovf_path).returns(@ovf_path) - end - - should "call export on the runner with the ovf path" do - @internal_vm.expects(:export).with(@ovf_path).once - @instance.export - end - end - - context "path to OVF file" do - setup do - @temp_dir = "foo" - @env["export.temp_dir"] = @temp_dir - end - - should "be the temporary directory joined with the OVF filename" do - assert_equal File.join(@temp_dir, @env.env.config.vm.box_ovf), @instance.ovf_path - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb b/test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb deleted file mode 100644 index d7caca0417e..00000000000 --- a/test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb +++ /dev/null @@ -1,77 +0,0 @@ -require "test_helper" - -class ForwardPortsHelpersVMActionTest < Test::Unit::TestCase - setup do - @klass = Class.new do - include Vagrant::Action::VM::ForwardPortsHelpers - def initialize(env); @env = env; end - end - - @app, @env = action_env - - @vm = mock("vm") - @vm.stubs(:name).returns("foo") - @env["vm"] = @vm - - @instance = @klass.new(@env) - end - - context "getting list of used ports" do - setup do - @vms = [] - VirtualBox::VM.stubs(:all).returns(@vms) - VirtualBox.stubs(:version).returns("3.1.0") - @vm.stubs(:uuid).returns(:bar) - end - - def mock_vm(options={}) - options = { - :running? => true, - :accessible? => true, - :uuid => :foo - }.merge(options) - - vm = mock("vm") - options.each do |k,v| - vm.stubs(k).returns(v) - end - - vm - end - - def mock_fp(hostport) - fp = mock("fp") - fp.stubs(:hostport).returns(hostport.to_s) - fp - end - - should "ignore VMs which aren't running" do - @vms << mock_vm(:running? => false) - @vms[0].expects(:forwarded_ports).never - @instance.used_ports - end - - should "ignore VMs which aren't accessible" do - @vms << mock_vm(:accessible? => false) - @vms[0].expects(:forwarded_ports).never - @instance.used_ports - end - - should "ignore VMs of the same uuid" do - @vms << mock_vm(:uuid => @vm.uuid) - @vms[0].expects(:forwarded_ports).never - @instance.used_ports - end - - should "return the forwarded ports for VB 3.2.x" do - VirtualBox.stubs(:version).returns("3.2.4") - fps = [mock_fp(2222), mock_fp(80)] - na = mock("na") - ne = mock("ne") - na.stubs(:nat_driver).returns(ne) - ne.stubs(:forwarded_ports).returns(fps) - @vms << mock_vm(:network_adapters => [na]) - assert_equal [2222, 80], @instance.used_ports - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/forward_ports_test.rb b/test/unit_legacy/vagrant/action/vm/forward_ports_test.rb deleted file mode 100644 index 175673e3b0b..00000000000 --- a/test/unit_legacy/vagrant/action/vm/forward_ports_test.rb +++ /dev/null @@ -1,197 +0,0 @@ -require "test_helper" - -class ForwardPortsVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::ForwardPorts - @app, @env = action_env - - @vm = mock("vm") - @vm.stubs(:name).returns("foo") - @env["vm"] = @vm - @env["vm.modify"] = mock("proc") - end - - context "initializing" do - should "call proper methods" do - @klass.any_instance.expects(:threshold_check) - @klass.any_instance.expects(:external_collision_check) - @klass.new(@app, @env) - end - end - - context "checking for threshold" do - setup do - @klass.any_instance.stubs(:external_collision_check) - @env.env.config.vm.forwarded_ports.clear - end - - should "issue a warning for ports less than 1024" do - @env.env.config.vm.forward_port("foo", 22, 222) - - @env.ui.expects(:warn).once - @klass.new(@app, @env) - end - - should "not issue a warning for ports greater than 1024" do - @env.env.config.vm.forward_port("foo", 22, 2222) - - @env.ui.expects(:warn).never - @klass.new(@app, @env) - end - end - - context "checking for colliding external ports" do - setup do - @env.env.config.vm.forwarded_ports.clear - @env.env.config.vm.forward_port("ssh", 22, 2222) - - @used_ports = [] - @klass.any_instance.stubs(:used_ports).returns(@used_ports) - @klass.any_instance.stubs(:handle_collision) - end - - should "not raise any errors if no forwarded ports collide" do - @used_ports << 80 - assert_nothing_raised { @klass.new(@app, @env) } - end - - should "handle collision if it happens" do - @used_ports << 2222 - @klass.any_instance.expects(:handle_collision).with("ssh", anything, anything).once - assert_nothing_raised { @klass.new(@app, @env) } - end - end - - context "with instance" do - setup do - @klass.any_instance.stubs(:threshold_check) - @klass.any_instance.stubs(:external_collision_check) - @instance = @klass.new(@app, @env) - end - - context "handling collisions" do - setup do - @name = :foo - @options = { - :hostport => 0, - :auto => true - } - @used_ports = [1,2,3] - - @env.env.config.vm.auto_port_range = (1..5) - end - - should "error if auto forwarding is disabled" do - @options[:auto] = false - - assert_raises(Vagrant::Errors::ForwardPortCollision) { - @instance.handle_collision(@name, @options, @used_ports) - } - end - - should "set the host port to the first available port" do - assert_equal 0, @options[:hostport] - @instance.handle_collision(@name, @options, @used_ports) - assert_equal 4, @options[:hostport] - end - - should "add the newly used port to the list of used ports" do - assert !@used_ports.include?(4) - @instance.handle_collision(@name, @options, @used_ports) - assert @used_ports.include?(4) - end - - should "not use a host port which is being forwarded later" do - @env.env.config.vm.forward_port("http", 80, 4) - - assert_equal 0, @options[:hostport] - @instance.handle_collision(@name, @options, @used_ports) - assert_equal 5, @options[:hostport] - end - - should "raise an exception if there are no auto ports available" do - @env.env.config.vm.auto_port_range = (1..3) - - assert_raises(Vagrant::Errors::ForwardPortAutolistEmpty) { - @instance.handle_collision(@name, @options, @used_ports) - } - end - end - - context "calling" do - should "clear all previous ports and forward new ports" do - exec_seq = sequence("exec_seq") - - @env["vm.modify"].expects(:call).with() do |proc| - proc.call(@internal_vm) - true - end - - @instance.expects(:forward_ports).once.in_sequence(exec_seq) - @app.expects(:call).once.with(@env).in_sequence(exec_seq) - @instance.call(@env) - end - end - - context "forwarding ports" do - setup do - @internal_vm = mock("internal_vm") - @vm.stubs(:vm).returns(@internal_vm) - end - - should "create a port forwarding for the VM" do - forwarded_ports = mock("forwarded_ports") - network_adapter = mock("network_adapter") - - @internal_vm.stubs(:network_adapters).returns([network_adapter]) - network_adapter.expects(:attachment_type).returns(:nat) - - @instance.expects(:forward_port).once - - @instance.forward_ports(@internal_vm) - end - - should "not port forward for non NAT interfaces" do - forwarded_ports = mock("forwarded_ports") - network_adapter = mock("network_adapter") - - @internal_vm.expects(:network_adapters).returns([network_adapter]) - network_adapter.expects(:attachment_type).returns(:host_only) - - @instance.forward_ports(@internal_vm) - end - end - - context "forwarding ports implementation" do - setup do - VirtualBox.stubs(:version).returns("3.2.8") - - @internal_vm = mock("internal_vm") - @vm.stubs(:vm).returns(@internal_vm) - end - - should "forward ports" do - name = @env.env.config.vm.forwarded_ports.keys.first - opts = @env.env.config.vm.forwarded_ports[name] - - adapters = [] - adapter = mock("adapter") - engine = mock("engine") - fps = mock("forwarded ports") - adapter.stubs(:nat_driver).returns(engine) - engine.stubs(:forwarded_ports).returns(fps) - fps.expects(:<<).with do |port| - assert_equal name, port.name - assert_equal opts[:hostport], port.hostport - assert_equal opts[:guestport], port.guestport - true - end - - adapters[opts[:adapter]] = adapter - @internal_vm.stubs(:network_adapters).returns(adapters) - - @instance.forward_port(@internal_vm, name, opts) - end - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/halt_test.rb b/test/unit_legacy/vagrant/action/vm/halt_test.rb deleted file mode 100644 index 4ddfba8a3c5..00000000000 --- a/test/unit_legacy/vagrant/action/vm/halt_test.rb +++ /dev/null @@ -1,79 +0,0 @@ -require "test_helper" - -class HaltVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Halt - @app, @env = action_env - - @vm = mock("vm") - @vm.stubs(:name).returns("foo") - @vm.stubs(:ssh).returns(mock("ssh")) - @vm.stubs(:system).returns(mock("system")) - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - context "initializing" do - should "merge in the given options" do - @klass.new(@app, @env, :foo => :bar) - assert_equal :bar, @env[:foo] - end - end - - context "calling" do - setup do - @vm.stubs(:created?).returns(true) - @internal_vm.stubs(:running?).returns(true) - - @vm.system.stubs(:halt) - @internal_vm.stubs(:stop) - @internal_vm.stubs(:state).returns(:powered_off) - end - - should "do nothing if VM is not created" do - @internal_vm.stubs(:created?).returns(false) - @vm.system.expects(:halt).never - @internal_vm.expects(:stop).never - @app.expects(:call).once - - @instance.call(@env) - end - - should "do nothing if VM not running" do - @internal_vm.stubs(:running?).returns(false) - @vm.system.expects(:halt).never - @internal_vm.expects(:stop).never - @app.expects(:call).once - - @instance.call(@env) - end - - should "halt with the system and NOT force VM to stop if powered off" do - @internal_vm.expects(:state).with(true).returns(:powered_off) - @vm.system.expects(:halt).once - @internal_vm.expects(:stop).never - @app.expects(:call).once - - @instance.call(@env) - end - - should "halt with the system and force VM to stop if NOT powered off" do - @internal_vm.expects(:state).with(true).returns(:running) - @vm.system.expects(:halt).once - @internal_vm.expects(:stop).once - @app.expects(:call).once - - @instance.call(@env) - end - - should "not call halt on the system if forcing" do - @env[:force] = true - @vm.system.expects(:halt).never - @instance.call(@env) - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/host_name_test.rb b/test/unit_legacy/vagrant/action/vm/host_name_test.rb deleted file mode 100644 index bb6a74e5812..00000000000 --- a/test/unit_legacy/vagrant/action/vm/host_name_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require "test_helper" - -class HostNameVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::HostName - @app, @env = action_env - @instance = @klass.new(@app, @env) - - @vm = mock("vm") - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - end - - should "not run anything if no host name is set" do - @env["config"].vm.host_name = nil - @env["vm"].expects(:system).never - @app.expects(:call).with(@env).once - - @instance.call(@env) - end - - should "change host name if set" do - @env["config"].vm.host_name = "foo" - - system = mock("system") - @vm.stubs(:system).returns(system) - - seq = sequence("host_seq") - @app.expects(:call).with(@env).in_sequence(seq) - system.expects(:change_host_name).with(@env["config"].vm.host_name).in_sequence(seq) - - @instance.call(@env) - end -end diff --git a/test/unit_legacy/vagrant/action/vm/import_test.rb b/test/unit_legacy/vagrant/action/vm/import_test.rb deleted file mode 100644 index 1dc5d35694a..00000000000 --- a/test/unit_legacy/vagrant/action/vm/import_test.rb +++ /dev/null @@ -1,66 +0,0 @@ -require "test_helper" - -class ImportVMActionTest < Test::Unit::TestCase - setup do - clean_paths - vagrant_box("foo") - - @klass = Vagrant::Action::VM::Import - @app, @env = action_env(vagrant_env(vagrantfile(<<-vf))) - config.vm.box = "foo" - vf - - @instance = @klass.new(@app, @env) - - @env.env.vm = Vagrant::VM.new(:env => @env.env, :name => "foobar") - - VirtualBox::VM.stubs(:import) - - @vm = mock("vm") - @vm.stubs(:uuid).returns("foobar") - end - - should "call import on VirtualBox with proper base" do - VirtualBox::VM.expects(:import).once.with(@env.env.box.ovf_file.to_s).returns(@vm) - @instance.call(@env) - end - - should "call next in chain on success and set VM" do - VirtualBox::VM.stubs(:import).returns(@vm) - @app.expects(:call).with(@env).once - @instance.call(@env) - - assert_equal @vm, @env["vm"].vm - end - - should "mark environment erroneous and not continue chain on failure" do - @app.expects(:call).never - assert_raises(Vagrant::Errors::VMImportFailure) { - @instance.call(@env) - } - end - - context "recovery" do - setup do - @env.env.vm.stubs(:created?).returns(true) - end - - should "not run the destroy action on recover if error is a VagrantError" do - @env["vagrant.error"] = Vagrant::Errors::VMImportFailure.new - @env.env.actions.expects(:run).never - @instance.recover(@env) - end - - should "not run the destroy action on recover if VM is not created" do - @env.env.vm.stubs(:created?).returns(false) - @env.env.actions.expects(:run).never - @instance.recover(@env) - end - - should "run the destroy action on recover" do - @env.env.vm.stubs(:created?).returns(true) - @env.env.actions.expects(:run).with(:destroy).once - @instance.recover(@env) - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/match_mac_address_test.rb b/test/unit_legacy/vagrant/action/vm/match_mac_address_test.rb deleted file mode 100644 index a75fc051c2c..00000000000 --- a/test/unit_legacy/vagrant/action/vm/match_mac_address_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require "test_helper" - -class MatchMACAddressVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::MatchMACAddress - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - should "match the mac addresses" do - nic = mock("nic") - nic.expects(:mac_address=).once - - update_seq = sequence("update_seq") - @internal_vm.expects(:network_adapters).returns([nic]).once.in_sequence(update_seq) - @app.expects(:call).with(@env).once.in_sequence(update_seq) - - @env["vm.modify"].expects(:call).with() do |proc| - proc.call(@internal_vm) - true - end - - @instance.call(@env) - end - - should "raise an exception if no base MAC address is specified" do - @env.env.config.vm.base_mac = nil - - assert_raises(Vagrant::Errors::VMBaseMacNotSpecified) { - @instance.call(@env) - } - end -end diff --git a/test/unit_legacy/vagrant/action/vm/modify_test.rb b/test/unit_legacy/vagrant/action/vm/modify_test.rb deleted file mode 100644 index 2c1aa437e3f..00000000000 --- a/test/unit_legacy/vagrant/action/vm/modify_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -require "test_helper" - -class ModifyVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Modify - @app, @env = action_env - - @vm = mock("vm") - @vm.stubs(:ssh).returns(mock("ssh")) - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - context "initialization" do - should "have the vm.modify function setup in the environment" do - assert @env.has_key?("vm.modify") - end - end - - context "calling" do - should "run the procs with the VM as an argument and save the VM" do - seq = sequence("procseq") - - proc = Proc.new { |vm| } - @env["vm.modify"].call(proc) - - proc.expects(:call).with(@internal_vm).once.in_sequence(seq) - @internal_vm.expects(:save).once.in_sequence(seq) - @vm.expects(:reload!).once.in_sequence(seq) - - @instance.call(@env) - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/network_test.rb b/test/unit_legacy/vagrant/action/vm/network_test.rb deleted file mode 100644 index 6745de52e6b..00000000000 --- a/test/unit_legacy/vagrant/action/vm/network_test.rb +++ /dev/null @@ -1,286 +0,0 @@ -require "test_helper" - -class NetworkVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Network - @app, @env = action_env - - @vm = mock("vm") - @vm.stubs(:name).returns("foo") - @vm.stubs(:ssh).returns(mock("ssh")) - @vm.stubs(:system).returns(mock("system")) - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - end - - context "initializing" do - should "raise an error if on windows x64 and networking is enabled" do - Vagrant::Util::Platform.stubs(:windows?).returns(true) - Vagrant::Util::Platform.stubs(:bit64?).returns(true) - @env.env.config.vm.network("foo") - - assert_raises(Vagrant::Errors::NetworkNotImplemented) { - @klass.new(@app, @env) - } - end - - should "not raise an error if not on windows and networking is enabled" do - Vagrant::Util::Platform.stubs(:windows?).returns(false) - @env.env.config.vm.network("foo") - - assert_nothing_raised { - @klass.new(@app, @env) - } - end - - should "verify no bridge collisions for each network enabled" do - @env.env.config.vm.network("foo") - @klass.any_instance.expects(:verify_no_bridge_collision).returns(true).once.with() do |options| - assert_equal "foo", options[:ip] - true - end - - @klass.new(@app, @env) - end - end - - context "with an instance" do - setup do - @klass.any_instance.stubs(:verify_no_bridge_collision) - @instance = @klass.new(@app, @env) - - @interfaces = [] - VirtualBox::Global.global.host.stubs(:network_interfaces).returns(@interfaces) - end - - def mock_interface(options=nil) - options = { - :interface_type => :host_only, - :name => "foo" - }.merge(options || {}) - - interface = mock("interface") - options.each do |k,v| - interface.stubs(k).returns(v) - end - - @interfaces << interface - interface - end - - context "calling" do - setup do - @env.env.config.vm.network("foo") - @instance.stubs(:enable_network?).returns(false) - end - - should "do nothing if network should not be enabled" do - @instance.expects(:assign_network).never - @app.expects(:call).with(@env).once - @vm.system.expects(:prepare_host_only_network).never - @vm.system.expects(:enable_host_only_network).never - - @instance.call(@env) - end - - should "assign and enable the network if networking enabled" do - @instance.stubs(:enable_network?).returns(true) - - run_seq = sequence("run") - @instance.expects(:assign_network).once.in_sequence(run_seq) - @app.expects(:call).with(@env).once.in_sequence(run_seq) - @vm.system.expects(:prepare_host_only_network).once.in_sequence(run_seq) - @vm.system.expects(:enable_host_only_network).once.in_sequence(run_seq) - - @instance.call(@env) - end - end - - context "checking if network is enabled" do - should "return true if the network options are set" do - @env.env.config.vm.network("foo") - assert @instance.enable_network? - end - - should "return false if the network was not set" do - assert !@instance.enable_network? - end - end - - context "assigning the network" do - setup do - @network_name = "foo" - @instance.stubs(:network_name).returns(@network_name) - - @network_adapters = [] - @internal_vm.stubs(:network_adapters).returns(@network_adapters) - end - - def expect_adapter_setup(options=nil) - options = { - :ip => "foo", - :adapter => 7 - }.merge(options || {}) - - @env["config"].vm.network(options[:ip], options) - - @env["vm"].vm.network_adapters.clear - @env["vm"].vm.network_adapters[options[:adapter]] = adapter = mock("adapter") - - adapter.expects(:enabled=).with(true) - adapter.expects(:attachment_type=).with(:host_only).once - adapter.expects(:host_only_interface=).with(@network_name).once - - if options[:mac] - adapter.expects(:mac_address=).with(options[:mac].gsub(':', '')).once - else - adapter.expects(:mac_address=).never - end - - adapter.expects(:save).once - end - - should "setup the specified network adapter" do - expect_adapter_setup - @instance.assign_network - end - - should "setup the specified network adapter's mac address if specified" do - expect_adapter_setup(:mac => "foo") - @instance.assign_network - end - - should "properly remove : from mac address" do - expect_adapter_setup(:mac => "foo:bar") - @instance.assign_network - end - end - - context "network name" do - setup do - @instance.stubs(:matching_network?).returns(false) - - @options = { :ip => :foo, :netmask => :bar, :name => nil } - end - - should "return the network which matches" do - result = mock("result") - interface = mock_interface(:name => result) - - @instance.expects(:matching_network?).with(interface, @options).returns(true) - assert_equal result, @instance.network_name(@options) - end - - should "ignore non-host only interfaces" do - @options[:name] = "foo" - mock_interface(:name => @options[:name], - :interface_type => :bridged) - - assert_raises(Vagrant::Errors::NetworkNotFound) { - @instance.network_name(@options) - } - end - - should "return the network which matches the name if given" do - @options[:name] = "foo" - - interface = mock_interface(:name => @options[:name]) - assert_equal @options[:name], @instance.network_name(@options) - end - - should "error and exit if the given network name is not found" do - @options[:name] = "foo" - - @interfaces.expects(:create).never - assert_raises(Vagrant::Errors::NetworkNotFound) { - @instance.network_name(@options) - } - end - - should "create a network for the IP and netmask" do - result = mock("result") - network_ip = :foo - - interface = mock_interface(:name => result) - interface.expects(:enable_static).with(network_ip, @options[:netmask]) - @interfaces.expects(:create).returns(interface) - @instance.expects(:network_ip).with(@options[:ip], @options[:netmask]).once.returns(network_ip) - - assert_equal result, @instance.network_name(@options) - end - end - - context "checking for a matching network" do - setup do - @interface = mock("interface") - @interface.stubs(:network_mask).returns("foo") - @interface.stubs(:ip_address).returns("192.168.0.1") - - @options = { - :netmask => "foo", - :ip => "baz" - } - end - - should "return false if the netmasks don't match" do - @options[:netmask] = "bar" - assert @interface.network_mask != @options[:netmask] # sanity - assert !@instance.matching_network?(@interface, @options) - end - - should "return true if the netmasks yield the same IP" do - tests = [["255.255.255.0", "192.168.0.1", "192.168.0.45"], - ["255.255.0.0", "192.168.45.1", "192.168.28.7"]] - - tests.each do |netmask, interface_ip, guest_ip| - @options[:netmask] = netmask - @options[:ip] = guest_ip - @interface.stubs(:network_mask).returns(netmask) - @interface.stubs(:ip_address).returns(interface_ip) - - assert @instance.matching_network?(@interface, @options) - end - end - end - - context "applying the netmask" do - should "return the proper result" do - tests = { - ["192.168.0.1","255.255.255.0"] => [192,168,0,0], - ["192.168.45.10","255.255.255.0"] => [192,168,45,0] - } - - tests.each do |k,v| - assert_equal v, @instance.apply_netmask(*k) - end - end - end - - context "splitting an IP" do - should "return the proper result" do - tests = { - "192.168.0.1" => [192,168,0,1] - } - - tests.each do |k,v| - assert_equal v, @instance.split_ip(k) - end - end - end - - context "network IP" do - should "return the proper result" do - tests = { - ["192.168.0.45", "255.255.255.0"] => "192.168.0.1" - } - - tests.each do |args, result| - assert_equal result, @instance.network_ip(*args) - end - end - end - - end -end diff --git a/test/unit_legacy/vagrant/action/vm/nfs_helpers_test.rb b/test/unit_legacy/vagrant/action/vm/nfs_helpers_test.rb deleted file mode 100644 index f8f4c702f98..00000000000 --- a/test/unit_legacy/vagrant/action/vm/nfs_helpers_test.rb +++ /dev/null @@ -1,26 +0,0 @@ -require "test_helper" - -class NFSHelpersVMActionTest < Test::Unit::TestCase - setup do - @klass = Class.new do - include Vagrant::Action::VM::NFSHelpers - end - - @app, @env = action_env - - @instance = @klass.new - end - - should "clear NFS exports for the environment if the host exists" do - @host = mock("host") - @env.env.stubs(:host).returns(@host) - @host.expects(:nfs_cleanup).once - - @instance.clear_nfs_exports(@env) - end - - should "not do anything if host is nil" do - @env.env.stubs(:host).returns(nil) - assert_nothing_raised { @instance.clear_nfs_exports(@env) } - end -end diff --git a/test/unit_legacy/vagrant/action/vm/nfs_test.rb b/test/unit_legacy/vagrant/action/vm/nfs_test.rb deleted file mode 100644 index 5b0374846d0..00000000000 --- a/test/unit_legacy/vagrant/action/vm/nfs_test.rb +++ /dev/null @@ -1,260 +0,0 @@ -require "test_helper" - -class NFSVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::NFS - @app, @env = action_env - - @vm = mock("vm") - @vm.stubs(:system).returns(mock("system")) - @env.env.stubs(:host).returns(Vagrant::Hosts::Base.new(@env)) - @env.env.config.vm.network("192.168.55.1") - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - end - - context "initializing" do - should "not call verify settings if NFS is not enabled" do - @klass.any_instance.expects(:verify_settings).never - @klass.new(@app, @env) - end - - should "call verify settings if NFS is enabled" do - @env.env.config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true) - @klass.any_instance.expects(:verify_settings).once - @klass.new(@app, @env) - end - end - - context "with an instance" do - setup do - @instance = @klass.new(@app, @env) - end - - context "calling" do - setup do - @instance.stubs(:folders).returns([:a]) - - [:clear_nfs_exports, :extract_folders, :prepare_folders, :export_folders, :mount_folders].each do |meth| - @instance.stubs(meth) - end - end - - should "call the proper sequence and succeed" do - seq = sequence('seq') - @instance.expects(:extract_folders).in_sequence(seq) - @instance.expects(:prepare_folders).in_sequence(seq) - @instance.expects(:clear_nfs_exports).with(@env).in_sequence(seq) - @instance.expects(:export_folders).in_sequence(seq) - @app.expects(:call).with(@env).in_sequence(seq) - @instance.expects(:mount_folders).in_sequence(seq) - @instance.call(@env) - end - - should "not export folders if folders is empty" do - @instance.stubs(:folders).returns([]) - - seq = sequence('seq') - @instance.expects(:extract_folders).in_sequence(seq) - @instance.expects(:prepare_folders).never - @instance.expects(:export_folders).never - @instance.expects(:clear_nfs_exports).never - @app.expects(:call).with(@env).in_sequence(seq) - @instance.expects(:mount_folders).never - @instance.call(@env) - end - end - - context "recovery" do - setup do - @vm.stubs(:created?).returns(true) - end - - should "clear NFS exports" do - @instance.expects(:clear_nfs_exports).with(@env).once - @instance.recover(@env) - end - - should "do nothing if VM is not created" do - @vm.stubs(:created?).returns(false) - @instance.expects(:clear_nfs_exports).never - @instance.recover(@env) - end - end - - context "extracting folders" do - setup do - @env.env.config.vm.shared_folders.clear - @env.env.config.vm.share_folder("v-foo", "/foo", ".", :nfs => true) - @env.env.config.vm.share_folder("v-bar", "/bar", ".", :nfs => true) - end - - should "extract the NFS enabled folders" do - @instance.extract_folders - assert_equal 2, @instance.folders.length - end - - should "mark the folders disabled from the original config" do - @instance.extract_folders - %W[v-foo v-bar].each do |key| - assert @env["config"].vm.shared_folders[key][:disabled] - end - end - - should "expand the hostpath relative to the env root" do - @instance.extract_folders - %W[v-foo v-bar].each do |key| - opts = @env["config"].vm.shared_folders[key] - assert_equal File.expand_path(opts[:hostpath], @env.env.root_path), @instance.folders[key][:hostpath] - end - end - end - - context "preparing UID/GID" do - setup do - @stat = mock("stat") - File.stubs(:stat).returns(@stat) - end - - should "return nil if the perm is not set" do - @env.env.config.nfs.map_uid = nil - assert_nil @instance.prepare_permission(:uid, {:gid => 7}) - end - - should "return nil if the perm explicitly says nil" do - assert_nil @instance.prepare_permission(:uid, {:map_uid => nil}) - end - - should "return the set value if it is set" do - assert_equal 7, @instance.prepare_permission(:gid, {:map_gid => 7}) - end - - should "return the global config value if set and not explicitly set on folder" do - @env.env.config.nfs.map_gid = 12 - assert_equal 12, @instance.prepare_permission(:gid, {}) - end - - should "return the stat result of the hostpath if :auto" do - opts = { :hostpath => "foo", :map_uid => :auto } - File.expects(:stat).with(opts[:hostpath]).returns(@stat) - @stat.stubs(:uid).returns(24) - - assert_equal 24, @instance.prepare_permission(:uid, opts) - end - end - - context "exporting folders" do - setup do - @instance.stubs(:folders).returns({}) - @instance.stubs(:guest_ip).returns("192.168.33.10") - end - - should "call nfs_export on the host" do - @env["host"].expects(:nfs_export).with(@instance.guest_ip, @instance.folders) - @instance.export_folders - end - end - - context "mounting folders" do - setup do - @instance.stubs(:host_ip).returns("foo") - @instance.stubs(:folders).returns({ "v-data" => {:guestpath => "foo"}}) - end - - should "mount the folders on the system" do - @vm.system.expects(:mount_nfs).with(@instance.host_ip, @instance.folders) - @instance.mount_folders - end - - should "not mount folders which have no guest path" do - @instance.stubs(:folders).returns({ "v-data" => {}}) - @vm.system.expects(:mount_nfs).with(@instance.host_ip, {}) - @instance.mount_folders - end - end - - context "getting the host IP" do - setup do - @network_adapters = [] - @internal_vm.stubs(:network_adapters).returns(@network_adapters) - end - - def stub_interface(ip) - interface = mock("interface") - adapter = mock("adapter") - adapter.stubs(:host_interface_object).returns(interface) - interface.stubs(:ip_address).returns(ip) - - @network_adapters << adapter - interface - end - - should "return the IP of the first interface" do - ip = "192.168.1.1" - stub_interface(ip) - - assert_equal ip, @instance.host_ip - end - - should "return nil if no IP is found" do - assert_nil @instance.host_ip - end - end - - context "getting the guest IP" do - should "return the first networked IP" do - ip = "192.168.33.10" - @env.env.config.vm.network(ip, :adapter => 1) - @env.env.config.vm.network("192.168.66.10", :adapter => 2) - assert_equal ip, @instance.guest_ip - end - end - - context "nfs enabled" do - should "return false if no folders are marked for NFS" do - assert !@instance.nfs_enabled? - end - - should "return true if a shared folder is marked for NFS" do - @env.env.config.vm.share_folder("v-foo", "/foo", "/bar", :nfs => true) - assert @instance.nfs_enabled? - end - end - - context "verifying settings" do - setup do - @env.env.host.stubs(:nfs?).returns(true) - end - - should "error environment if host is nil" do - @env.env.stubs(:host).returns(nil) - assert_raises(Vagrant::Errors::NFSHostRequired) { - @instance.verify_settings - } - end - - should "error environment if host does not support NFS" do - @env.env.host.stubs(:nfs?).returns(false) - assert_raises(Vagrant::Errors::NFSNotSupported) { - @instance.verify_settings - } - end - - should "error environment if host only networking is not enabled" do - @env.env.config.vm.network_options.clear - assert_raises(Vagrant::Errors::NFSNoHostNetwork) { - @instance.verify_settings - } - end - - should "be fine if everything passes" do - @env.env.host.stubs(:nfs?).returns(true) - assert_nothing_raised { - @instance.verify_settings - } - end - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/package_test.rb b/test/unit_legacy/vagrant/action/vm/package_test.rb deleted file mode 100644 index b5350c42600..00000000000 --- a/test/unit_legacy/vagrant/action/vm/package_test.rb +++ /dev/null @@ -1,25 +0,0 @@ -require "test_helper" - -class PackageVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Package - @app, @env = action_env - @env["export.temp_dir"] = "foo" - - @instance = @klass.new(@app, @env) - end - - should "be a subclass of general packaging middleware" do - assert @instance.is_a?(Vagrant::Action::General::Package) - end - - should "set the package directory then call parent" do - @instance.expects(:general_call).once.with() do |env| - assert env["package.directory"] - assert_equal env["package.directory"], env["export.temp_dir"] - true - end - - @instance.call(@env) - end -end diff --git a/test/unit_legacy/vagrant/action/vm/package_vagrantfile_test.rb b/test/unit_legacy/vagrant/action/vm/package_vagrantfile_test.rb deleted file mode 100644 index f918d5de28f..00000000000 --- a/test/unit_legacy/vagrant/action/vm/package_vagrantfile_test.rb +++ /dev/null @@ -1,46 +0,0 @@ -require "test_helper" - -class PackageVagrantfileVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::PackageVagrantfile - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - @env["export.temp_dir"] = "foo" - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - @instance = @klass.new(@app, @env) - end - - context "calling" do - should "create the vagrantfile then continue chain" do - seq = sequence("sequence") - @instance.expects(:create_vagrantfile).in_sequence(seq) - @app.expects(:call).with(@env).in_sequence(seq) - - @instance.call(@env) - end - end - - context "creating vagrantfile" do - setup do - @network_adapter = mock("nic") - @network_adapter.stubs(:mac_address).returns("mac_address") - @internal_vm.stubs(:network_adapters).returns([@network_adapter]) - end - - should "write the rendered vagrantfile to temp_path Vagrantfile" do - f = mock("file") - rendered = mock("rendered") - File.expects(:open).with(File.join(@env["export.temp_dir"], "Vagrantfile"), "w").yields(f) - Vagrant::Util::TemplateRenderer.expects(:render).returns(rendered).with("package_Vagrantfile", { - :base_mac => @internal_vm.network_adapters.first.mac_address - }) - f.expects(:write).with(rendered) - - @instance.create_vagrantfile - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/provision_test.rb b/test/unit_legacy/vagrant/action/vm/provision_test.rb deleted file mode 100644 index 446160500c8..00000000000 --- a/test/unit_legacy/vagrant/action/vm/provision_test.rb +++ /dev/null @@ -1,65 +0,0 @@ -require "test_helper" - -class ProvisionVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Provision - @app, @env = action_env - - @vm = mock("vm") - @vm.stubs(:name).returns("foo") - @vm.stubs(:ssh).returns(mock("ssh")) - @vm.stubs(:system).returns(mock("system")) - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - end - - context "with an instance" do - setup do - # Set provisioner to nil so the provisioner isn't loaded on init - @env["config"].vm.provisioners.clear - @instance = @klass.new(@app, @env) - end - - context "loading a provisioner" do - should "instantiate and prepare each provisioner" do - @env["config"].vm.provision :chef_solo - @env["config"].vm.provision :chef_solo - provisioners = @instance.enabled_provisioners - - assert_equal 2, provisioners.length - end - - should "set the config for each provisioner" do - @env["config"].vm.provision :chef_solo do |chef| - chef.cookbooks_path = "foo" - end - - provisioners = @instance.enabled_provisioners - - assert_equal "foo", provisioners.first.config.cookbooks_path - end - end - - context "calling" do - should "provision and continue chain" do - provisioners = [mock("one"), mock("two")] - seq = sequence("seq") - @instance.stubs(:enabled_provisioners).returns(provisioners) - - provisioners.each do |prov| - prov.expects(:prepare).in_sequence(seq) - end - - @app.expects(:call).with(@env).in_sequence(seq) - - provisioners.each do |prov| - prov.expects(:provision!).in_sequence(seq) - end - - @instance.call(@env) - end - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/provisioner_cleanup_test.rb b/test/unit_legacy/vagrant/action/vm/provisioner_cleanup_test.rb deleted file mode 100644 index 132a7eb30e9..00000000000 --- a/test/unit_legacy/vagrant/action/vm/provisioner_cleanup_test.rb +++ /dev/null @@ -1,56 +0,0 @@ -require "test_helper" - -class ProvisionerCleanupVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::ProvisionerCleanup - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - end - - context "with an instance" do - setup do - # Set provisioner to nil so the provisioner isn't loaded on init - @env["config"].vm.provisioners.clear - @instance = @klass.new(@app, @env) - end - - context "loading a provisioner" do - should "instantiate and prepare each provisioner" do - @env["config"].vm.provision :chef_solo - @env["config"].vm.provision :chef_solo - provisioners = @instance.enabled_provisioners - - assert_equal 2, provisioners.length - end - - should "set the config for each provisioner" do - @env["config"].vm.provision :chef_solo do |chef| - chef.cookbooks_path = "foo" - end - - provisioners = @instance.enabled_provisioners - - assert_equal "foo", provisioners.first.config.cookbooks_path - end - end - - context "calling" do - should "provision and continue chain" do - provisioners = [mock("one"), mock("two")] - seq = sequence("seq") - @instance.stubs(:enabled_provisioners).returns(provisioners) - provisioners.each do |prov| - prov.expects(:cleanup).in_sequence(seq) - end - @app.expects(:call).with(@env).in_sequence(seq) - - @instance.call(@env) - end - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/resume_test.rb b/test/unit_legacy/vagrant/action/vm/resume_test.rb deleted file mode 100644 index 95a33020cef..00000000000 --- a/test/unit_legacy/vagrant/action/vm/resume_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require "test_helper" - -class ResumeVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Resume - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - context "calling" do - should "run the proper methods when saved" do - @internal_vm.expects(:saved?).returns(true) - - seq = sequence("seq") - @env.env.actions.expects(:run).with(Vagrant::Action::VM::Boot).once.in_sequence(seq) - @app.expects(:call).with(@env).once.in_sequence(seq) - @instance.call(@env) - end - - should "do nothing if VM is not saved" do - @internal_vm.expects(:saved?).returns(false) - - @vm.expects(:start).never - @app.expects(:call).with(@env).once - @instance.call(@env) - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/share_folders_test.rb b/test/unit_legacy/vagrant/action/vm/share_folders_test.rb deleted file mode 100644 index 52e7baf0601..00000000000 --- a/test/unit_legacy/vagrant/action/vm/share_folders_test.rb +++ /dev/null @@ -1,144 +0,0 @@ -require "test_helper" - -class ShareFoldersVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::ShareFolders - @app, @env = action_env - - @vm = mock("vm") - @vm.stubs(:name).returns("foo") - @vm.stubs(:ssh).returns(mock("ssh")) - @vm.stubs(:system).returns(mock("system")) - @env["vm"] = @vm - @env["vm.modify"] = mock("proc") - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - # No validation for this test since its a nightmare due to all the - # nonexistent shared folders. - Vagrant::Config::Top.any_instance.stubs(:validate!) - - @instance = @klass.new(@app, @env) - end - - def stub_shared_folders(contents) - env = vagrant_env(vagrantfile(<<-vf)) - config.vm.shared_folders.clear - #{contents} - vf - - @env.stubs(:env).returns(env) - env.config.vm.shared_folders - end - - context "calling" do - should "run the methods in the proper order" do - before_seq = sequence("before") - @instance.expects(:create_metadata).once.in_sequence(before_seq) - @app.expects(:call).with(@env).in_sequence(before_seq) - @instance.expects(:mount_shared_folders).once.in_sequence(before_seq) - - @instance.call(@env) - end - end - - context "collecting shared folders" do - should "return a hash of the shared folders" do - data = { - "foo" => %W[bar baz], - "bar" => %W[foo baz] - } - - stub_shared_folders(<<-sf) - config.vm.share_folder("foo", "bar", "baz") - config.vm.share_folder("bar", "foo", "baz") - sf - - result = @instance.shared_folders - assert_equal data.length, result.length - data.each do |name, value| - guest, host = value - assert_equal guest, result[name][:guestpath] - assert_equal host, result[name][:hostpath] - end - end - - should "ignore disabled shared folders" do - stub_shared_folders(<<-sf) - config.vm.share_folder("v-foo", "/foo", "/foo") - config.vm.share_folder("v-root", "/vagrant", ".", :disabled => true) - config.vm.share_folder("v-bar", "/bar", "/bar") - sf - - assert_equal 2, @instance.shared_folders.length - assert_equal %W[v-bar v-foo], @instance.shared_folders.keys.sort - end - - should "not destroy original hash" do - @folders = stub_shared_folders(<<-sf) - config.vm.share_folder("foo", "bar", "baz", :sync => true) - sf - - folder = @folders["foo"].dup - - @instance.shared_folders - assert_equal folder, @env.env.config.vm.shared_folders["foo"] - end - end - - context "setting up shared folder metadata" do - setup do - stub_shared_folders(<<-sf) - config.vm.share_folder("foo", "fooguest", "foohost") - config.vm.share_folder("bar", "barguest", "barhost") - sf - end - - should "add all shared folders to the VM" do - shared_folders = [] - data = %W[foo bar] - shared_folders.expects(:<<).times(data.length).with() do |sf| - hostpath = File.expand_path("#{sf.name}host", @env.env.root_path) - assert data.include?(sf.name) - assert_equal hostpath, sf.host_path - true - end - - @internal_vm.stubs(:shared_folders).returns(shared_folders) - - @env["vm.modify"].expects(:call).with() do |proc| - proc.call(@internal_vm) - true - end - - @instance.create_metadata - end - end - - context "mounting the shared folders" do - setup do - @folders = stub_shared_folders(<<-sf) - config.vm.share_folder("foo", "fooguest", "foohost", :owner => "yo", :group => "fo") - config.vm.share_folder("bar", "fooguest/foo", "barhost", :owner => "foo", :group => "bar") - config.vm.share_folder("foo_no_mount", nil, "foohost2") - sf - @ssh = mock("ssh") - @vm.ssh.stubs(:execute).yields(@ssh) - @vm.system.stubs(:mount_shared_folder) - end - - should "mount all shared folders to the VM" do - mount_seq = sequence("mount_seq") - @folders.each do |name, data| - if data[:guestpath] - @vm.system.expects(:mount_shared_folder).with(@ssh, name, data[:guestpath], data[:owner], data[:group]).in_sequence(mount_seq) - else - @vm.system.expects(:mount_shared_folder).with(@ssh, name, anything, anything, anything).never - end - end - - @instance.mount_shared_folders - end - end -end diff --git a/test/unit_legacy/vagrant/action/vm/suspend_test.rb b/test/unit_legacy/vagrant/action/vm/suspend_test.rb deleted file mode 100644 index 2f94cdf0a3f..00000000000 --- a/test/unit_legacy/vagrant/action/vm/suspend_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require "test_helper" - -class SuspendVMActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action::VM::Suspend - @app, @env = action_env - - @vm = mock("vm") - @env["vm"] = @vm - - @internal_vm = mock("internal") - @vm.stubs(:vm).returns(@internal_vm) - - @instance = @klass.new(@app, @env) - end - - context "calling" do - should "run the proper methods when running" do - @internal_vm.expects(:running?).returns(true) - - seq = sequence("seq") - @internal_vm.expects(:save_state).once.in_sequence(seq) - @app.expects(:call).with(@env).once.in_sequence(seq) - @instance.call(@env) - end - - should "do nothing if VM is not running" do - @internal_vm.expects(:running?).returns(false) - - @internal_vm.expects(:save_state).never - @app.expects(:call).with(@env).once - @instance.call(@env) - end - end -end diff --git a/test/unit_legacy/vagrant/action_test.rb b/test/unit_legacy/vagrant/action_test.rb deleted file mode 100644 index a849ec6f89c..00000000000 --- a/test/unit_legacy/vagrant/action_test.rb +++ /dev/null @@ -1,89 +0,0 @@ -require "test_helper" - -class ActionTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Action - end - - context "with a class" do - teardown do - @klass.actions.delete(:foo) - end - - should "be able to register an action" do - @klass.register(:foo, :bar) - assert @klass.actions.has_key?(:foo) - assert_equal :bar, @klass.actions[:foo] - end - - should "be able to retrieve an action using []" do - @klass.register(:foo, :bar) - assert_equal :bar, @klass[:foo] - end - end - - context "with an instance" do - setup do - @instance = @klass.new(vagrant_env) - end - - should "raise an exception if a nil action is given" do - assert_raises(ArgumentError) { @instance.run(nil) } - assert_raises(ArgumentError) { @instance.run(:dontexist) } - end - - should "run the callable item with the proper context" do - callable = mock("callable") - callable.expects(:call).with() do |env| - assert env.kind_of?(Vagrant::Action::Environment) - assert_equal @instance.env, env.env - true - end - - @instance.run(callable) - end - - should "run the callable with the passed in options if given" do - options = { - :key => :value, - :another => %W[1 2 3] - } - - callable = mock("callable") - callable.expects(:call).with() do |env| - assert env.kind_of?(Vagrant::Action::Environment) - assert_equal @instance.env, env.env - - options.each do |k,v| - assert_equal v, env[k] - end - - true - end - - @instance.run(callable, options) - end - - should "run the registered callable if a symbol is given" do - callable = mock("callable") - callable.expects(:call).once - - @klass.register(:call, callable) - @instance.run(:call) - @klass.actions.delete(:call) - end - - should "run the given class if a class is given" do - callable = Class.new do - def initialize(app, env); end - end - - callable.any_instance.expects(:call).with() do |env| - assert_equal :foo, env[:bar] - true - end - - @instance.run(callable, :bar => :foo) - end - end -end diff --git a/test/unit_legacy/vagrant/box_collection_test.rb b/test/unit_legacy/vagrant/box_collection_test.rb deleted file mode 100644 index 9763d29190c..00000000000 --- a/test/unit_legacy/vagrant/box_collection_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "test_helper" - -class BoxCollectionTest < Test::Unit::TestCase - setup do - clean_paths - - @klass = Vagrant::BoxCollection - end - - should "load all the boxes from the box path" do - vagrant_box("foo") - vagrant_box("bar") - - result = @klass.new(vagrant_env) - names = result.collect { |b| b.name }.sort - assert result.length >= 2 - assert names.include?("foo") - assert names.include?("bar") - end - - should "reload the box list" do - instance = @klass.new(vagrant_env) - amount = instance.length - - vagrant_box("foo") - - instance.reload! - assert_equal (amount + 1), instance.length - end - - should "find a specific box" do - vagrant_box("foo") - vagrant_box("bar") - - instance = @klass.new(vagrant_env) - result = instance.find("foo") - assert result - assert_equal "foo", result.name - end - - should "return nil if it couldn't find a specific box" do - instance = @klass.new(vagrant_env) - assert_nil instance.find("thisshouldnotexist") - end -end diff --git a/test/unit_legacy/vagrant/box_test.rb b/test/unit_legacy/vagrant/box_test.rb deleted file mode 100644 index e50a74802e8..00000000000 --- a/test/unit_legacy/vagrant/box_test.rb +++ /dev/null @@ -1,74 +0,0 @@ -require "test_helper" - -class BoxTest < Test::Unit::TestCase - context "class methods" do - setup do - @env = vagrant_env - end - - context "adding" do - setup do - @name = "foo" - @uri = "bar" - end - - should "create a new instance, set the variables, and add it" do - box = mock("box") - box.expects(:uri=).with(@uri) - box.expects(:add).once - Vagrant::Box.expects(:new).with(@env, @name).returns(box) - Vagrant::Box.add(@env, @name, @uri) - end - end - end - - context "instance methods" do - setup do - @box = Vagrant::Box.new(vagrant_env, "foo") - end - - should "raise an exception if a box exists with the name we're attempting to add" do - vagrant_box(@box.name) - - assert_raises(Vagrant::Errors::BoxAlreadyExists) { - @box.add - } - end - - should "execute the Add action when add is called" do - @box.env.actions.expects(:run).with(:box_add, { "box" => @box, "validate" => false }) - @box.add - end - - context "box directory" do - should "return the boxes_path joined with the name" do - assert_equal @box.env.boxes_path.join(@box.name), @box.directory - end - end - - context "destroying" do - should "execute the destroy action" do - @box.env.actions.expects(:run).with(:box_remove, { "box" => @box, "validate" => false }) - @box.destroy - end - end - - context "repackaging" do - should "execute the repackage action" do - @box.env.actions.expects(:run).with(:box_repackage, { "box" => @box, "validate" => false }) - @box.repackage - end - - should "forward given options into the action" do - @box.env.actions.expects(:run).with(:box_repackage, { "box" => @box, "foo" => "bar", "validate" => false }) - @box.repackage("foo" => "bar") - end - end - - context "ovf file" do - should "be the directory joined with the config ovf file" do - assert_equal @box.directory.join(@box.env.config.vm.box_ovf), @box.ovf_file - end - end - end -end diff --git a/test/unit_legacy/vagrant/cli_test.rb b/test/unit_legacy/vagrant/cli_test.rb deleted file mode 100644 index 05f716b2e60..00000000000 --- a/test/unit_legacy/vagrant/cli_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require "test_helper" - -class CLITest < Test::Unit::TestCase - setup do - @klass = Vagrant::CLI - end - - context "registering" do - should "register a base command as a single invokable" do - base = Class.new(Vagrant::Command::Base) - name = "__test_registering_single_subcommand" - @klass.register(base, name, name, "A description") - assert @klass.tasks[name] - end - - should "register a group base as a subcommand" do - base = Class.new(Vagrant::Command::GroupBase) - name = "_test_registering_single_group" - @klass.register(base, name, name, "A description") - assert @klass.subcommands.include?(name) - end - - should "alias methods if the alias option is given" do - base = Class.new(Vagrant::Command::Base) do - def execute - raise "WORKED" - end - end - - name = "__test_registering_with_alias" - @klass.register(base, name, name, "A description", :alias => "--ALIAS") - assert_raises(RuntimeError) { @klass.start(["--ALIAS"], :env => vagrant_env) } - end - end -end diff --git a/test/unit_legacy/vagrant/command/base_test.rb b/test/unit_legacy/vagrant/command/base_test.rb deleted file mode 100644 index 0d09e5da919..00000000000 --- a/test/unit_legacy/vagrant/command/base_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -require "test_helper" - -class CommandBaseTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Command::Base - @env = vagrant_env - end - - context "initialization" do - should "require an environment" do - assert_raises(Vagrant::Errors::CLIMissingEnvironment) { @klass.new([], {}, {}) } - assert_nothing_raised { @klass.new([], {}, { :env => @env }) } - end - end - - context "extracting a name from a usage string" do - should "extract properly" do - assert_equal "init", @klass.extract_name_from_usage("init") - assert_equal "init", @klass.extract_name_from_usage("init [foo] [bar]") - assert_equal "ssh-config", @klass.extract_name_from_usage("ssh-config") - end - end -end diff --git a/test/unit_legacy/vagrant/command/group_base_test.rb b/test/unit_legacy/vagrant/command/group_base_test.rb deleted file mode 100644 index 0def8b817d7..00000000000 --- a/test/unit_legacy/vagrant/command/group_base_test.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "test_helper" - -class CommandGroupBaseTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Command::GroupBase - @env = vagrant_env - end - - context "initialization" do - should "require an environment" do - assert_raises(Vagrant::Errors::CLIMissingEnvironment) { @klass.new([], {}, {}) } - assert_nothing_raised { @klass.new([], {}, { :env => @env }) } - end - end -end diff --git a/test/unit_legacy/vagrant/command/helpers_test.rb b/test/unit_legacy/vagrant/command/helpers_test.rb deleted file mode 100644 index 8fc2f06dc92..00000000000 --- a/test/unit_legacy/vagrant/command/helpers_test.rb +++ /dev/null @@ -1,88 +0,0 @@ -require "test_helper" - -class CommandHelpersTest < Test::Unit::TestCase - setup do - @module = Vagrant::Command::Helpers - @command = Class.new(Vagrant::Command::Base) do - argument :name, :optional => true, :type => :string - end - end - - def command(args, env) - @command.new(args, {}, { :env => env }) - end - - context "initializing environment" do - should "raise an exception if no environment is given" do - assert_raises(Vagrant::Errors::CLIMissingEnvironment) { command([], nil) } - end - end - - context "vms from args" do - setup do - @env = vagrant_env - end - - should "raise an exception if no root path" do - @env.stubs(:root_path).returns(nil) - - assert_raises(Vagrant::Errors::NoEnvironmentError) { - command([], @env).target_vms - } - end - - should "only calculate the result once" do - instance = command([], @env) - result = instance.target_vms - assert instance.target_vms.equal?(result) - end - - context "without multivm" do - setup do - @env.stubs(:vms_ordered => [1, 2], :vms => {:one => 1, :two => 2}) - end - - should "raise an exception if a name is specified" do - instance = command(["foo"], vagrant_env) - assert_raises(Vagrant::Errors::MultiVMEnvironmentRequired) { - instance.target_vms - } - end - - should "return the VM if no name is specified" do - instance = command([], @env) - assert_nothing_raised { - assert_equal @env.vms.values.sort, instance.target_vms.sort - } - end - end - - context "with multivm" do - setup do - @env.stubs(:vms_ordered => [1, 2], :vms => {:one => 1, :two => 2}) - end - - should "return all the VMs if no name is specified" do - instance = command([], @env) - assert_equal @env.vms.values.sort, instance.target_vms.sort - end - - should "return only the specified VM if a name is given" do - instance = command(["one"], @env) - assert_equal @env.vms[:one], instance.target_vms.first - end - - should "return only the specified VM if name is given in the arg" do - instance = command([], @env) - assert_equal @env.vms[:two], instance.target_vms("two").first - end - - should "raise an exception if an invalid name is given" do - instance = command(["foo"], @env) - assert_raises(Vagrant::Errors::VMNotFoundError) { - instance.target_vms - } - end - end - end -end diff --git a/test/unit_legacy/vagrant/command/init_test.rb b/test/unit_legacy/vagrant/command/init_test.rb deleted file mode 100644 index 7005a46635a..00000000000 --- a/test/unit_legacy/vagrant/command/init_test.rb +++ /dev/null @@ -1,10 +0,0 @@ -require "test_helper" - -class CommandInitCommandTest < Test::Unit::TestCase - should "create a Vagrantfile in the environment's cwd" do - path = vagrant_app - env = Vagrant::Environment.new(:cwd => path) - silence(:stdout) { env.cli("init") } - assert File.exist?(path.join("Vagrantfile")) - end -end diff --git a/test/unit_legacy/vagrant/command/package_test.rb b/test/unit_legacy/vagrant/command/package_test.rb deleted file mode 100644 index 6330a9c9ef0..00000000000 --- a/test/unit_legacy/vagrant/command/package_test.rb +++ /dev/null @@ -1,27 +0,0 @@ -require "test_helper" - -class CommandPackageCommandTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Command::PackageCommand - @env = vagrant_env - end - - def command(args, opts, env) - @klass.new(args, opts, { :env => env }) - end - - context "initialization" do - should "require an environment" do - assert_raises(Vagrant::Errors::CLIMissingEnvironment) { command([], {}, nil) } - assert_nothing_raised { command([], {}, @env) } - end - end - - should "raise an exception if VM for supplied base option is not found" do - Vagrant::VM.stubs(:find).returns(Vagrant::VM.new(nil)) - - assert_raises(Vagrant::Errors::BaseVMNotFound) { - command([], { :base => "foo" }, @env).execute - } - end -end diff --git a/test/unit_legacy/vagrant/config/base_test.rb b/test/unit_legacy/vagrant/config/base_test.rb deleted file mode 100644 index ed251c67a1e..00000000000 --- a/test/unit_legacy/vagrant/config/base_test.rb +++ /dev/null @@ -1,52 +0,0 @@ -require "test_helper" - -class ConfigBaseTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Config::Base - end - - context "class methods" do - should "enable configuration with proper accessor" do - klass = Class.new(@klass) - acc = :foo - Vagrant::Config::Top.expects(:configures).with(acc, klass) - klass.configures(acc) - end - end - - context "instance methods" do - setup do - @base = @klass.new - end - - should "return a hash of instance variables" do - data = { "foo" => "bar", "bar" => "baz" } - - data.each do |iv, value| - @base.instance_variable_set("@#{iv}".to_sym, value) - end - - result = @base.instance_variables_hash - assert_equal data.length, result.length - - data.each do |iv, value| - assert_equal value, result[iv] - end - end - - context "converting to JSON" do - should "include magic `json_class`" do - @iv_hash = { "foo" => "bar" } - @base.expects(:instance_variables_hash).returns(@iv_hash) - @json = { 'json_class' => @base.class.name }.merge(@iv_hash).to_json - assert_equal @json, @base.to_json - end - - should "not include top in the JSON hash" do - @base.top = "FOO" - hash = @base.instance_variables_hash - assert !hash.has_key?(:top) - end - end - end -end diff --git a/test/unit_legacy/vagrant/config/error_recorder_test.rb b/test/unit_legacy/vagrant/config/error_recorder_test.rb deleted file mode 100644 index c9b1d37ace9..00000000000 --- a/test/unit_legacy/vagrant/config/error_recorder_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "test_helper" - -class ConfigErrorsTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Config::ErrorRecorder - @instance = @klass.new - end - - should "not have any errors to start" do - assert @instance.errors.empty? - end - - should "add errors" do - key = "vagrant.test.errors.test_key" - @instance.add(key) - assert_equal key, @instance.errors.first - end -end diff --git a/test/unit_legacy/vagrant/config/ssh_test.rb b/test/unit_legacy/vagrant/config/ssh_test.rb deleted file mode 100644 index 2fb90e333b3..00000000000 --- a/test/unit_legacy/vagrant/config/ssh_test.rb +++ /dev/null @@ -1,12 +0,0 @@ -require "test_helper" - -class ConfigSSHTest < Test::Unit::TestCase - setup do - @env = vagrant_env - end - - should "expand any path when requesting the value" do - result = File.expand_path(@env.config.ssh.private_key_path, @env.root_path) - assert_equal result, @env.config.ssh.private_key_path - end -end diff --git a/test/unit_legacy/vagrant/config/vagrant_test.rb b/test/unit_legacy/vagrant/config/vagrant_test.rb deleted file mode 100644 index 4ca3091e687..00000000000 --- a/test/unit_legacy/vagrant/config/vagrant_test.rb +++ /dev/null @@ -1,35 +0,0 @@ -require "test_helper" - -class ConfigVagrantTest < Test::Unit::TestCase - setup do - @config = Vagrant::Config::VagrantConfig.new - end - - context "validation" do - setup do - @config.dotfile_name = "foo" - @config.host = "foo" - - @errors = Vagrant::Config::ErrorRecorder.new - end - - should "be valid with given set of values" do - @config.validate(@errors) - assert @errors.errors.empty? - end - - should "be invalid with no dotfile" do - @config.dotfile_name = nil - - @config.validate(@errors) - assert !@errors.errors.empty? - end - - should "be invalid with no host" do - @config.host = nil - - @config.validate(@errors) - assert !@errors.errors.empty? - end - end -end diff --git a/test/unit_legacy/vagrant/config/vm/provisioner_test.rb b/test/unit_legacy/vagrant/config/vm/provisioner_test.rb deleted file mode 100644 index ba45acbfe51..00000000000 --- a/test/unit_legacy/vagrant/config/vm/provisioner_test.rb +++ /dev/null @@ -1,92 +0,0 @@ -require "test_helper" - -class ConfigVMProvisionerTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Config::VMConfig::Provisioner - @top = Vagrant::Config::Top.new(nil) - end - - context "initializing" do - should "expose the top instance that the provisioner belongs to" do - instance = @klass.new(@top, :chef_solo) - assert_equal @top, instance.top - end - - should "expose the shortcut used" do - instance = @klass.new(@top, :chef_solo) - assert_equal :chef_solo, instance.shortcut - end - - should "expose the provisioner class if its a valid shortcut" do - instance = @klass.new(@top, :chef_solo) - assert_equal Vagrant::Provisioners::ChefSolo, instance.provisioner - end - - should "expose the provisioner class if its a valid class" do - instance = @klass.new(@top, Vagrant::Provisioners::ChefSolo) - assert_equal Vagrant::Provisioners::ChefSolo, instance.provisioner - end - - should "have a nil provisioner class if invalid" do - instance = @klass.new(@top, :i_shall_never_exist) - assert_nil instance.provisioner - end - - should "have a nil config instance if invalid" do - instance = @klass.new(@top, :i_shall_never_exist) - assert_nil instance.config - end - - should "set the top of the config object to the given top" do - instance = @klass.new(@top, :chef_solo) - assert_equal @top, instance.config.top - end - - should "configure the provisioner if valid" do - instance = @klass.new(@top, :chef_solo) do |chef| - chef.cookbooks_path = "foo" - end - - assert_equal "foo", instance.config.cookbooks_path - end - - should "configure the provisioner with a hash if valid" do - instance = @klass.new(@top, :chef_solo, :cookbooks_path => "foo") - assert_equal "foo", instance.config.cookbooks_path - end - end - - context "validation" do - setup do - @errors = Vagrant::Config::ErrorRecorder.new - end - - should "be invalid if provisioner is valid" do - instance = @klass.new(@top, :i_shall_never_exist) - instance.validate(@errors) - assert !@errors.errors.empty? - end - - should "be invalid if provisioner doesn't inherit from provisioners base" do - klass = Class.new - instance = @klass.new(@top, klass) - instance.validate(@errors) - assert !@errors.errors.empty? - end - - should "be valid with a valid provisioner" do - instance = @klass.new(@top, :chef_solo) do |chef| - chef.add_recipe "foo" - end - - instance.validate(@errors) - assert @errors.errors.empty? - end - - should "be invalid if a provisioner's config is invalid" do - instance = @klass.new(@top, :chef_solo) - instance.validate(@errors) - assert !@errors.errors.empty? - end - end -end diff --git a/test/unit_legacy/vagrant/config/vm_test.rb b/test/unit_legacy/vagrant/config/vm_test.rb deleted file mode 100644 index 3501af53fd7..00000000000 --- a/test/unit_legacy/vagrant/config/vm_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -require "test_helper" - -class ConfigVMTest < Test::Unit::TestCase - setup do - @username = "mitchellh" - - @env = vagrant_env - @config = @env.config.vm - @env.config.ssh.username = @username - end - - context "defining VMs" do - should "store the proc by name but not run it" do - foo = mock("proc") - foo.expects(:call).never - - proc = Proc.new { foo.call } - @config.define(:name, &proc) - assert @config.defined_vms[:name].proc_stack.include?(proc) - end - - should "store the options" do - @config.define(:name, :set => true) - assert @config.defined_vms[:name].options[:set] - end - - should "retain vm definition order" do - @config.define(:a) {} - @config.define(:b) {} - @config.define(:c) {} - - assert_equal [:a, :b, :c], @config.defined_vm_keys - end - end - - context "customizing" do - should "include the stacked proc runner module" do - assert @config.class.included_modules.include?(Vagrant::Util::StackedProcRunner) - end - - should "add the customize proc to the proc stack" do - proc = Proc.new {} - @config.customize(&proc) - assert @config.proc_stack.include?(proc) - end - end -end diff --git a/test/unit_legacy/vagrant/config_test.rb b/test/unit_legacy/vagrant/config_test.rb deleted file mode 100644 index 38fe7edd792..00000000000 --- a/test/unit_legacy/vagrant/config_test.rb +++ /dev/null @@ -1,148 +0,0 @@ -require "test_helper" - -class ConfigTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Config - end - - context "with an instance" do - setup do - @instance = @klass.new - end - - should "load the config files in the given order" do - names = %w{alpha beta gamma} - - @instance.load_order = [:alpha, :beta] - - names.each do |name| - vagrantfile(vagrant_box(name), "config.vm.box = '#{name}'") - @instance.set(name.to_sym, vagrant_box(name).join("Vagrantfile")) - end - - config = @instance.load(nil) - assert_equal "beta", config.vm.box - end - - should "load the config as procs" do - @instance.set(:proc, Proc.new { |config| config.vm.box = "proc" }) - @instance.load_order = [:proc] - config = @instance.load(nil) - - assert_equal "proc", config.vm.box - end - - should "load an array of procs" do - @instance.set(:proc, [Proc.new { |config| config.vm.box = "proc" }, - Proc.new { |config| config.vm.box = "proc2" }]) - @instance.load_order = [:proc] - config = @instance.load(nil) - - assert_equal "proc2", config.vm.box - end - - should "not care if a file doesn't exist" do - @instance.load_order = [:foo] - assert_nothing_raised { @instance.set(:foo, "i/dont/exist") } - assert_nothing_raised { @instance.load(nil) } - end - - should "not reload a file" do - foo_path = vagrant_box("foo").join("Vagrantfile") - - vagrantfile(vagrant_box("foo")) - @instance.set(:foo, foo_path) - - # Nothing should be raised in this case because the file isn't reloaded - vagrantfile(vagrant_box("foo"), "^%&8318") - assert_nothing_raised { @instance.set(:foo, foo_path) } - end - - should "raise an exception if there is a syntax error in a file" do - vagrantfile(vagrant_box("foo"), "^%&8318") - - assert_raises(Vagrant::Errors::VagrantfileSyntaxError) { - @instance.set(:foo, vagrant_box("foo").join("Vagrantfile")) - } - end - end - - context "top config class" do - setup do - @configures_list = {} - @klass::Top.stubs(:configures_list).returns(@configures_list) - end - - context "adding configure keys" do - setup do - @key = "top_config_foo" - @config_klass = mock("klass") - end - - should "add key and klass to configures list" do - @klass::Top.configures(@key, @config_klass) - assert_equal @config_klass, @configures_list[@key] - end - end - - context "configuration keys on instance" do - setup do - @configures_list.clear - end - - should "initialize each configurer and set it to its key" do - env = mock('env') - - 5.times do |i| - key = "key#{i}" - klass = mock("klass#{i}") - instance = mock("instance#{i}") - instance.expects(:top=).with() do |top| - assert top.is_a?(@klass::Top) - true - end - klass.expects(:new).returns(instance) - @configures_list[key] = klass - end - - @klass::Top.new(env) - end - - should "allow reading via methods" do - key = "my_foo_bar_key" - klass = mock("klass") - instance = mock("instance") - instance.stubs(:top=) - klass.expects(:new).returns(instance) - @klass::Top.configures(key, klass) - - config = @klass::Top.new - assert_equal instance, config.send(key) - end - end - - context "validation" do - should "do nothing if no errors are added" do - valid_class = Class.new(@klass::Base) - @klass::Top.configures(:subconfig, valid_class) - instance = @klass::Top.new - assert_nothing_raised { instance.validate! } - end - - should "raise an exception if there are errors" do - invalid_class = Class.new(@klass::Base) do - def validate(errors) - errors.add("vagrant.test.errors.test_key") - end - end - - @klass::Top.configures(:subconfig, invalid_class) - instance = @klass::Top.new - - assert_raises(Vagrant::Errors::ConfigValidationFailed) { - instance.validate! - } - end - end - end -end diff --git a/test/unit_legacy/vagrant/downloaders/http_test.rb b/test/unit_legacy/vagrant/downloaders/http_test.rb deleted file mode 100644 index 946a2214ff1..00000000000 --- a/test/unit_legacy/vagrant/downloaders/http_test.rb +++ /dev/null @@ -1,93 +0,0 @@ -require "test_helper" - -class HttpDownloaderTest < Test::Unit::TestCase - setup do - @downloader, @tempfile = vagrant_mock_downloader(Vagrant::Downloaders::HTTP) - @downloader.stubs(:report_progress) - @downloader.stubs(:complete_progress) - @uri = "http://google.com/" - @headers = nil - end - - context "downloading" do - setup do - ENV["http_proxy"] = nil - - @parsed_uri = URI.parse(@uri) - @http = Net::HTTP.new(@parsed_uri.host, @parsed_uri.port) - Net::HTTP.stubs(:new).returns(@http) - @http.stubs(:start) - end - - should "create a proper net/http object" do - Net::HTTP.expects(:new).with(@parsed_uri.host, @parsed_uri.port, nil, nil, nil, nil).once.returns(@http) - @http.expects(:start) - @downloader.download!(@uri, @tempfile) - end - - should "create a proper net/http object with a proxy" do - ENV["http_proxy"] = "http://user:foo@google.com" - @proxy = URI.parse(ENV["http_proxy"]) - Net::HTTP.expects(:new).with(@parsed_uri.host, @parsed_uri.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password).once.returns(@http) - @http.expects(:start) - @downloader.download!(@uri, @tempfile) - end - - should "create a proper net/http object without a proxy if no_proxy defined" do - @uri = "http://somewhere.direct.com/some_file" - @parsed_uri = URI.parse(@uri) - ENV["http_proxy"] = "http://user:foo@google.com" - ENV["no_proxy"] = "direct.com" - Net::HTTP.expects(:new).with(@parsed_uri.host, @parsed_uri.port, nil, nil, nil, nil).once.returns(@http) - @http.expects(:start) - @downloader.download!(@uri, @tempfile) - end - - should "enable SSL if scheme is https" do - @uri = "https://google.com/" - @http.expects(:use_ssl=).with(true).once - @downloader.download!(@uri, @tempfile) - end - - should "read the body of the response and place each segment into the file" do - h = mock("http") - response = mock("response") - response.stubs(:content_length) - response.stubs(:is_a?).with(anything).returns(false) - response.stubs(:is_a?).with(Net::HTTPOK).returns(true) - segment = mock("segment") - segment.stubs(:length).returns(7) - - @http.stubs(:start).yields(h) - h.expects(:request_get).with(@parsed_uri.request_uri, @headers).once.yields(response) - response.expects(:read_body).once.yields(segment) - @tempfile.expects(:write).with(segment).once - - @downloader.download!(@uri, @tempfile) - end - - should "error environment if invalid URL given" do - Net::HTTP.expects(:new).raises(SocketError.new) - - assert_raises(Vagrant::Errors::DownloaderHTTPSocketError) { - @downloader.download!(@uri, @tempfile) - } - end - end - - context "matching the uri" do - should "use extract to verify that the string is in fact a uri" do - URI.expects(:extract).returns(['foo']) - assert Vagrant::Downloaders::HTTP.match?('foo') - end - - should "return false if there are no extract results" do - URI.expects(:extract).returns([]) - assert !Vagrant::Downloaders::HTTP.match?('foo') - end - end - - context "reporting progress" do - # TODO: Testing for this, probably - end -end diff --git a/test/unit_legacy/vagrant/environment_test.rb b/test/unit_legacy/vagrant/environment_test.rb deleted file mode 100644 index 18997259728..00000000000 --- a/test/unit_legacy/vagrant/environment_test.rb +++ /dev/null @@ -1,539 +0,0 @@ -require "test_helper" -require "pathname" -require "tempfile" - -class EnvironmentTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Environment - - clean_paths - end - - context "class method check virtualbox version" do - setup do - VirtualBox.stubs(:version).returns("4.1.0") - end - - should "not error and exit if everything is good" do - VirtualBox.expects(:version).returns("4.1.0") - assert_nothing_raised { @klass.check_virtualbox! } - end - - should "error and exit if VirtualBox is not installed or detected" do - VirtualBox.expects(:version).returns(nil) - assert_raises(Vagrant::Errors::VirtualBoxNotDetected) { @klass.check_virtualbox! } - end - - should "error and exit if VirtualBox is lower than version 4.0" do - version = "3.2.12r1041" - VirtualBox.expects(:version).returns(version) - assert_raises(Vagrant::Errors::VirtualBoxInvalidVersion) { @klass.check_virtualbox! } - end - end - - context "initialization" do - should "set the cwd if given" do - cwd = "foobarbaz" - env = @klass.new(:cwd => cwd) - assert_equal Pathname.new(cwd), env.cwd - end - - should "default to pwd if cwd is nil" do - env = @klass.new - assert_equal Pathname.new(Dir.pwd), env.cwd - end - end - - context "paths" do - setup do - @env = vagrant_env - end - - context "dotfile path" do - should "build up the dotfile out of the root path and the dotfile name" do - assert_equal @env.root_path.join(@env.config.vagrant.dotfile_name), @env.dotfile_path - end - end - - context "home path" do - setup do - @env = @klass.new - - # Make a fake home directory for helping with tests - @home_path = tmp_path.join("home") - ENV["HOME"] = @home_path.to_s - FileUtils.rm_rf(@home_path) - FileUtils.mkdir_p(@home_path) - end - - should "return the home path if it loaded" do - ENV["VAGRANT_HOME"] = nil - - expected = Pathname.new(File.expand_path(@klass::DEFAULT_HOME)) - assert_equal expected, @env.home_path - end - - should "return the home path set by the environmental variable" do - ENV["VAGRANT_HOME"] = "foo" - - expected = Pathname.new(File.expand_path(ENV["VAGRANT_HOME"])) - assert_equal expected, @env.home_path - end - end - - context "temp path" do - should "return the home path joined with 'tmp'" do - assert_equal @env.home_path.join("tmp"), @env.tmp_path - end - end - - context "boxes path" do - should "return the home path joined with 'tmp'" do - assert_equal @env.home_path.join("boxes"), @env.boxes_path - end - end - end - - context "resource" do - setup do - @env = vagrant_env - end - - should "return 'vagrant' as a default" do - assert_equal 'vagrant', @env.resource - end - - should "return the VM name if it is specified" do - @env.stubs(:vm).returns(mock("vm", :name => "foo")) - assert_equal "foo", @env.resource - end - end - - context "primary VM helper" do - should "return the first VM if not multivm" do - env = vagrant_env - assert_equal env.vms[@klass::DEFAULT_VM], env.primary_vm - end - - should "call and return the primary VM from the parent if has one" do - env = vagrant_env(vagrantfile(<<-vf)) - config.vm.define(:web, :primary => true) do; end - config.vm.define :db do; end - vf - - assert_equal :web, env.primary_vm.name - end - - should "return nil if no VM is marked as primary" do - env = vagrant_env(vagrantfile(<<-vf)) - config.vm.define :web - config.vm.define :db - config.vm.define :utility - vf - - assert env.primary_vm.nil? - end - end - - context "multivm? helper" do - should "return true if VM length greater than 1" do - env = vagrant_env(vagrantfile(<<-vf)) - config.vm.define :web - config.vm.define :db - vf - - assert env.multivm? - end - - should "return true if VM length is 1 and a sub-VM is defined" do - env = vagrant_env(vagrantfile(<<-vf)) - config.vm.define :web - vf - - assert env.multivm? - end - - should "return false if only default VM exists" do - assert !vagrant_env.multivm? - end - end - - context "local data" do - should "lazy load the data store only once" do - result = { :foo => :bar } - Vagrant::DataStore.expects(:new).returns(result).once - env = vagrant_env - assert_equal result, env.local_data - assert_equal result, env.local_data - assert_equal result, env.local_data - end - - should "return the parent's local data if a parent exists" do - env = vagrant_env(vagrantfile(<<-vf)) - config.vm.define :web - config.vm.define :db - vf - - env.local_data[:foo] = :bar - - Vagrant::DataStore.expects(:new).never - assert_equal :bar, env.vms[:web].env.local_data[:foo] - end - end - - context "accessing host" do - should "load the host once" do - env = @klass.new(:cwd => vagrantfile) - result = mock("result") - Vagrant::Hosts::Base.expects(:load).with(env, env.config.vagrant.host).once.returns(result) - assert_equal result, env.host - assert_equal result, env.host - assert_equal result, env.host - end - end - - context "accessing actions" do - should "initialize the Action object with the given environment" do - env = @klass.new(:cwd => vagrant_app) - result = mock("result") - Vagrant::Action.expects(:new).with(env).returns(result).once - assert_equal result, env.actions - assert_equal result, env.actions - assert_equal result, env.actions - end - end - - context "global data" do - should "lazy load the data store only once" do - env = vagrant_env - store = env.global_data - - assert env.global_data.equal?(store) - assert env.global_data.equal?(store) - assert env.global_data.equal?(store) - end - - should "return the parent's global data if a parent exists" do - env = vagrant_env(vagrantfile(<<-vf)) - config.vm.define :web - config.vm.define :db - vf - - result = env.global_data - assert env.vms[:web].env.global_data.equal?(result) - end - end - - context "loading the root path" do - should "should walk the parent directories looking for rootfile" do - paths = [Pathname.new("/foo/bar/baz"), - Pathname.new("/foo/bar"), - Pathname.new("/foo"), - Pathname.new("/") - ] - - rootfile = "Foo" - - search_seq = sequence("search_seq") - paths.each do |path| - File.expects(:exist?).with(path.join(rootfile).to_s).returns(false).in_sequence(search_seq) - File.expects(:exist?).with(path).returns(true).in_sequence(search_seq) if !path.root? - end - - assert !@klass.new(:cwd => paths.first, :vagrantfile_name => rootfile).root_path - end - - should "should set the path for the rootfile" do - rootfile = "Foo" - path = Pathname.new(File.expand_path("/foo")) - File.expects(:exist?).with(path.join(rootfile).to_s).returns(true) - - assert_equal path, @klass.new(:cwd => path, :vagrantfile_name => rootfile).root_path - end - - should "not infinite loop on relative paths" do - assert @klass.new(:cwd => "../test").root_path.nil? - end - - should "only load the root path once" do - rootfile = "foo" - env = @klass.new(:vagrantfile_name => rootfile) - File.expects(:exist?).with(env.cwd.join(rootfile).to_s).returns(true).once - - assert_equal env.cwd, env.root_path - assert_equal env.cwd, env.root_path - assert_equal env.cwd, env.root_path - end - - should "only load the root path once even if nil" do - File.stubs(:exist?).returns(false) - - env = @klass.new - assert env.root_path.nil? - assert env.root_path.nil? - assert env.root_path.nil? - end - end - - context "locking" do - setup do - @instance = @klass.new(:lock_path => Tempfile.new('vagrant-test').path) - end - - should "allow nesting locks" do - assert_nothing_raised do - @instance.lock do - @instance.lock do - # Nothing - end - end - end - end - - should "raise an exception if an environment already has a lock" do - @another = @klass.new(:lock_path => @instance.lock_path) - - # Create first locked thread which should succeed - first = Thread.new do - begin - @instance.lock do - Thread.current[:locked] = true - loop { sleep 1000 } - end - rescue Vagrant::Errors::EnvironmentLockedError - Thread.current[:locked] = false - end - end - - # Wait until the first thread has acquired the lock - loop do - break if first[:locked] || !first.alive? - Thread.pass - end - - # Verify that the fist got the lock - assert first[:locked] - - # Create second locked thread which should fail - second = Thread.new do - begin - @another.lock do - Thread.current[:error] = false - end - rescue Vagrant::Errors::EnvironmentLockedError - Thread.current[:error] = true - end - end - - # Wait for the second to end and verify it failed - second.join - assert second[:error] - - # Make sure both threads are killed - first.kill - second.kill - end - end - - context "accessing the configuration" do - should "load the environment if its not already loaded" do - env = @klass.new(:cwd => vagrantfile) - env.expects(:load!).once - env.config - end - - should "not load the environment if its already loaded" do - env = vagrant_env - env.expects(:load!).never - env.config - end - end - - context "accessing the box collection" do - should "create a box collection representing the environment" do - env = vagrant_env - assert env.boxes.is_a?(Vagrant::BoxCollection) - assert_equal env, env.boxes.env - end - - should "not load the environment if its already loaded" do - env = vagrant_env - env.expects(:load!).never - env.boxes - end - - should "return the parent's box collection if it has one" do - env = vagrant_env(vagrantfile(<<-vf)) - config.vm.define :web - config.vm.define :db - vf - - assert env.vms[:web].env.boxes.equal?(env.boxes) - end - end - - context "accessing the VMs hash" do - should "load the environment if its not already loaded" do - env = @klass.new(:cwd => vagrantfile) - assert !env.loaded? - env.vms - assert env.loaded? - end - - should "not load the environment if its already loaded" do - env = vagrant_env - env.expects(:load!).never - env.vms - end - - should "return the parent's VMs hash if it has one" do - env = vagrant_env(vagrantfile(<<-vf)) - config.vm.define :web - config.vm.define :db - vf - - assert env.vms[:web].env.vms.equal?(env.vms) - end - end - - context "loading" do - context "overall load method" do - should "load! should call proper sequence and return itself" do - env = @klass.new(:cwd => vagrantfile) - call_seq = sequence("call_sequence") - @klass.expects(:check_virtualbox!).once.in_sequence(call_seq) - env.expects(:load_config!).once.in_sequence(call_seq) - assert_equal env, env.load! - end - end - - context "loading config" do - setup do - clean_paths - @env = @klass.new(:cwd => vagrantfile) - end - - def create_box_vagrantfile - vagrantfile(vagrant_box("box"), <<-FILE) - config.package.name = "box.box" - config.vm.base_mac = "set" - FILE - end - - def create_home_vagrantfile - vagrantfile(home_path, 'config.package.name = "home.box"') - end - - def create_root_vagrantfile - vagrantfile(@env.root_path, 'config.package.name = "root.box"') - end - - should "load from the project root" do - assert_equal "package.box", @env.config.package.name - end - - should "load from box if specified" do - create_box_vagrantfile - vagrantfile(@env.root_path, "config.vm.box = 'box'") - - assert_equal "box.box", @env.primary_vm.env.config.package.name - end - - should "load from home path if exists" do - create_home_vagrantfile - assert_equal "home.box", @env.config.package.name - end - - should "load from root path" do - create_home_vagrantfile - create_root_vagrantfile - assert_equal "root.box", @env.config.package.name - end - - should "load from a sub-vm configuration if environment represents a VM" do - create_home_vagrantfile - create_box_vagrantfile - vagrantfile(@env.root_path, <<-vf) - config.package.name = "root.box" - config.vm.define :web do |web| - web.vm.box = "box" - web.package.name = "web.box" - end - vf - - assert_equal "root.box", @env.config.package.name - assert_equal "web.box", @env.vms[:web].env.config.package.name - assert_equal "set", @env.vms[:web].env.config.vm.base_mac - end - - should "be able to reload config" do - vagrantfile(@env.root_path, "config.vm.box = 'box'") - - # First load the config normally - @env.load_config! - assert_equal "box", @env.config.vm.box - assert_not_equal "set", @env.config.vm.base_mac - - # Modify the Vagrantfile and reload it, then verify new results - # are available - vagrantfile(@env.root_path, "config.vm.base_mac = 'set'") - @env.reload_config! - assert_equal "set", @env.config.vm.base_mac - end - end - - context "loading home directory" do - setup do - @env = vagrant_env - - File.stubs(:directory?).returns(true) - FileUtils.stubs(:mkdir_p) - end - - should "create each directory if it doesn't exist" do - create_seq = sequence("create_seq") - File.stubs(:directory?).returns(false) - @klass::HOME_SUBDIRS.each do |subdir| - FileUtils.expects(:mkdir_p).with(@env.home_path.join(subdir)).in_sequence(create_seq) - end - - @env.load_home_directory! - end - - should "not create directories if they exist" do - File.stubs(:directory?).returns(true) - FileUtils.expects(:mkdir_p).never - @env.load_home_directory! - end - end - - context "loading the UUID out from the persisted dotfile" do - setup do - @env = vagrant_env - end - - should "load all the VMs from the dotfile" do - @env.local_data[:active] = { "foo" => "bar", "bar" => "baz" } - - results = {} - @env.local_data[:active].each do |key, value| - vm = mock("vm#{key}") - Vagrant::VM.expects(:find).with(value, @env, key.to_sym).returns(vm) - results[key.to_sym] = vm - end - - returned = @env.load_vms! - - results.each do |key, value| - assert_equal value, returned[key] - end - end - - should "uuid should be nil if local data contains nothing" do - assert @env.local_data.empty? # sanity - @env.load_vms! - assert_nil @env.vm - end - end - end -end diff --git a/test/unit_legacy/vagrant/errors_test.rb b/test/unit_legacy/vagrant/errors_test.rb deleted file mode 100644 index ab885df4f67..00000000000 --- a/test/unit_legacy/vagrant/errors_test.rb +++ /dev/null @@ -1,42 +0,0 @@ -require "test_helper" - -class ErrorsTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Errors::VagrantError - @super = Class.new(@klass) { error_namespace("vagrant.test.errors") } - end - - should "set the given status code" do - klass = Class.new(@super) { status_code(4444) } - assert_equal 4444, klass.new.status_code - end - - should "raise an error if attempting to set the same status code twice" do - klass = Class.new(@super) { status_code(4445) } - - assert_raises(RuntimeError) { - Class.new(@super) { status_code(4445) } - } - end - - should "translate the given message if non-hash is given" do - klass = Class.new(@super) - assert_equal I18n.t("vagrant.test.errors.test_key"), klass.new("test_key").message - end - - should "use the alternate namespace if given" do - klass = Class.new(@super) - instance = klass.new(:_key => :test_key, :_namespace => "vagrant.test.alternate") - assert_equal I18n.t("vagrant.test.alternate.test_key"), instance.message - end - - should "use the translation from I18n if specified" do - klass = Class.new(@super) { error_key(:test_key) } - assert_equal I18n.t("vagrant.test.errors.test_key"), klass.new.message - end - - should "use the translation with the options specified if key given" do - klass = Class.new(@super) { error_key(:test_key_with_interpolation) } - assert_equal I18n.t("vagrant.test.errors.test_key_with_interpolation", :key => "yo"), klass.new(:key => "yo").message - end -end diff --git a/test/unit_legacy/vagrant/hosts/base_test.rb b/test/unit_legacy/vagrant/hosts/base_test.rb deleted file mode 100644 index ad0dc837ff9..00000000000 --- a/test/unit_legacy/vagrant/hosts/base_test.rb +++ /dev/null @@ -1,46 +0,0 @@ -require "test_helper" - -class BaseHostTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Hosts::Base - end - - context "class methods" do - context "loading" do - setup do - @env = vagrant_env - end - - should "return detected class if klass is nil" do - Vagrant::Util::Platform.stubs(:platform).returns("darwin") - result = @klass.load(@env, nil) - assert result.is_a?(Vagrant::Hosts::BSD) - end - - should "instantiate the given class" do - result = @klass.load(@env, Vagrant::Hosts::BSD) - assert result.is_a?(Vagrant::Hosts::BSD) - assert_equal @env, result.env - end - end - - context "detecting class" do - should "return the proper class" do - Vagrant::Util::Platform.stubs(:platform).returns("darwin10") - assert_equal Vagrant::Hosts::BSD, @klass.detect - end - - should "return nil if no class is detected" do - Vagrant::Util::Platform.stubs(:platform).returns("boo") - assert_nil @klass.detect - end - - should "return nil if an exception is raised" do - Vagrant::Util::Platform.stubs(:platform).returns("boo") - assert_nothing_raised { - assert_nil @klass.detect - } - end - end - end -end diff --git a/test/unit_legacy/vagrant/hosts/bsd_test.rb b/test/unit_legacy/vagrant/hosts/bsd_test.rb deleted file mode 100644 index 8e73d15c8a1..00000000000 --- a/test/unit_legacy/vagrant/hosts/bsd_test.rb +++ /dev/null @@ -1,53 +0,0 @@ -require "test_helper" - -class BSDHostTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Hosts::BSD - @env = vagrant_env - @instance = @klass.new(@env.vms.values.first.env) - end - - context "supporting nfs check" do - should "support NFS" do - @instance.expects(:system).returns(true) - assert @instance.nfs? - end - - should "not support NFS if nfsd is not found" do - @instance.expects(:system).returns(false) - assert !@instance.nfs? - end - - should "retry until a boolean is returned" do - seq = sequence("seq") - @instance.expects(:system).in_sequence(seq).raises(TypeError.new("foo")) - @instance.expects(:system).in_sequence(seq).returns(true) - assert @instance.nfs? - end - end - - context "nfs export" do - setup do - @instance.stubs(:system) - - @ip = "foo" - @folders = "bar" - end - - should "output the lines of the rendered template" do - output = %W[foo bar baz].join("\n") - Vagrant::Util::TemplateRenderer.expects(:render).with("nfs/exports", - :uuid => @instance.env.vm.uuid, - :ip => @ip, - :folders => @folders).returns(output) - - @instance.expects(:system).times(output.split("\n").length) - @instance.expects(:system).with("sudo nfsd restart") - @instance.nfs_export(@ip, @folders) - end - end - - context "nfs cleanup" do - # TODO: How to test all the system calls? - end -end diff --git a/test/unit_legacy/vagrant/hosts/linux_test.rb b/test/unit_legacy/vagrant/hosts/linux_test.rb deleted file mode 100644 index 5c1ff9a85c7..00000000000 --- a/test/unit_legacy/vagrant/hosts/linux_test.rb +++ /dev/null @@ -1,54 +0,0 @@ -require "test_helper" - -class LinuxHostTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Hosts::Linux - @env = vagrant_env - - @instance = @klass.new(@env.vms.values.first.env) - end - - context "supporting nfs check" do - should "support NFS" do - @instance.expects(:system).returns(true) - assert @instance.nfs? - end - - should "not support NFS if nfsd is not found" do - @instance.expects(:system).returns(false) - assert !@instance.nfs? - end - - should "retry until a boolean is returned" do - seq = sequence("seq") - @instance.expects(:system).in_sequence(seq).raises(TypeError.new("foo")) - @instance.expects(:system).in_sequence(seq).returns(true) - assert @instance.nfs? - end - end - - context "nfs export" do - setup do - @instance.stubs(:system) - - @ip = "foo" - @folders = "bar" - end - - should "output the lines of the rendered template" do - output = %W[foo bar baz].join("\n") - Vagrant::Util::TemplateRenderer.expects(:render).with("nfs/exports_linux", - :uuid => @instance.env.vm.uuid, - :ip => @ip, - :folders => @folders).returns(output) - - @instance.expects(:system).times(output.split("\n").length) - @instance.expects(:system).with("sudo /etc/init.d/nfs-kernel-server restart") - @instance.nfs_export(@ip, @folders) - end - end - - context "nfs cleanup" do - # TODO: How to test all the system calls? - end -end diff --git a/test/unit_legacy/vagrant/plugin_test.rb b/test/unit_legacy/vagrant/plugin_test.rb deleted file mode 100644 index 028e7279b22..00000000000 --- a/test/unit_legacy/vagrant/plugin_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "test_helper" - -class PluginTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Plugin - end - - # This is a pretty tough class to test. TODO. -end diff --git a/test/unit_legacy/vagrant/provisioners/base_test.rb b/test/unit_legacy/vagrant/provisioners/base_test.rb deleted file mode 100644 index 6dbe5198660..00000000000 --- a/test/unit_legacy/vagrant/provisioners/base_test.rb +++ /dev/null @@ -1,63 +0,0 @@ -require "test_helper" - -class BaseProvisionerTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Provisioners::Base - end - - should "include the util class so subclasses have access to it" do - assert Vagrant::Provisioners::Base.include?(Vagrant::Util) - end - - context "registering provisioners" do - teardown do - @klass.registered.delete(:zomg) - end - - should "not have unregistered provisioners" do - assert_nil @klass.registered[:foo] - end - - should "be able to register a provisioner" do - foo = Class.new(@klass) do - register :zomg - end - - assert_equal foo, @klass.registered[:zomg] - end - end - - context "base instance" do - setup do - @env = Vagrant::Action::Environment.new(vagrant_env) - @config = mock("config") - @base = Vagrant::Provisioners::Base.new(@env, @config) - end - - should "set the environment" do - assert_equal @env.env, @base.env - end - - should "return the VM which the provisioner is acting on" do - assert_equal @env.env.vm, @base.vm - end - - should "provide access to the config" do - assert_equal @config, @base.config - end - - should "implement provision! which does nothing" do - assert_nothing_raised do - assert @base.respond_to?(:provision!) - @base.provision! - end - end - - should "implement prepare which does nothing" do - assert_nothing_raised do - assert @base.respond_to?(:prepare) - @base.prepare - end - end - end -end diff --git a/test/unit_legacy/vagrant/provisioners/chef_client_test.rb b/test/unit_legacy/vagrant/provisioners/chef_client_test.rb deleted file mode 100644 index ac6721b93f2..00000000000 --- a/test/unit_legacy/vagrant/provisioners/chef_client_test.rb +++ /dev/null @@ -1,190 +0,0 @@ -require "test_helper" - -class ChefClientProvisionerTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Provisioners::ChefClient - - @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env) - - @config = @klass::Config.new - @action = @klass.new(@action_env, @config) - @env = @action.env - @vm = @action.vm - end - - context "config validation" do - setup do - @errors = Vagrant::Config::ErrorRecorder.new - - @config.run_list = ["foo"] - @config.chef_server_url = "foo" - @config.validation_key_path = "foo" - end - - should "be invalid if run list is empty" do - @config.run_list = [] - @config.validate(@errors) - assert !@errors.errors.empty? - end - - should "be invalid if run list is empty" do - @config.chef_server_url = nil - @config.validate(@errors) - assert !@errors.errors.empty? - end - - should "be invalid if run list is empty" do - @config.validation_key_path = nil - @config.validate(@errors) - assert !@errors.errors.empty? - end - end - - context "provisioning" do - should "run the proper sequence of methods in order" do - prov_seq = sequence("prov_seq") - @action.expects(:verify_binary).with("chef-client").once.in_sequence(prov_seq) - @action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq) - @action.expects(:create_client_key_folder).once.in_sequence(prov_seq) - @action.expects(:upload_validation_key).once.in_sequence(prov_seq) - @action.expects(:setup_json).once.in_sequence(prov_seq) - @action.expects(:setup_server_config).once.in_sequence(prov_seq) - @action.expects(:run_chef_client).once.in_sequence(prov_seq) - @action.provision! - end - end - - context "preparing" do - setup do - File.stubs(:file?).returns(true) - end - - should "not raise an exception if validation_key_path is set" do - @config.validation_key_path = "7" - @config.chef_server_url = "7" - - assert_nothing_raised { @action.prepare } - end - - should "raise an exception if validation_key_path is nil" do - @config.validation_key_path = nil - - assert_raises(Vagrant::Provisioners::Chef::ChefError) { - @action.prepare - } - end - - should "not raise an exception if validation_key_path does exist" do - @config.validation_key_path = vagrantfile(tmp_path) - @config.chef_server_url = "7" - - assert_nothing_raised { @action.prepare } - end - - should "raise an exception if validation_key_path doesn't exist" do - @config.validation_key_path = "7" - @config.chef_server_url = "7" - - File.expects(:file?).with(@action.validation_key_path).returns(false) - assert_raises(Vagrant::Provisioners::Chef::ChefError) { - @action.prepare - } - end - - should "not raise an exception if chef_server_url is set" do - @config.validation_key_path = vagrantfile(tmp_path) - @config.chef_server_url = "7" - - assert_nothing_raised { @action.prepare } - end - - should "raise an exception if chef_server_url is nil" do - @config.chef_server_url = nil - - assert_raises(Vagrant::Provisioners::Chef::ChefError) { - @action.prepare - } - end - end - - context "creating the client key folder" do - setup do - @raw_path = "/foo/bar/baz.pem" - @config.client_key_path = @raw_path - - @path = Pathname.new(@raw_path) - end - - should "create the folder using the dirname of the path" do - ssh = mock("ssh") - ssh.expects(:sudo!).with("mkdir -p #{@path.dirname}").once - @vm.ssh.expects(:execute).yields(ssh) - @action.create_client_key_folder - end - end - - context "uploading the validation key" do - should "upload the validation key to the provisioning path" do - @action.expects(:validation_key_path).once.returns("foo") - @action.expects(:guest_validation_key_path).once.returns("bar") - @vm.ssh.expects(:upload!).with("foo", "bar").once - @action.upload_validation_key - end - end - - context "the validation key path" do - should "expand the configured key path" do - result = mock("result") - File.expects(:expand_path).with(@config.validation_key_path, @env.root_path).once.returns(result) - assert_equal result, @action.validation_key_path - end - end - - context "the guest validation key path" do - should "be the provisioning path joined with validation.pem" do - result = mock("result") - File.expects(:join).with(@config.provisioning_path, "validation.pem").once.returns(result) - assert_equal result, @action.guest_validation_key_path - end - end - - context "generating and uploading chef client configuration file" do - setup do - @action.stubs(:guest_validation_key_path).returns("foo") - end - - should "call setup_config with proper variables" do - @action.expects(:setup_config).with("chef_server_client", "client.rb", { - :node_name => @config.node_name, - :chef_server_url => @config.chef_server_url, - :validation_client_name => @config.validation_client_name, - :validation_key => @action.guest_validation_key_path, - :client_key => @config.client_key_path, - :file_cache_path => @config.file_cache_path, - :file_backup_path => @config.file_backup_path, - :environment => @config.environment, - :encrypted_data_bag_secret => @config.encrypted_data_bag_secret - }) - - @action.setup_server_config - end - end - - context "running chef client" do - setup do - @ssh = mock("ssh") - @vm.ssh.stubs(:execute).yields(@ssh) - end - - should "run chef client" do - @ssh.expects(:sudo!).with("chef-client -c #{@config.provisioning_path}/client.rb -j #{@config.provisioning_path}/dna.json").once - @action.run_chef_client - end - - should "check the exit status if that is given" do - @ssh.stubs(:sudo!).yields(nil, :exit_status, :foo) - @ssh.expects(:check_exit_status).with(:foo, anything).once - @action.run_chef_client - end - end -end diff --git a/test/unit_legacy/vagrant/provisioners/chef_solo_test.rb b/test/unit_legacy/vagrant/provisioners/chef_solo_test.rb deleted file mode 100644 index e3533d52d4f..00000000000 --- a/test/unit_legacy/vagrant/provisioners/chef_solo_test.rb +++ /dev/null @@ -1,115 +0,0 @@ -require "test_helper" - -class ChefSoloProvisionerTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Provisioners::ChefSolo - - @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env) - - @config = @klass::Config.new - @action = @klass.new(@action_env, @config) - @env = @action.env - @vm = @action.vm - end - - context "config validation" do - setup do - @errors = Vagrant::Config::ErrorRecorder.new - @config.run_list = ["foo"] - @config.cookbooks_path = "cookbooks" - end - - should "be invalid if run list is empty" do - @config.run_list = [] - @config.validate(@errors) - assert !@errors.errors.empty? - end - - should "be invalid if cookbooks path is empty" do - @config.cookbooks_path = nil - @config.validate(@errors) - assert !@errors.errors.empty? - end - end - - context "provisioning" do - should "run the proper sequence of methods in order" do - prov_seq = sequence("prov_seq") - @action.expects(:verify_binary).with("chef-solo").once.in_sequence(prov_seq) - @action.expects(:chown_provisioning_folder).once.in_sequence(prov_seq) - @action.expects(:setup_json).once.in_sequence(prov_seq) - @action.expects(:setup_solo_config).once.in_sequence(prov_seq) - @action.expects(:run_chef_solo).once.in_sequence(prov_seq) - @action.provision! - end - end - - context "creating expanded folder sets" do - should "expand VM folders properly" do - assert_equal [[:vm, nil, "/foo"]], @action.expanded_folders([:vm, "/foo"]) - end - - should "expand host folders properly" do - path = "foo" - local_path = File.expand_path(path, @env.root_path) - remote_path = "#{@action.config.provisioning_path}/chef-solo-1" - assert_equal [[:host, local_path, remote_path]], @action.expanded_folders([:host, path]) - end - - should "share roles and cookbooks in different folders" do - local_roles_path = File.expand_path('roles',@env.root_path) - local_cookbooks_path = File.expand_path('cookbooks',@env.root_path) - remote_roles_path = @action.expanded_folders([:host,local_roles_path])[0][2] - remote_cookbooks_path = @action.expanded_folders([:host,local_cookbooks_path])[0][2] - assert_not_equal remote_roles_path, remote_cookbooks_path - end - end - - context "guest paths" do - should "extract the parts properly" do - structure = [[1,2,3],[1,2,3]] - assert_equal [3,3], @action.guest_paths(structure) - end - end - - context "generating and uploading chef solo configuration file" do - setup do - @vm.ssh.stubs(:upload!) - - @config.recipe_url = "foo/bar/baz" - @action.prepare - end - - should "call setup_config with proper variables" do - @action.expects(:setup_config).with("chef_solo_solo", "solo.rb", { - :node_name => @config.node_name, - :provisioning_path => @config.provisioning_path, - :cookbooks_path => @action.guest_paths(@action.cookbook_folders), - :recipe_url => @config.recipe_url, - :roles_path => @action.guest_paths(@action.role_folders).first, - :data_bags_path => @action.guest_paths(@action.data_bags_folders).first, - :encrypted_data_bag_secret => @config.encrypted_data_bag_secret - }) - - @action.setup_solo_config - end - end - - context "running chef solo" do - setup do - @ssh = mock("ssh") - @vm.ssh.stubs(:execute).yields(@ssh) - end - - should "run chef solo" do - @ssh.expects(:sudo!).with("chef-solo -c #{@config.provisioning_path}/solo.rb -j #{@config.provisioning_path}/dna.json").once - @action.run_chef_solo - end - - should "check the exit status if that is given" do - @ssh.stubs(:sudo!).yields(nil, :exit_status, :foo) - @ssh.expects(:check_exit_status).with(:foo, anything).once - @action.run_chef_solo - end - end -end diff --git a/test/unit_legacy/vagrant/provisioners/chef_test.rb b/test/unit_legacy/vagrant/provisioners/chef_test.rb deleted file mode 100644 index b54cbdb20a3..00000000000 --- a/test/unit_legacy/vagrant/provisioners/chef_test.rb +++ /dev/null @@ -1,209 +0,0 @@ -require "test_helper" - -class ChefProvisionerTest < Test::Unit::TestCase - setup do - @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env) - - @klass = Vagrant::Provisioners::Chef - @config = @klass::Config.new - @action = @klass.new(@action_env, @config) - @env = @action.env - @vm = @action.vm - end - - context "preparing" do - should "error the environment" do - assert_raises(@klass::ChefError) { - @action.prepare - } - end - end - - context "config" do - should "not include the 'json' key in the config dump" do - result = @config.to_json - assert result !~ /"json":/ - end - - should "not include the 'run_list' key in json if not accessed" do - result = @config.merged_json - assert !result.has_key?(:run_list) - end - - should "include the 'run_list' key in json if it is set" do - @config.run_list << "foo" - result = @config.merged_json - assert result.has_key?(:run_list) - end - - should "provide accessors to the run list" do - @config.run_list << "foo" - assert !@config.run_list.empty? - assert_equal ["foo"], @config.run_list - end - - should "provide a writer for the run list" do - data = mock("data") - - assert_nothing_raised { - @config.run_list = data - assert_equal data, @config.run_list - } - end - - should "have an empty run list to begin with" do - assert @config.run_list.empty? - end - - should "add a recipe to the run list" do - @config.add_recipe("foo") - assert_equal "recipe[foo]", @config.run_list[0] - end - - should "not wrap the recipe in 'recipe[]' if it was in the name" do - @config.add_recipe("recipe[foo]") - assert_equal "recipe[foo]", @config.run_list[0] - end - - should "add a role to the run list" do - @config.add_role("user") - assert_equal "role[user]", @config.run_list[0] - end - - should "not wrap the role in 'role[]' if it was in the name" do - @config.add_role("role[user]") - assert_equal "role[user]", @config.run_list[0] - end - end - - context "verifying binary" do - setup do - @ssh = mock("ssh") - @vm.ssh.stubs(:execute).yields(@ssh) - end - - should "verify binary exists" do - binary = "foo" - @ssh.expects(:sudo!).with("which #{binary}", anything) - @action.verify_binary(binary) - end - end - - context "chef binary path" do - should "return just the binary if no binary path is set" do - @config.binary_path = nil - assert_equal "foo", @action.chef_binary_path("foo") - end - - should "return the joined binary path and binary if set" do - @config.binary_path = "/foo" - assert_equal File.join(@config.binary_path, "bar"), @action.chef_binary_path("bar") - end - end - - context "permissions on provisioning folder" do - should "create and chown the folder to the ssh user" do - ssh_seq = sequence("ssh_seq") - ssh = mock("ssh") - ssh.expects(:sudo!).with("mkdir -p #{@config.provisioning_path}").once.in_sequence(ssh_seq) - ssh.expects(:sudo!).with("chown #{@env.config.ssh.username} #{@config.provisioning_path}").once.in_sequence(ssh_seq) - @vm.ssh.expects(:execute).yields(ssh) - @action.chown_provisioning_folder - end - end - - context "generating and uploading chef configuration file" do - setup do - @vm.ssh.stubs(:upload!) - - @template = "template" - @filename = "foo.rb" - - Vagrant::Util::TemplateRenderer.stubs(:render).returns("foo") - end - - should "render and upload file" do - template_data = mock("data") - string_io = mock("string_io") - Vagrant::Util::TemplateRenderer.expects(:render).with(@template, anything).returns(template_data) - StringIO.expects(:new).with(template_data).returns(string_io) - File.expects(:join).with(@config.provisioning_path, @filename).once.returns("bar") - @vm.ssh.expects(:upload!).with(string_io, "bar") - - @action.setup_config(@template, @filename, {}) - end - - should "provide log level by default" do - Vagrant::Util::TemplateRenderer.expects(:render).returns("foo").with() do |template, vars| - assert vars.has_key?(:log_level) - assert_equal @config.log_level.to_sym, vars[:log_level] - true - end - - @action.setup_config(@template, @filename, {}) - end - - should "allow custom template variables" do - custom = { - :foo => "bar", - :int => 7 - } - - Vagrant::Util::TemplateRenderer.expects(:render).returns("foo").with() do |template, vars| - custom.each do |key, value| - assert vars.has_key?(key) - assert_equal value, vars[key] - end - - true - end - - @action.setup_config(@template, @filename, custom) - end - end - - context "generating and uploading json" do - def assert_json - @vm.ssh.expects(:upload!).with do |json, path| - data = JSON.parse(json.read) - yield data - true - end - - @action.setup_json - end - - should "merge in the extra json specified in the config" do - @config.json = { :foo => "BAR" } - assert_json do |data| - assert_equal "BAR", data["foo"] - end - end - - should "add the directory as a special case to the JSON" do - assert_json do |data| - assert_equal @env.config.vm.shared_folders["v-root"][:guestpath], data["vagrant"]["directory"] - end - end - - should "not add the directory if the 'v-root' shared folder doesn't exist" do - @env.config.vm.shared_folders.delete("v-root") - assert_json do |data| - assert !data["vagrant"].has_key?("directory") - end - end - - should "add the config to the JSON" do - assert_json do |data| - assert_equal @env.config.ssh.username, data["vagrant"]["config"]["ssh"]["username"] - end - end - - should "upload a StringIO to dna.json" do - StringIO.expects(:new).with(anything).returns("bar") - File.expects(:join).with(@config.provisioning_path, "dna.json").once.returns("baz") - @vm.ssh.expects(:upload!).with("bar", "baz").once - @action.setup_json - end - end -end diff --git a/test/unit_legacy/vagrant/provisioners/puppet_server_test.rb b/test/unit_legacy/vagrant/provisioners/puppet_server_test.rb deleted file mode 100644 index 4bbdf924539..00000000000 --- a/test/unit_legacy/vagrant/provisioners/puppet_server_test.rb +++ /dev/null @@ -1,68 +0,0 @@ -require "test_helper" - -class PuppetServerProvisionerTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Provisioners::PuppetServer - - @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env) - - @config = @klass::Config.new - @action = @klass.new(@action_env, @config) - @env = @action.env - @vm = @action.vm - end - - context "provisioning" do - should "run the proper sequence of methods in order" do - prov_seq = sequence("prov_seq") - @action.expects(:verify_binary).with("puppetd").once.in_sequence(prov_seq) - @action.expects(:run_puppetd_client).once.in_sequence(prov_seq) - @action.provision! - end - end - - context "verifying binary" do - setup do - @ssh = mock("ssh") - @shell = mock("shell") - @vm.ssh.stubs(:execute).yields(@ssh) - end - - should "verify binary exists" do - binary = "foo" - @ssh.expects(:sudo!).with("which #{binary}", anything) - @action.verify_binary(binary) - end - end - - context "running puppetd client" do - setup do - @cn = "puppet_node" - @ssh = mock("ssh") - @vm.ssh.stubs(:execute).yields(@ssh) - end - - should "run the puppetd client" do - @ssh.expects(:sudo!).with("puppetd --server #{@config.puppet_server} --certname #{@cn}").once - @action.run_puppetd_client - end - - should "run puppetd with given options when given as an array" do - @config.options = ["--modulepath", "modules", "--verbose"] - @ssh.expects(:sudo!).with("puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once - @action.run_puppetd_client - end - - should "run puppetd with the options when given as a string" do - @config.options = "--modulepath modules --verbose" - @ssh.expects(:sudo!).with("puppetd --modulepath modules --verbose --server #{@config.puppet_server} --certname #{@cn}").once - @action.run_puppetd_client - end - - should "check the exit status if that is given" do - @ssh.stubs(:sudo!).yields(nil, :exit_status, :foo) - @ssh.expects(:check_exit_status).with(:foo, anything).once - @action.run_puppetd_client - end - end -end diff --git a/test/unit_legacy/vagrant/provisioners/puppet_test.rb b/test/unit_legacy/vagrant/provisioners/puppet_test.rb deleted file mode 100644 index 5817115c416..00000000000 --- a/test/unit_legacy/vagrant/provisioners/puppet_test.rb +++ /dev/null @@ -1,182 +0,0 @@ -require "test_helper" - -class PuppetProvisionerTest < Test::Unit::TestCase - setup do - clean_paths - - @klass = Vagrant::Provisioners::Puppet - - @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env) - - @config = @klass::Config.new - @config.top = Vagrant::Config::Top.new(@action_env.env) - @config.top.vm.box = "foo" - @action = @klass.new(@action_env, @config) - @env = @action.env - @vm = @action.vm - end - - context "config" do - setup do - @errors = Vagrant::Config::ErrorRecorder.new - - # Set a box - @config.top.vm.box = "foo" - - # Start in a valid state (verified by the first test) - @config.expanded_manifests_path.mkdir - File.open(@config.expanded_manifests_path.join(@config.computed_manifest_file), "w") { |f| f.puts "HELLO" } - end - - should "expand the manifest path relative to the root path" do - assert_equal File.expand_path(@config.manifests_path, @env.root_path), @config.expanded_manifests_path.to_s - end - - should "default the manifest file to the box name" do - assert_equal "#{@config.top.vm.box}.pp", @config.computed_manifest_file - end - - should "use the custom manifest file if set" do - @config.manifest_file = "woot.pp" - assert_equal "woot.pp", @config.computed_manifest_file - end - - should "return an empty array if no module path is set" do - @config.module_path = nil - assert_equal [], @config.expanded_module_paths - end - - should "return array of module paths expanded relative to root path" do - @config.module_path = "foo" - - result = @config.expanded_module_paths - assert result.is_a?(Array) - assert_equal 1, result.length - assert_equal File.expand_path(@config.module_path, @env.root_path), result[0].to_s - end - - should "be valid" do - @config.validate(@errors) - assert @errors.errors.empty? - end - - should "be invalid if the manifests path doesn't exist" do - @config.expanded_manifests_path.rmtree - @config.validate(@errors) - assert !@errors.errors.empty? - end - - should "be invalid if a custom manifests path doesn't exist" do - @config.manifests_path = "dont_exist" - @config.validate(@errors) - assert !@errors.errors.empty? - end - - should "be invalid if the manifest file doesn't exist" do - @config.expanded_manifests_path.join(@config.computed_manifest_file).unlink - @config.validate(@errors) - assert !@errors.errors.empty? - end - - should "be invalid if a specified module path doesn't exist" do - @config.module_path = "foo" - @config.validate(@errors) - assert !@errors.errors.empty? - end - - should "be valid if all module paths exist" do - @config.module_path = "foo" - @config.expanded_module_paths.first.mkdir - @config.validate(@errors) - assert @errors.errors.empty? - end - end - - context "preparing" do - should "share manifests" do - pre_seq = sequence("prepare") - @action.expects(:set_module_paths).once.in_sequence(pre_seq) - @action.expects(:share_manifests).once.in_sequence(pre_seq) - @action.expects(:share_module_paths).once.in_sequence(pre_seq) - @action.prepare - end - end - - context "provisioning" do - should "run the proper sequence of methods in order" do - prov_seq = sequence("prov_seq") - @action.expects(:verify_binary).with("puppet").once.in_sequence(prov_seq) - @action.expects(:run_puppet_client).once.in_sequence(prov_seq) - @action.provision! - end - end - - context "share manifests folder" do - should "share manifest folder" do - @env.config.vm.expects(:share_folder).with("manifests", @action.manifests_guest_path, @config.expanded_manifests_path) - @action.share_manifests - end - end - - context "sharing module paths" do - should "share all the module paths" do - @config.module_path = ["foo", "bar"] - @config.expanded_module_paths.each_with_index do |path, i| - @env.config.vm.expects(:share_folder).with("v-pp-m#{i}", File.join(@config.pp_path, "modules-#{i}"), path) - end - - @action.set_module_paths - @action.share_module_paths - end - end - - context "verifying binary" do - setup do - @ssh = mock("ssh") - @vm.ssh.stubs(:execute).yields(@ssh) - end - - should "verify binary exists" do - binary = "foo" - @ssh.expects(:sudo!).with("which #{binary}", anything) - @action.verify_binary(binary) - end - end - - context "running puppet client" do - setup do - @ssh = mock("ssh") - @vm.ssh.stubs(:execute).yields(@ssh) - @action.set_module_paths - end - - def expect_puppet_command(command) - @ssh.expects(:sudo!).with(["cd #{@action.manifests_guest_path}", command]) - end - - should "cd into the pp_path directory and run puppet" do - expect_puppet_command("puppet apply #{@config.computed_manifest_file}") - @action.run_puppet_client - end - - should "cd into the pp_path directory and run puppet with given options when given as an array" do - @config.options = ["--modulepath", "modules", "--verbose"] - expect_puppet_command("puppet apply --modulepath modules --verbose #{@config.computed_manifest_file}") - @action.run_puppet_client - end - - should "cd into the pp_path directory and run puppet with the options when given as a string" do - @config.options = "--modulepath modules --verbose" - expect_puppet_command("puppet apply --modulepath modules --verbose #{@config.computed_manifest_file}") - @action.run_puppet_client - end - - should "cd into the pp_path and run puppet with module paths if set" do - @config.module_path = "foo" - expect_puppet_command("puppet apply --modulepath '#{File.join(@config.pp_path, 'modules-0')}' #{@config.computed_manifest_file}") - - @action.set_module_paths - @action.run_puppet_client - end - end -end diff --git a/test/unit_legacy/vagrant/provisioners/shell_test.rb b/test/unit_legacy/vagrant/provisioners/shell_test.rb deleted file mode 100644 index af2ac090b5a..00000000000 --- a/test/unit_legacy/vagrant/provisioners/shell_test.rb +++ /dev/null @@ -1,79 +0,0 @@ -require "test_helper" - -class ShellProvisionerTest < Test::Unit::TestCase - setup do - clean_paths - - @klass = Vagrant::Provisioners::Shell - @action_env = Vagrant::Action::Environment.new(vagrant_env.vms[:default].env) - @config = @klass::Config.new - @config.top = Vagrant::Config::Top.new(@action_env.env) - @action = @klass.new(@action_env, @config) - - @config.path = "foo" - end - - context "config" do - setup do - @errors = Vagrant::Config::ErrorRecorder.new - - # Start in a valid state (verified by a test below) - @config.path = "foo" - File.open(@config.expanded_path, "w") { |f| f.puts "HELLO" } - end - - should "be valid" do - @config.validate(@errors) - assert @errors.errors.empty? - end - - should "be invalid if the path is not set" do - @config.path = nil - - @config.validate(@errors) - assert !@errors.errors.empty? - end - - should "be invalid if the path does not exist" do - @config.path = "bar" - - @config.validate(@errors) - assert !@errors.errors.empty? - end - - should "be invalid if the upload path is not set" do - @config.upload_path = nil - - @config.validate(@errors) - assert !@errors.errors.empty? - end - end - - context "provisioning" do - setup do - @ssh = mock("ssh") - @action.vm.ssh.stubs(:execute).yields(@ssh) - end - - should "upload the file, chmod, then execute it" do - commands = ["chmod +x #{@config.upload_path}", @config.upload_path] - - p_seq = sequence("provisioning") - @action.vm.ssh.expects(:upload!).with(@config.expanded_path.to_s, @config.upload_path).in_sequence(p_seq) - @ssh.expects(:sudo!).with(commands).in_sequence(p_seq) - - @action.provision! - end - - should "append arguments if provided" do - @config.args = "foo bar baz" - commands = ["chmod +x #{@config.upload_path}", "#{@config.upload_path} #{@config.args}"] - - p_seq = sequence("provisioning") - @action.vm.ssh.expects(:upload!).with(@config.expanded_path.to_s, @config.upload_path).in_sequence(p_seq) - @ssh.expects(:sudo!).with(commands).in_sequence(p_seq) - - @action.provision! - end - end -end diff --git a/test/unit_legacy/vagrant/ssh/session_test.rb b/test/unit_legacy/vagrant/ssh/session_test.rb deleted file mode 100644 index 06b1e7d12bf..00000000000 --- a/test/unit_legacy/vagrant/ssh/session_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require "test_helper" - -class SshSessionTest < Test::Unit::TestCase - setup do - @session = mock("session") - @env = vagrant_env - - @klass = Vagrant::SSH::Session - @instance = @klass.new(@session, @env) - end - - context "exec!" do - should "retry max_tries times" do - @session.expects(:open_channel).times(@env.config.ssh.max_tries).raises(IOError) - assert_raises(IOError) { - @instance.exec!("foo") - } - end - end - - context "checking exit status" do - should "raise an ActionException if its non-zero" do - assert_raises(Vagrant::Errors::VagrantError) { - @instance.check_exit_status(1, "foo") - } - end - - should "raise the given exception if specified" do - assert_raises(Vagrant::Errors::BaseVMNotFound) { - @instance.check_exit_status(1, "foo", :_error_class => Vagrant::Errors::BaseVMNotFound) - } - end - - should "raise nothing if its zero" do - assert_nothing_raised { - @instance.check_exit_status(0, "foo") - } - end - end -end diff --git a/test/unit_legacy/vagrant/ssh_test.rb b/test/unit_legacy/vagrant/ssh_test.rb deleted file mode 100644 index a5d566da002..00000000000 --- a/test/unit_legacy/vagrant/ssh_test.rb +++ /dev/null @@ -1,304 +0,0 @@ -require "test_helper" - -class SshTest < Test::Unit::TestCase - def mock_ssh - @env = vagrant_env.vms[:default].env - @network_adapters = [] - @vm = mock("vm") - @vm.stubs(:network_adapters).returns(@network_adapters) - @env.vm.stubs(:vm).returns(@vm) - - @ssh = Vagrant::SSH.new(@env) - @session = mock("session") - end - - setup do - VirtualBox.stubs(:version).returns("4.1.0") - end - - context "connecting to external SSH" do - setup do - mock_ssh - @ssh.stubs(:check_key_permissions) - @ssh.stubs(:port).returns(2222) - @ssh.stubs(:safe_exec) - Kernel.stubs(:system).returns(true) - end - - should "raise an exception if SSH is not found" do - Kernel.stubs(:system).returns(false) - Kernel.expects(:system).returns(false).with() do |command| - assert command =~ /^which ssh/ - true - end - - assert_raises(Vagrant::Errors::SSHUnavailable) { - @ssh.connect - } - end - - should "check key permissions prior to exec" do - exec_seq = sequence("exec_seq") - @ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(exec_seq) - @ssh.expects(:safe_exec).in_sequence(exec_seq) - @ssh.connect - end - - should "call exec with defaults when no options are supplied" do - ssh_exec_expect(@ssh.port, - @env.config.ssh.private_key_path, - @env.config.ssh.username, - @env.config.ssh.host) - @ssh.connect - end - - should "call exec with supplied params" do - args = {:username => 'bar', :private_key_path => 'baz', :host => 'bak'} - ssh_exec_expect(@ssh.port, args[:private_key_path], args[:username], args[:host]) - @ssh.connect(args) - end - - should "add forward agent option if enabled" do - @env.config.ssh.forward_agent = true - ssh_exec_expect(@ssh.port, - @env.config.ssh.private_key_path, - @env.config.ssh.username, - @env.config.ssh.host) do |args| - assert args =~ /-o ForwardAgent=yes/ - end - @ssh.connect - end - - should "add forward X11 option if enabled" do - @env.config.ssh.forward_x11 = true - ssh_exec_expect(@ssh.port, - @env.config.ssh.private_key_path, - @env.config.ssh.username, - @env.config.ssh.host) do |args| - assert args =~ /-o ForwardX11=yes/ - end - @ssh.connect - end - - context "checking windows" do - should "error and exit if the platform is windows" do - Vagrant::Util::Platform.stubs(:windows?).returns(true) - assert_raises(Vagrant::Errors::SSHUnavailableWindows) { @ssh.connect } - end - - should "not error and exit if the platform is anything other that windows" do - Vagrant::Util::Platform.stubs(:windows?).returns(false) - assert_nothing_raised { @ssh.connect } - end - end - - def ssh_exec_expect(port, key_path, uname, host) - @ssh.expects(:safe_exec).with() do |arg| - assert arg =~ /^ssh/, "ssh command expected" - assert arg =~ /-p #{port}/, "-p #{port} expected" - assert arg =~ /-i #{key_path}/, "-i #{key_path} expected" - assert arg =~ /#{uname}@#{host}/, "#{uname}@{host} expected" - yield arg if block_given? - true - end - end - end - - context "executing ssh commands" do - setup do - mock_ssh - @ssh.stubs(:check_key_permissions) - @ssh.stubs(:port).returns(80) - end - - should "check key permissions then attempt to start connection" do - seq = sequence("seq") - @ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(seq) - Net::SSH.expects(:start).once.in_sequence(seq) - @ssh.execute - end - - should "call net::ssh.start with the proper names" do - Net::SSH.expects(:start).once.with() do |host, username, opts| - assert_equal @env.config.ssh.host, host - assert_equal @env.config.ssh.username, username - assert_equal @ssh.port, opts[:port] - assert_equal [@env.config.ssh.private_key_path], opts[:keys] - assert opts[:keys_only] - true - end - @ssh.execute - end - - should "forward agent if configured" do - @env.config.ssh.forward_agent = true - Net::SSH.expects(:start).once.with() do |host, username, opts| - assert opts[:forward_agent] - true - end - - @ssh.execute - end - - should "use custom host if set" do - @env.config.ssh.host = "foo" - Net::SSH.expects(:start).with(@env.config.ssh.host, @env.config.ssh.username, anything).once - @ssh.execute - end - - should "yield an SSH session object" do - raw = mock("raw") - Net::SSH.expects(:start).returns(raw) - @ssh.execute do |ssh| - assert ssh.is_a?(Vagrant::SSH::Session) - assert_equal raw, ssh.session - end - end - end - - context "SCPing files to the remote host" do - setup do - mock_ssh - end - - should "use Vagrant::SSH execute to setup an SCP connection and upload" do - scp = mock("scp") - ssh = mock("ssh") - sess = mock("session") - ssh.stubs(:session).returns(sess) - scp.expects(:upload!).with("foo", "bar").once - Net::SCP.expects(:new).with(ssh.session).returns(scp).once - @ssh.expects(:execute).yields(ssh).once - @ssh.upload!("foo", "bar") - end - end - - context "checking if host is up" do - setup do - mock_ssh - @ssh.stubs(:check_key_permissions) - @ssh.stubs(:port).returns(2222) - @session.stubs(:exec!).returns("hello\n") - end - - should "return false if SSH connection times out" do - @env.config.ssh.timeout = 0.5 - - Net::SSH.stubs(:start).with() do - # Sleep here to artificially fake timeout - sleep 1 - true - end - - assert !@ssh.up? - end - - should "return false if the connection is refused" do - Net::SSH.expects(:start).times(@env.config.ssh.max_tries).raises(Errno::ECONNREFUSED) - assert_nothing_raised { - assert !@ssh.up? - } - end - - should "specify the timeout as an option to execute" do - @ssh.expects(:execute).yields(@session).with() do |opts| - assert_equal @env.config.ssh.timeout, opts[:timeout] - true - end - - assert @ssh.up? - end - - should "error and exit if a Net::SSH::AuthenticationFailed is raised" do - @ssh.expects(:execute).raises(Net::SSH::AuthenticationFailed) - assert_raises(Vagrant::Errors::SSHAuthenticationFailed) { @ssh.up? } - end - - should "only get the port once (in the main thread)" do - @ssh.expects(:port).once.returns(2222) - @ssh.up? - end - end - - context "getting the ssh port" do - setup do - mock_ssh - end - - should "return the port given in options if it exists" do - assert_equal "47", @ssh.port({ :port => "47" }) - end - end - - context "checking key permissions" do - setup do - mock_ssh - @ssh.stubs(:file_perms) - - @key_path = "foo" - - - @stat = mock("stat") - @stat.stubs(:owned?).returns(true) - File.stubs(:stat).returns(@stat) - - Vagrant::Util::Platform.stubs(:windows?).returns(false) - end - - should "do nothing if on windows" do - Vagrant::Util::Platform.stubs(:windows?).returns(true) - File.expects(:stat).never - @ssh.check_key_permissions(@key_path) - end - - should "do nothing if the user is not the owner" do - @stat.expects(:owned?).returns(false) - File.expects(:chmod).never - @ssh.check_key_permissions(@key_path) - end - - should "do nothing if the file perms equal 600" do - @ssh.expects(:file_perms).with(@key_path).returns("600") - File.expects(:chmod).never - @ssh.check_key_permissions(@key_path) - end - - should "chmod the file if the file perms aren't 600" do - perm_sequence = sequence("perm_seq") - @ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence) - File.expects(:chmod).with(0600, @key_path).once.in_sequence(perm_sequence) - @ssh.expects(:file_perms).returns("600").in_sequence(perm_sequence) - assert_nothing_raised { @ssh.check_key_permissions(@key_path) } - end - - should "error and exit if the resulting chmod doesn't work" do - perm_sequence = sequence("perm_seq") - @ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence) - File.expects(:chmod).with(0600, @key_path).once.in_sequence(perm_sequence) - @ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence) - assert_raises(Vagrant::Errors::SSHKeyBadPermissions) { @ssh.check_key_permissions(@key_path) } - end - - should "error and exit if a bad file perm is raised" do - @ssh.expects(:file_perms).with(@key_path).returns("900") - File.expects(:chmod).raises(Errno::EPERM) - assert_raises(Vagrant::Errors::SSHKeyBadPermissions) { @ssh.check_key_permissions(@key_path) } - end - end - - context "getting file permissions" do - setup do - mock_ssh - end - - should "return the last 3 characters of the file mode" do - path = "foo" - mode = "10000foo" - stat = mock("stat") - File.expects(:stat).with(path).returns(stat) - stat.expects(:mode).returns(mode) - @ssh.expects(:sprintf).with("%o", mode).returns(mode) - assert_equal path, @ssh.file_perms(path) - end - end -end diff --git a/test/unit_legacy/vagrant/systems/base_test.rb b/test/unit_legacy/vagrant/systems/base_test.rb deleted file mode 100644 index 9ff07f21a40..00000000000 --- a/test/unit_legacy/vagrant/systems/base_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "test_helper" - -class BaseSystemTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Systems::Base - - @vm = mock("vm") - @instance = @klass.new(@vm) - end - - should "provide access to the VM" do - assert_equal @vm, @instance.vm - end - - should "error on preparing host only network" do - assert_raises(@klass::BaseError) { @instance.prepare_host_only_network } - end -end diff --git a/test/unit_legacy/vagrant/systems/linux_test.rb b/test/unit_legacy/vagrant/systems/linux_test.rb deleted file mode 100644 index 6df77f823b4..00000000000 --- a/test/unit_legacy/vagrant/systems/linux_test.rb +++ /dev/null @@ -1,104 +0,0 @@ -require "test_helper" - -class LinuxSystemTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Systems::Linux - @ssh = mock("ssh") - @mock_env = vagrant_env - @vm = mock("vm") - @vm.stubs(:env).returns(@mock_env) - @instance = @klass.new(@vm) - end - - context "halting" do - setup do - @ssh_session = mock("ssh_session") - @ssh.stubs(:execute).yields(@ssh_session) - @vm.stubs(:ssh).returns(@ssh) - - @real_vm = mock("real_vm") - @real_vm.stubs(:state).returns(:powered_off) - @vm.stubs(:vm).returns(@real_vm) - end - - should "execute halt via SSH" do - @ssh_session.expects(:exec!).with("sudo halt").once - @instance.halt - end - end - - context "mounting shared folders" do - setup do - @name = "foo" - @guestpath = "/bar" - @owner = "owner" - @group = "group" - end - - should "create the dir, mount the folder, then set permissions" do - mount_seq = sequence("mount_seq") - @ssh.expects(:exec!).with("sudo mkdir -p #{@guestpath}").in_sequence(mount_seq) - @instance.expects(:mount_folder).with(@ssh, @name, @guestpath, @owner, @group).in_sequence(mount_seq) - @ssh.expects(:exec!).with("sudo chown `id -u #{@owner}`:`id -g #{@group}` #{@guestpath}").in_sequence(mount_seq) - - @instance.mount_shared_folder(@ssh, @name, @guestpath, @owner, @group) - end - end - - #------------------------------------------------------------------- - # "Private" methods tests - #------------------------------------------------------------------- - context "mounting the main folder" do - setup do - @name = "foo" - @guestpath = "bar" - @owner = "owner" - @group = "group" - @sleeptime = 0 - @limit = 10 - - @success_return = false - end - - def mount_folder - @instance.mount_folder(@ssh, @name, @guestpath, @owner, @group, @sleeptime) - end - - should "execute the proper mount command" do - @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=`id -u #{@owner}`,gid=`id -g #{@group}` #{@name} #{@guestpath}").returns(@success_return) - mount_folder - end - - should "test type of text and text string to detect error" do - data = mock("data") - data.expects(:[]=).with(:result, !@success_return) - - @ssh.expects(:exec!).yields(data, :stderr, "No such device").returns(@success_return) - mount_folder - end - - should "test type of text and test string to detect success" do - data = mock("data") - data.expects(:[]=).with(:result, @success_return) - - @ssh.expects(:exec!).yields(data, :stdout, "Nothing such device").returns(@success_return) - mount_folder - end - - should "raise an ActionException if the command fails constantly" do - @ssh.expects(:exec!).times(@limit).returns(!@success_return) - - assert_raises(Vagrant::Systems::Linux::LinuxError) { - mount_folder - } - end - - should "not raise any exception if the command succeeded" do - @ssh.expects(:exec!).once.returns(@success_return) - - assert_nothing_raised { - mount_folder - } - end - end -end diff --git a/test/unit_legacy/vagrant/util/busy_test.rb b/test/unit_legacy/vagrant/util/busy_test.rb deleted file mode 100644 index 0490f683dfa..00000000000 --- a/test/unit_legacy/vagrant/util/busy_test.rb +++ /dev/null @@ -1,106 +0,0 @@ -require "test_helper" - -class BusyUtilTest < Test::Unit::TestCase - setup do - @klass = Vagrant::Util::Busy - end - - context "registering" do - setup do - @callback = lambda { puts "FOO" } - Signal.stubs(:trap) - end - - teardown do - @klass.registered.clear - end - - should "trap the signal on the first registration" do - Signal.expects(:trap).with("INT").once - @klass.register(@callback) - @klass.register(lambda { puts "BAR" }) - end - - should "not register the same callback multiple times" do - @klass.register(@callback) - @klass.register(@callback) - @klass.register(@callback) - assert_equal 1, @klass.registered.length - assert_equal @callback, @klass.registered.first - end - end - - context "unregistering" do - setup do - Signal.stubs(:trap) - - @callback = lambda { puts "FOO" } - end - - teardown do - @klass.registered.clear - end - - should "remove the callback and set the trap to DEFAULT when removing final" do - @klass.register(@callback) - Signal.expects(:trap).with("INT", "DEFAULT").once - @klass.unregister(@callback) - assert @klass.registered.empty? - end - - should "not reset signal trap if not final callback" do - @klass.register(@callback) - @klass.register(lambda { puts "BAR" }) - Signal.expects(:trap).never - @klass.unregister(@callback) - end - end - - context "marking for busy" do - setup do - @callback = lambda { "foo" } - end - - should "register, call the block, then unregister" do - waiter = mock("waiting") - proc = lambda { waiter.ping! } - - seq = sequence('seq') - @klass.expects(:register).with(@callback).in_sequence(seq) - waiter.expects(:ping!).in_sequence(seq) - @klass.expects(:unregister).with(@callback).in_sequence(seq) - - @klass.busy(@callback, &proc) - end - - should "unregister callback even if block raises exception" do - waiter = mock("waiting") - proc = lambda { waiter.ping! } - - seq = sequence('seq') - @klass.expects(:register).with(@callback).in_sequence(seq) - waiter.expects(:ping!).raises(Exception.new("uh oh!")).in_sequence(seq) - @klass.expects(:unregister).with(@callback).in_sequence(seq) - - assert_raises(Exception) { @klass.busy(@callback, &proc) } - end - end - - context "firing callbacks" do - setup do - Signal.stubs(:trap) - end - - teardown do - @klass.registered.clear - end - - should "just call the registered callbacks" do - waiting = mock("waiting") - waiting.expects(:ping!).once - - @klass.register(lambda { waiting.ping! }) - @klass.fire_callbacks - end - end -end diff --git a/test/unit_legacy/vagrant/util/counter_test.rb b/test/unit_legacy/vagrant/util/counter_test.rb deleted file mode 100644 index 10f9f55c880..00000000000 --- a/test/unit_legacy/vagrant/util/counter_test.rb +++ /dev/null @@ -1,29 +0,0 @@ -require "test_helper" - -class CounterUtilTest < Test::Unit::TestCase - setup do - @klass = Class.new do - extend Vagrant::Util::Counter - end - end - - context "basic counter" do - should "get and update the counter" do - assert_equal 1, @klass.get_and_update_counter - assert_equal 2, @klass.get_and_update_counter - end - end - - context "multiple classes with a counter" do - setup do - @klass2 = Class.new do - extend Vagrant::Util::Counter - end - end - - should "not affect other classes" do - assert_equal 1, @klass.get_and_update_counter - assert_equal 1, @klass2.get_and_update_counter - end - end -end diff --git a/test/unit_legacy/vagrant/util/platform_test.rb b/test/unit_legacy/vagrant/util/platform_test.rb deleted file mode 100644 index 8370cb23472..00000000000 --- a/test/unit_legacy/vagrant/util/platform_test.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "test_helper" - -class PlatformTest < Test::Unit::TestCase - context "file options" do - should "include add binary bit to options on windows platform" do - # This constant is not defined on non-windows platforms, so define it here - File::BINARY = 4096 unless defined?(File::BINARY) - - Vagrant::Util::Platform.stubs(:windows?).returns(true) - assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY|File::BINARY - end - - should "not include binary bit on other platforms" do - Vagrant::Util::Platform.stubs(:windows?).returns(false) - assert_equal Vagrant::Util::Platform.tar_file_options, File::CREAT|File::EXCL|File::WRONLY - end - end -end diff --git a/test/unit_legacy/vagrant/util/stacked_proc_runner_test.rb b/test/unit_legacy/vagrant/util/stacked_proc_runner_test.rb deleted file mode 100644 index 69fb8327fd0..00000000000 --- a/test/unit_legacy/vagrant/util/stacked_proc_runner_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require "test_helper" - -class StackedProcRunnerUtilTest < Test::Unit::TestCase - class TestClass - include Vagrant::Util::StackedProcRunner - end - - setup do - @instance = TestClass.new - @instance.proc_stack.clear - end - - should "not run the procs right away" do - obj = mock("obj") - obj.expects(:foo).never - @instance.push_proc { |config| obj.foo } - @instance.push_proc { |config| obj.foo } - @instance.push_proc { |config| obj.foo } - end - - should "run the blocks when run_procs! is ran" do - obj = mock("obj") - obj.expects(:foo).times(2) - @instance.push_proc { obj.foo } - @instance.push_proc { obj.foo } - @instance.run_procs! - end - - should "run the blocks with the same arguments" do - passed_config = mock("config") - @instance.push_proc { |config| assert passed_config.equal?(config) } - @instance.push_proc { |config| assert passed_config.equal?(config) } - @instance.run_procs!(passed_config) - end - - should "not clear the blocks after running" do - obj = mock("obj") - obj.expects(:foo).times(2) - @instance.push_proc { obj.foo } - @instance.run_procs! - @instance.run_procs! - end -end diff --git a/test/unit_legacy/vagrant/util/template_renderer_test.rb b/test/unit_legacy/vagrant/util/template_renderer_test.rb deleted file mode 100644 index 41df5f723c9..00000000000 --- a/test/unit_legacy/vagrant/util/template_renderer_test.rb +++ /dev/null @@ -1,145 +0,0 @@ -require "test_helper" - -class TemplateRendererUtilTest < Test::Unit::TestCase - context "initializing" do - should "set the template to the given argument" do - r = Vagrant::Util::TemplateRenderer.new("foo") - assert_equal "foo", r.template - end - - should "set any additional variables" do - r = Vagrant::Util::TemplateRenderer.new("foo", {:bar => :baz}) - assert_equal :baz, r.bar - end - end - - context "rendering" do - setup do - @template = "foo" - @r = Vagrant::Util::TemplateRenderer.new(@template) - @r.stubs(:full_template_path).returns(@template + "!") - - @contents = "bar" - - @file = mock("file") - @file.stubs(:read).returns(@contents) - File.stubs(:open).yields(@file) - end - - should "open the template file for reading" do - File.expects(:open).with(@r.full_template_path, 'r').once - @r.render - end - - should "set the template to the file contents, render, then set it back" do - result = "bar" - - template_seq = sequence("template_seq") - @r.expects(:template=).with(@file.read).in_sequence(template_seq) - @r.expects(:render_string).returns(result).in_sequence(template_seq) - @r.expects(:template=).with(@template).in_sequence(template_seq) - assert_equal result, @r.render - end - - should "render the ERB file in the context of the renderer" do - result = "bar" - template = "<%= foo %>" - @r.foo = result - @file.expects(:read).returns(template) - assert_equal result, @r.render - end - end - - context "rendering as string" do - setup do - @result = "foo" - @erb = mock("erb") - @erb.stubs(:result).returns(@result) - - @r = Vagrant::Util::TemplateRenderer.new("foo") - end - - should "simply render the template as a string" do - Erubis::Eruby.expects(:new).with(@r.template, :trim => true).returns(@erb) - @erb.expects(:result).returns(@result) - assert_equal @result, @r.render_string - end - end - - context "the full template path" do - setup do - @template = "foo" - @r = Vagrant::Util::TemplateRenderer.new(@template) - end - - should "be the ERB file in the templates directory" do - result = Vagrant.source_root.join("templates", "#{@template}.erb") - assert_equal result.to_s, @r.full_template_path - end - - should "remove duplicate path separators" do - @r.template = "foo///bar" - result = Vagrant.source_root.join("templates", "foo", "bar.erb") - assert_equal result.to_s, @r.full_template_path - end - end - - context "class methods" do - context "render_with method" do - setup do - @template = "foo" - @r = Vagrant::Util::TemplateRenderer.new(@template) - @r.stubs(:render) - - @method = :rawr - - Vagrant::Util::TemplateRenderer.stubs(:new).with(@template, {}).returns(@r) - end - - should "use the second argument as the template" do - Vagrant::Util::TemplateRenderer.expects(:new).with(@template, {}).returns(@r) - Vagrant::Util::TemplateRenderer.render_with(@method, @template) - end - - should "send in additional argument to the renderer" do - data = {:hey => :foo} - Vagrant::Util::TemplateRenderer.expects(:new).with(@template, data).returns(@r) - Vagrant::Util::TemplateRenderer.render_with(@method, @template, data) - end - - should "yield a block if given with the renderer as the argument" do - @r.expects(:yielded=).with(true).once - Vagrant::Util::TemplateRenderer.render_with(@method, @template) do |r| - r.yielded = true - end - end - - should "render the result using the given method" do - result = mock('result') - @r.expects(@method).returns(result) - assert_equal result, Vagrant::Util::TemplateRenderer.render_with(@method, @template) - end - - should "convert the given method to a sym prior to calling" do - @r.expects(@method.to_sym).returns(nil) - Vagrant::Util::TemplateRenderer.render_with(@method.to_s, @template) - end - end - - context "render method" do - should "call render_with the render! method" do - args = ["foo", "bar", "baz"] - Vagrant::Util::TemplateRenderer.expects(:render_with).with(:render, *args) - Vagrant::Util::TemplateRenderer.render(*args) - end - end - - context "render_string method" do - should "call render_with the render! method" do - args = ["foo", "bar", "baz"] - Vagrant::Util::TemplateRenderer.expects(:render_with).with(:render_string, *args) - Vagrant::Util::TemplateRenderer.render_string(*args) - end - end - end -end diff --git a/test/unit_legacy/vagrant/vm_test.rb b/test/unit_legacy/vagrant/vm_test.rb deleted file mode 100644 index d816859f8ca..00000000000 --- a/test/unit_legacy/vagrant/vm_test.rb +++ /dev/null @@ -1,300 +0,0 @@ -require "test_helper" - -class VMTest < Test::Unit::TestCase - setup do - @env = vagrant_env - end - - context "finding a VM" do - should "return return an uncreated VM object if the VM is not found" do - VirtualBox::VM.expects(:find).returns(nil) - result = Vagrant::VM.find("foo") - assert result.is_a?(Vagrant::VM) - assert !result.created? - end - - should "return a Vagrant::VM object for that VM if found" do - VirtualBox::VM.expects(:find).with("foo").returns("bar") - result = Vagrant::VM.find("foo", @env) - assert result.is_a?(Vagrant::VM) - assert_equal "bar", result.vm - end - end - - context "vagrant VM instance" do - setup do - @vm_name = "foo" - @mock_vm = mock("vm") - @mock_vm.stubs(:running?).returns(false) - @vm = Vagrant::VM.new(:env => @env, :vm => @mock_vm, :name => @vm_name) - @mock_vm.stubs(:uuid).returns("foo") - end - - context "checking if created" do - should "return true if the VM object is not nil" do - @vm.stubs(:vm).returns(:foo) - assert @vm.created? - end - - should "return false if the VM object is nil" do - @vm.stubs(:vm).returns(nil) - assert !@vm.created? - end - end - - context "setting the VM" do - setup do - @raw_vm = mock("vm") - @raw_vm.stubs(:uuid).returns("foobar") - end - - should "set the VM" do - @vm.vm = @raw_vm - assert_equal @raw_vm, @vm.vm - end - - should "add the VM to the active list" do - assert @env.local_data.empty? - @vm.vm = @raw_vm - assert_equal @raw_vm.uuid, @env.local_data[:active][@vm.name.to_s] - end - - should "remove the VM from the active list if nil is given" do - @env.local_data[:active] = { @vm.name.to_s => "foo" } - - assert @env.local_data[:active].has_key?(@vm.name.to_s) # sanity - @vm.vm = nil - - # This becomes empty because vm= will commit the local data which - # actually prunes out the empty values. - assert @env.local_data.empty? - end - end - - context "accessing the SSH object" do - setup do - # Reset this to nil to force the reload - @vm.instance_variable_set(:@ssh, nil) - - @ssh = mock("ssh") - Vagrant::SSH.stubs(:new).returns(@ssh) - end - - should "load it the first time, and only load it once" do - Vagrant::SSH.expects(:new).with(@vm.env).once.returns(@ssh) - @vm.ssh - @vm.ssh - @vm.ssh - end - end - - context "loading associated system" do - should "error and exit if system is not specified" do - @vm.env.config.vm.system = nil - - assert_raises(Vagrant::Errors::VMSystemError) { - @vm.load_system! - } - end - - should "load the given system if specified" do - fake_class = Class.new(Vagrant::Systems::Base) - - assert_nothing_raised { @vm.load_system!(fake_class) } - assert @vm.system.is_a?(fake_class) - end - - context "with a class" do - should "initialize class if given" do - @vm.env.config.vm.system = Vagrant::Systems::Linux - - assert_nothing_raised { @vm.load_system!} - assert @vm.system.is_a?(Vagrant::Systems::Linux) - end - - should "raise error if class has invalid parent" do - @vm.env.config.vm.system = Class.new - assert_raises(Vagrant::Errors::VMSystemError) { - @vm.load_system! - } - end - end - - context "with a symbol" do - should "initialize proper symbols" do - valid = { - :linux => Vagrant::Systems::Linux, - :solaris => Vagrant::Systems::Solaris - } - - valid.each do |symbol, klass| - @vm.env.config.vm.system = symbol - - assert_nothing_raised { @vm.load_system! } - assert @vm.system.is_a?(klass) - assert_equal @vm, @vm.system.vm - end - end - - should "error and exit with invalid symbol" do - @vm.env.config.vm.system = :shall_never_exist - - assert_raises(Vagrant::Errors::VMSystemError) { - @vm.load_system! - } - end - end - - context "loading the distro" do - setup do - @vm.vm.stubs(:running?).returns(true) - end - - should "not replace the distro if it is nil" do - @vm.env.config.vm.system = Class.new(Vagrant::Systems::Base) - - @vm.load_system! - assert @vm.system.is_a?(@vm.env.config.vm.system) - end - - should "replace the distro if it is not nil" do - @vm.env.config.vm.system = Class.new(Vagrant::Systems::Base) do - def distro_dispatch - :linux - end - end - - @vm.load_system! - assert @vm.system.is_a?(Vagrant::Systems::Linux) - end - end - end - - context "uuid" do - should "call UUID on VM object" do - uuid = mock("uuid") - @mock_vm.expects(:uuid).once.returns(uuid) - assert_equal uuid, @vm.uuid - end - - should "return nil if vm is nil" do - @vm.expects(:vm).returns(nil) - assert @vm.uuid.nil? - end - end - - context "reloading" do - should "load the same VM and set it" do - new_vm = mock("vm") - VirtualBox::VM.expects(:find).with(@mock_vm.uuid).returns(new_vm) - @vm.reload! - assert_equal new_vm, @vm.vm - end - end - - context "packaging" do - should "execute the package action" do - @vm.env.actions.expects(:run).once.with() do |action, options| - assert_equal :package, action - assert_equal :bar, options[:foo] - true - end - - @vm.package(:foo => :bar) - end - end - - context "upping" do - should "execute the up action" do - @vm.env.actions.expects(:run).with(:up, nil).once - @vm.up - end - - should "forward options to the action sequence" do - @vm.env.actions.expects(:run).with(:up, :foo => :bar).once - @vm.up(:foo => :bar) - end - end - - context "halting" do - should "execute the halt action" do - @vm.env.actions.expects(:run).with(:halt, :foo => :bar).once - @vm.halt({:foo => :bar}) - end - end - - context "reloading action" do - should "execute the reload action" do - @vm.env.actions.expects(:run).with(:reload).once - @vm.reload - end - end - - context "provisioning" do - should "execute the provision action" do - @vm.env.actions.expects(:run).with(:provision).once - @vm.provision - end - end - - context "destroying" do - should "execute the destroy action" do - @vm.env.actions.expects(:run).with(:destroy).once - @vm.destroy - end - end - - context "suspending" do - should "execute the suspend action" do - @vm.env.actions.expects(:run).with(:suspend).once - @vm.suspend - end - end - - context "resuming" do - should "execute the resume action" do - @vm.env.actions.expects(:run).with(:resume).once - @vm.resume - end - end - - context "starting" do - setup do - @mock_vm.stubs(:running?).returns(false) - @mock_vm.stubs(:saved?).returns(false) - @mock_vm.stubs(:accessible?).returns(true) - end - - should "not do anything if the VM is already running" do - @mock_vm.stubs(:running?).returns(true) - @vm.expects(:execute!).never - @vm.start - end - - should "execute the resume action if saved" do - @mock_vm.expects(:saved?).returns(true) - @vm.expects(:resume).once - @vm.env.actions.expects(:run).with(:start, nil).never - @vm.start - end - - should "execute the start action" do - @vm.env.actions.expects(:run).with(:start, nil).once - @vm.start - end - - should "forward options to the action sequence" do - @vm.env.actions.expects(:run).with(:start, :foo => :bar).once - @vm.start(:foo => :bar) - end - - should "raise an exception if the VM is not accessible" do - @mock_vm.stubs(:accessible?).returns(false) - - assert_raises(Vagrant::Errors::VMInaccessible) { - @vm.start - } - end - end - end -end