vagrant 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +56 -0
- data/Gemfile +14 -3
- data/Gemfile.lock +38 -11
- data/README.md +1 -1
- data/bin/vagrant +20 -5
- data/config/default.rb +6 -8
- data/lib/vagrant.rb +40 -13
- data/lib/vagrant/action.rb +56 -16
- data/lib/vagrant/action/box/destroy.rb +3 -1
- data/lib/vagrant/action/box/download.rb +8 -13
- data/lib/vagrant/action/box/unpackage.rb +8 -11
- data/lib/vagrant/action/box/verify.rb +3 -3
- data/lib/vagrant/action/builder.rb +3 -30
- data/lib/vagrant/action/builtin.rb +6 -1
- data/lib/vagrant/action/environment.rb +14 -62
- data/lib/vagrant/action/general/package.rb +29 -22
- data/lib/vagrant/action/vm/boot.rb +5 -12
- data/lib/vagrant/action/vm/check_box.rb +4 -4
- data/lib/vagrant/action/vm/check_guest_additions.rb +4 -6
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +2 -2
- data/lib/vagrant/action/vm/clear_nfs_exports.rb +1 -1
- data/lib/vagrant/action/vm/clear_shared_folders.rb +1 -1
- data/lib/vagrant/action/vm/customize.rb +1 -1
- data/lib/vagrant/action/vm/destroy.rb +1 -2
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +1 -1
- data/lib/vagrant/action/vm/disable_networks.rb +11 -9
- data/lib/vagrant/action/vm/discard_state.rb +2 -2
- data/lib/vagrant/action/vm/export.rb +10 -11
- data/lib/vagrant/action/vm/forward_ports.rb +21 -9
- data/lib/vagrant/action/vm/halt.rb +3 -8
- data/lib/vagrant/action/vm/import.rb +16 -14
- data/lib/vagrant/action/vm/match_mac_address.rb +1 -1
- data/lib/vagrant/action/vm/network.rb +9 -16
- data/lib/vagrant/action/vm/nfs.rb +14 -18
- data/lib/vagrant/action/vm/provision.rb +5 -5
- data/lib/vagrant/action/vm/resume.rb +1 -1
- data/lib/vagrant/action/vm/share_folders.rb +6 -44
- data/lib/vagrant/action/vm/suspend.rb +1 -1
- data/lib/vagrant/action/warden.rb +74 -0
- data/lib/vagrant/box.rb +18 -82
- data/lib/vagrant/box_collection.rb +47 -0
- data/lib/vagrant/cli.rb +55 -0
- data/lib/vagrant/command/base.rb +106 -0
- data/lib/vagrant/command/box.rb +33 -0
- data/lib/vagrant/command/destroy.rb +17 -0
- data/lib/vagrant/command/group_base.rb +99 -0
- data/lib/vagrant/command/halt.rb +18 -0
- data/lib/vagrant/command/helpers.rb +33 -0
- data/lib/vagrant/command/init.rb +14 -0
- data/lib/vagrant/command/named_base.rb +14 -0
- data/lib/vagrant/command/package.rb +41 -0
- data/lib/vagrant/command/provision.rb +17 -0
- data/lib/vagrant/command/reload.rb +17 -0
- data/lib/vagrant/command/resume.rb +17 -0
- data/lib/vagrant/command/ssh.rb +41 -0
- data/lib/vagrant/command/ssh_config.rb +21 -0
- data/lib/vagrant/command/status.rb +23 -0
- data/lib/vagrant/command/suspend.rb +17 -0
- data/lib/vagrant/command/up.rb +20 -0
- data/lib/vagrant/command/upgrade_to_060.rb +45 -0
- data/lib/vagrant/command/version.rb +13 -0
- data/lib/vagrant/config.rb +107 -189
- data/lib/vagrant/config/base.rb +67 -0
- data/lib/vagrant/config/error_recorder.rb +19 -0
- data/lib/vagrant/config/nfs.rb +10 -0
- data/lib/vagrant/config/package.rb +9 -0
- data/lib/vagrant/config/ssh.rb +28 -0
- data/lib/vagrant/config/vagrant.rb +21 -0
- data/lib/vagrant/config/vm.rb +111 -0
- data/lib/vagrant/data_store.rb +68 -0
- data/lib/vagrant/downloaders/file.rb +3 -3
- data/lib/vagrant/downloaders/http.rb +5 -5
- data/lib/vagrant/environment.rb +246 -243
- data/lib/vagrant/errors.rb +306 -0
- data/lib/vagrant/hosts/base.rb +1 -1
- data/lib/vagrant/hosts/bsd.rb +3 -9
- data/lib/vagrant/hosts/linux.rb +3 -9
- data/lib/vagrant/plugin.rb +50 -0
- data/lib/vagrant/provisioners/base.rb +0 -6
- data/lib/vagrant/provisioners/chef.rb +63 -58
- data/lib/vagrant/provisioners/chef_server.rb +9 -11
- data/lib/vagrant/provisioners/chef_solo.rb +2 -2
- data/lib/vagrant/ssh.rb +34 -37
- data/lib/vagrant/systems/base.rb +0 -13
- data/lib/vagrant/systems/linux.rb +10 -33
- data/lib/vagrant/systems/solaris.rb +59 -0
- data/lib/vagrant/test_helpers.rb +109 -0
- data/lib/vagrant/ui.rb +65 -0
- data/lib/vagrant/util.rb +9 -19
- data/lib/vagrant/util/glob_loader.rb +19 -17
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/plain_logger.rb +2 -0
- data/lib/vagrant/util/platform.rb +2 -0
- data/lib/vagrant/util/resource_logger.rb +5 -70
- data/lib/vagrant/util/retryable.rb +25 -0
- data/lib/vagrant/util/template_renderer.rb +1 -1
- data/lib/vagrant/version.rb +1 -1
- data/lib/vagrant/vm.rb +27 -13
- data/templates/commands/init/Vagrantfile.erb +13 -0
- data/templates/config/validation_failed.erb +7 -0
- data/templates/locales/en.yml +402 -0
- data/templates/package_Vagrantfile.erb +1 -1
- data/test/locales/en.yml +8 -0
- data/test/test_helper.rb +19 -103
- data/test/vagrant/action/box/destroy_test.rb +7 -19
- data/test/vagrant/action/box/download_test.rb +9 -25
- data/test/vagrant/action/box/package_test.rb +2 -2
- data/test/vagrant/action/box/unpackage_test.rb +8 -34
- data/test/vagrant/action/box/verify_test.rb +10 -19
- data/test/vagrant/action/builder_test.rb +0 -15
- data/test/vagrant/action/env/set_test.rb +1 -1
- data/test/vagrant/action/environment_test.rb +8 -26
- data/test/vagrant/action/general/package_test.rb +53 -53
- data/test/vagrant/action/vm/boot_test.rb +5 -22
- data/test/vagrant/action/vm/check_box_test.rb +35 -25
- data/test/vagrant/action/vm/clean_machine_folder_test.rb +1 -1
- data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +1 -1
- data/test/vagrant/action/vm/clear_nfs_exports_test.rb +1 -1
- data/test/vagrant/action/vm/clear_shared_folders_test.rb +1 -1
- data/test/vagrant/action/vm/customize_test.rb +2 -1
- data/test/vagrant/action/vm/destroy_test.rb +1 -2
- data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +1 -1
- data/test/vagrant/action/vm/disable_networks_test.rb +10 -1
- data/test/vagrant/action/vm/discard_state_test.rb +10 -1
- data/test/vagrant/action/vm/export_test.rb +9 -37
- data/test/vagrant/action/vm/forward_ports_helpers_test.rb +2 -2
- data/test/vagrant/action/vm/forward_ports_test.rb +19 -16
- data/test/vagrant/action/vm/halt_test.rb +11 -1
- data/test/vagrant/action/vm/import_test.rb +37 -21
- data/test/vagrant/action/vm/match_mac_address_test.rb +1 -1
- data/test/vagrant/action/vm/network_test.rb +8 -7
- data/test/vagrant/action/vm/nfs_helpers_test.rb +6 -3
- data/test/vagrant/action/vm/nfs_test.rb +20 -45
- data/test/vagrant/action/vm/package_test.rb +1 -1
- data/test/vagrant/action/vm/package_vagrantfile_test.rb +1 -1
- data/test/vagrant/action/vm/provision_test.rb +10 -17
- data/test/vagrant/action/vm/resume_test.rb +1 -1
- data/test/vagrant/action/vm/share_folders_test.rb +25 -106
- data/test/vagrant/action/vm/suspend_test.rb +1 -1
- data/test/vagrant/action/warden_test.rb +105 -0
- data/test/vagrant/action_test.rb +5 -27
- data/test/vagrant/box_collection_test.rb +44 -0
- data/test/vagrant/box_test.rb +5 -105
- data/test/vagrant/cli_test.rb +35 -0
- data/test/vagrant/command/base_test.rb +23 -0
- data/test/vagrant/command/group_base_test.rb +15 -0
- data/test/vagrant/command/helpers_test.rb +88 -0
- data/test/vagrant/config/base_test.rb +52 -0
- data/test/vagrant/config/error_recorder_test.rb +18 -0
- data/test/vagrant/config/ssh_test.rb +12 -0
- data/test/vagrant/config/vagrant_test.rb +11 -0
- data/test/vagrant/config/vm_test.rb +70 -0
- data/test/vagrant/config_test.rb +113 -206
- data/test/vagrant/data_store_test.rb +68 -0
- data/test/vagrant/downloaders/base_test.rb +1 -1
- data/test/vagrant/downloaders/file_test.rb +4 -3
- data/test/vagrant/downloaders/http_test.rb +14 -4
- data/test/vagrant/environment_test.rb +290 -590
- data/test/vagrant/errors_test.rb +42 -0
- data/test/vagrant/hosts/base_test.rb +1 -1
- data/test/vagrant/hosts/bsd_test.rb +3 -6
- data/test/vagrant/hosts/linux_test.rb +3 -5
- data/test/vagrant/plugin_test.rb +9 -0
- data/test/vagrant/provisioners/base_test.rb +1 -1
- data/test/vagrant/provisioners/chef_server_test.rb +31 -35
- data/test/vagrant/provisioners/chef_solo_test.rb +1 -1
- data/test/vagrant/provisioners/chef_test.rb +7 -7
- data/test/vagrant/ssh_session_test.rb +3 -10
- data/test/vagrant/ssh_test.rb +25 -33
- data/test/vagrant/systems/linux_test.rb +6 -71
- data/test/vagrant/ui_test.rb +29 -0
- data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
- data/test/vagrant/util/resource_logger_test.rb +14 -81
- data/test/vagrant/util/retryable_test.rb +38 -0
- data/test/vagrant/util/template_renderer_test.rb +4 -4
- data/test/vagrant/vm_test.rb +47 -26
- data/vagrant.gemspec +14 -12
- metadata +142 -108
- data/bin/.gitignore +0 -0
- data/lib/vagrant/action/action_exception.rb +0 -16
- data/lib/vagrant/action/env/error_halt.rb +0 -16
- data/lib/vagrant/action/exception_catcher.rb +0 -14
- data/lib/vagrant/action/vm/persist.rb +0 -22
- data/lib/vagrant/active_list.rb +0 -83
- data/lib/vagrant/command.rb +0 -27
- data/lib/vagrant/commands/base.rb +0 -181
- data/lib/vagrant/commands/box.rb +0 -16
- data/lib/vagrant/commands/box/add.rb +0 -30
- data/lib/vagrant/commands/box/list.rb +0 -30
- data/lib/vagrant/commands/box/remove.rb +0 -30
- data/lib/vagrant/commands/box/repackage.rb +0 -35
- data/lib/vagrant/commands/destroy.rb +0 -37
- data/lib/vagrant/commands/halt.rb +0 -43
- data/lib/vagrant/commands/init.rb +0 -36
- data/lib/vagrant/commands/package.rb +0 -81
- data/lib/vagrant/commands/provision.rb +0 -31
- data/lib/vagrant/commands/reload.rb +0 -36
- data/lib/vagrant/commands/resume.rb +0 -35
- data/lib/vagrant/commands/ssh.rb +0 -78
- data/lib/vagrant/commands/ssh_config.rb +0 -45
- data/lib/vagrant/commands/status.rb +0 -125
- data/lib/vagrant/commands/suspend.rb +0 -36
- data/lib/vagrant/commands/up.rb +0 -44
- data/lib/vagrant/exceptions/uncallable_action.rb +0 -17
- data/lib/vagrant/util/translator.rb +0 -35
- data/templates/strings.yml +0 -341
- data/templates/unison/crontab_entry.erb +0 -1
- data/templates/unison/script.erb +0 -71
- data/test/vagrant/action/env/error_halt_test.rb +0 -21
- data/test/vagrant/action/exception_catcher_test.rb +0 -30
- data/test/vagrant/action/vm/persist_test.rb +0 -50
- data/test/vagrant/active_list_test.rb +0 -173
- data/test/vagrant/command_test.rb +0 -53
- data/test/vagrant/commands/base_test.rb +0 -139
- data/test/vagrant/commands/box/add_test.rb +0 -34
- data/test/vagrant/commands/box/list_test.rb +0 -32
- data/test/vagrant/commands/box/remove_test.rb +0 -41
- data/test/vagrant/commands/box/repackage_test.rb +0 -52
- data/test/vagrant/commands/destroy_test.rb +0 -44
- data/test/vagrant/commands/halt_test.rb +0 -50
- data/test/vagrant/commands/init_test.rb +0 -71
- data/test/vagrant/commands/package_test.rb +0 -97
- data/test/vagrant/commands/provision_test.rb +0 -60
- data/test/vagrant/commands/reload_test.rb +0 -47
- data/test/vagrant/commands/resume_test.rb +0 -44
- data/test/vagrant/commands/ssh_config_test.rb +0 -77
- data/test/vagrant/commands/ssh_test.rb +0 -129
- data/test/vagrant/commands/status_test.rb +0 -40
- data/test/vagrant/commands/suspend_test.rb +0 -44
- data/test/vagrant/commands/up_test.rb +0 -49
- data/test/vagrant/util/translator_test.rb +0 -61
- data/test/vagrant/util_test.rb +0 -27
@@ -1 +0,0 @@
|
|
1
|
-
* * * * * <%= script %> '<%= from %>' '<%= to %>' '<%= options %>' >> <%= log_file %> 2>&1
|
data/templates/unison/script.erb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
#------------------------------------------------------------
|
3
|
-
# Author : John Bender and Mitchell Hashimoto
|
4
|
-
# Description : Runs the `unison` folder synchronization
|
5
|
-
# utility for shared folders.
|
6
|
-
#------------------------------------------------------------
|
7
|
-
|
8
|
-
#------------------------------------------------------------
|
9
|
-
# Argument verification
|
10
|
-
#------------------------------------------------------------
|
11
|
-
if [ $# -ne 3 ]; then
|
12
|
-
echo "Usage: `basename $0` from_folder to_folder options"
|
13
|
-
exit 1
|
14
|
-
fi
|
15
|
-
|
16
|
-
# Sanitization function which turns any non-alphanumeric char
|
17
|
-
# into a dash '-' and returns it by echoing the result.
|
18
|
-
function sanitize() {
|
19
|
-
local DATA=$1
|
20
|
-
DATA=${DATA//[^a-zA-Z0-9_-]/-}
|
21
|
-
echo ${DATA}
|
22
|
-
}
|
23
|
-
|
24
|
-
#------------------------------------------------------------
|
25
|
-
# "Configuration"
|
26
|
-
#------------------------------------------------------------
|
27
|
-
# TODO Change lockfile to depend on the from/to folder to
|
28
|
-
# allow multiple syncs of diff folders to happen at once.
|
29
|
-
FROM=$1
|
30
|
-
TO=$2
|
31
|
-
OPTIONS=$3
|
32
|
-
LOCK_FILE=`basename $0`-$(sanitize ${TO}).lck
|
33
|
-
|
34
|
-
#------------------------------------------------------------
|
35
|
-
# Am I Running?
|
36
|
-
#------------------------------------------------------------
|
37
|
-
if [ -f "${LOCK_FILE}" ]; then
|
38
|
-
# The file exists, verify its running and if so exit.
|
39
|
-
OUR_PID=`head -n 1 "${LOCK_FILE}"`
|
40
|
-
TEST_RUNNING=`ps -p ${OUR_PID} | grep ${OUR_PID}`
|
41
|
-
|
42
|
-
if [ "${TEST_RUNNING}" ]; then
|
43
|
-
# The process is running, echo and exit.
|
44
|
-
echo "Unison sync already running. [PID: ${OUR_PID}]"
|
45
|
-
exit 0
|
46
|
-
fi
|
47
|
-
fi
|
48
|
-
|
49
|
-
# We're not running if we reached this point, so lock
|
50
|
-
# it up.
|
51
|
-
echo $$ > "${LOCK_FILE}"
|
52
|
-
|
53
|
-
#------------------------------------------------------------
|
54
|
-
# The Meat
|
55
|
-
#------------------------------------------------------------
|
56
|
-
echo "Beginning Sync:"
|
57
|
-
echo " -- From: ${FROM}"
|
58
|
-
echo " -- To: ${TO}"
|
59
|
-
echo " -- Options: ${OPTIONS}"
|
60
|
-
while [ 1 ]; do
|
61
|
-
echo "Syncing: $(date)"
|
62
|
-
# TODO check result and output log data... somewhere!
|
63
|
-
sudo unison ${FROM} ${TO} ${OPTIONS}
|
64
|
-
sleep 1
|
65
|
-
done
|
66
|
-
|
67
|
-
#------------------------------------------------------------
|
68
|
-
# Cleanup and Exit
|
69
|
-
#------------------------------------------------------------
|
70
|
-
rm -f "${LOCK_FILE}"
|
71
|
-
exit 0
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class ErrorHaltEnvActionTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@klass = Vagrant::Action::Env::ErrorHalt
|
6
|
-
@app, @env = mock_action_data
|
7
|
-
@instance = @klass.new(@app, @env)
|
8
|
-
end
|
9
|
-
|
10
|
-
should "continue the chain if no error" do
|
11
|
-
assert !@env.error?
|
12
|
-
@app.expects(:call).with(@env).once
|
13
|
-
@instance.call(@env)
|
14
|
-
end
|
15
|
-
|
16
|
-
should "halt the chain if an error occured" do
|
17
|
-
@env.error!(:foo)
|
18
|
-
@app.expects(:call).never
|
19
|
-
@instance.call(@env)
|
20
|
-
end
|
21
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class ExceptionCatcherTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@klass = Class.new
|
6
|
-
@klass.send(:include, Vagrant::Action::ExceptionCatcher)
|
7
|
-
@env = Vagrant::Action::Environment.new(mock_environment)
|
8
|
-
|
9
|
-
@instance = @klass.new
|
10
|
-
end
|
11
|
-
|
12
|
-
should "run block and return result if no exception" do
|
13
|
-
result = @instance.catch_action_exception(@env) do
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
|
-
assert result
|
18
|
-
assert !@env.error?
|
19
|
-
end
|
20
|
-
|
21
|
-
should "run block and return false with error environment on exception" do
|
22
|
-
result = @instance.catch_action_exception(@env) do
|
23
|
-
raise Vagrant::Action::ActionException.new(:foo, :foo => :bar)
|
24
|
-
end
|
25
|
-
|
26
|
-
assert !result
|
27
|
-
assert @env.error?
|
28
|
-
assert_equal :foo, @env.error.first
|
29
|
-
end
|
30
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class PersistVMActionTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@klass = Vagrant::Action::VM::Persist
|
6
|
-
@app, @env = mock_action_data
|
7
|
-
|
8
|
-
@vm = mock("vm")
|
9
|
-
@vm.stubs(:uuid).returns("123")
|
10
|
-
@env["vm"] = @vm
|
11
|
-
end
|
12
|
-
|
13
|
-
context "initializing" do
|
14
|
-
setup do
|
15
|
-
File.stubs(:file?).returns(true)
|
16
|
-
File.stubs(:exist?).returns(true)
|
17
|
-
@dotfile_path = "foo"
|
18
|
-
@env.env.stubs(:dotfile_path).returns(@dotfile_path)
|
19
|
-
end
|
20
|
-
|
21
|
-
should "error environment if dotfile exists but is not a file" do
|
22
|
-
File.expects(:file?).with(@env.env.dotfile_path).returns(false)
|
23
|
-
@klass.new(@app, @env)
|
24
|
-
assert @env.error?
|
25
|
-
assert_equal :dotfile_error, @env.error.first
|
26
|
-
end
|
27
|
-
|
28
|
-
should "initialize properly if dotfiles doesn't exist" do
|
29
|
-
File.expects(:exist?).with(@env.env.dotfile_path).returns(false)
|
30
|
-
@klass.new(@app, @env)
|
31
|
-
assert !@env.error?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "with an instance" do
|
36
|
-
setup do
|
37
|
-
File.stubs(:file?).returns(true)
|
38
|
-
File.stubs(:exist?).returns(true)
|
39
|
-
@instance = @klass.new(@app, @env)
|
40
|
-
end
|
41
|
-
|
42
|
-
should "persist the dotfile then continue chain" do
|
43
|
-
update_seq = sequence("update_seq")
|
44
|
-
@env.env.expects(:update_dotfile).in_sequence(update_seq)
|
45
|
-
@app.expects(:call).with(@env).in_sequence(update_seq)
|
46
|
-
|
47
|
-
@instance.call(@env)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,173 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class ActiveListTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@env = mock_environment
|
6
|
-
@list = Vagrant::ActiveList.new(@env)
|
7
|
-
end
|
8
|
-
|
9
|
-
context "initializing" do
|
10
|
-
should "set the environment to nil if not specified" do
|
11
|
-
assert_nothing_raised {
|
12
|
-
list = Vagrant::ActiveList.new
|
13
|
-
assert list.env.nil?
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
should "set the environment to the given parameter if specified" do
|
18
|
-
env = mock("env")
|
19
|
-
list = Vagrant::ActiveList.new(env)
|
20
|
-
assert_equal env, list.env
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "listing" do
|
25
|
-
setup do
|
26
|
-
@path = "foo"
|
27
|
-
@list.stubs(:path).returns(@path)
|
28
|
-
end
|
29
|
-
|
30
|
-
should "load if reload is given" do
|
31
|
-
File.stubs(:file?).returns(true)
|
32
|
-
File.expects(:open).once
|
33
|
-
@list.list(true)
|
34
|
-
end
|
35
|
-
|
36
|
-
should "not load if the active json file doesn't exist" do
|
37
|
-
File.expects(:file?).with(@list.path).returns(false)
|
38
|
-
File.expects(:open).never
|
39
|
-
assert_equal Hash.new, @list.list(true)
|
40
|
-
end
|
41
|
-
|
42
|
-
should "parse the JSON by reading the file" do
|
43
|
-
file = mock("file")
|
44
|
-
data = mock("data")
|
45
|
-
result = { :hey => :yep }
|
46
|
-
File.expects(:file?).returns(true)
|
47
|
-
File.expects(:open).with(@list.path, 'r').once.yields(file)
|
48
|
-
file.expects(:read).returns(data)
|
49
|
-
JSON.expects(:parse).with(data).returns(result)
|
50
|
-
assert_equal result, @list.list(true)
|
51
|
-
end
|
52
|
-
|
53
|
-
should "not load if reload flag is false and already loaded" do
|
54
|
-
File.expects(:file?).once.returns(false)
|
55
|
-
result = @list.list(true)
|
56
|
-
assert result.equal?(@list.list)
|
57
|
-
assert result.equal?(@list.list)
|
58
|
-
assert result.equal?(@list.list)
|
59
|
-
end
|
60
|
-
|
61
|
-
should "be an empty hash if JSON parsing raises an exception" do
|
62
|
-
file = mock("file")
|
63
|
-
file.stubs(:read)
|
64
|
-
File.expects(:file?).returns(true)
|
65
|
-
File.expects(:open).with(@list.path, 'r').once.yields(file)
|
66
|
-
JSON.expects(:parse).raises(Exception)
|
67
|
-
|
68
|
-
assert_nothing_raised do
|
69
|
-
assert_equal Hash.new, @list.list(true)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
context "filter list" do
|
75
|
-
should "remove nonexistent VMs" do
|
76
|
-
list = {}
|
77
|
-
result = {}
|
78
|
-
5.times do |i|
|
79
|
-
vm = mock("vm#{i}")
|
80
|
-
vm.stubs(:uuid).returns(i)
|
81
|
-
|
82
|
-
list[vm.uuid] = {}
|
83
|
-
|
84
|
-
found_vm = i % 2 ? nil : vm
|
85
|
-
Vagrant::VM.stubs(:find).with(vm.uuid, @env).returns(found_vm)
|
86
|
-
results[vm.uuid] = {} if found_vm
|
87
|
-
end
|
88
|
-
|
89
|
-
@list.stubs(:list).returns(list)
|
90
|
-
assert_equal result, @list.filter_list
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "adding a VM to the list" do
|
95
|
-
setup do
|
96
|
-
@the_list = {}
|
97
|
-
@list.stubs(:list).returns(@the_list)
|
98
|
-
@list.stubs(:save)
|
99
|
-
|
100
|
-
@uuid = "foo"
|
101
|
-
@vm = mock("vm")
|
102
|
-
@vm.stubs(:uuid).returns(@uuid)
|
103
|
-
end
|
104
|
-
|
105
|
-
should "add the VMs UUID to the list" do
|
106
|
-
@list.add(@vm)
|
107
|
-
assert @the_list[@uuid]
|
108
|
-
assert @the_list[@uuid].is_a?(Hash)
|
109
|
-
end
|
110
|
-
|
111
|
-
should "save after adding" do
|
112
|
-
save_seq = sequence('save')
|
113
|
-
@the_list.expects(:[]=).in_sequence(save_seq)
|
114
|
-
@list.expects(:save).in_sequence(save_seq)
|
115
|
-
@list.add(@vm)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
context "deleting a VM from the list" do
|
120
|
-
setup do
|
121
|
-
@the_list = ["bar"]
|
122
|
-
@list.stubs(:list).returns(@the_list)
|
123
|
-
@list.stubs(:save)
|
124
|
-
|
125
|
-
@uuid = "bar"
|
126
|
-
@vm = mock("vm")
|
127
|
-
@vm.stubs(:uuid).returns(@uuid)
|
128
|
-
@vm.stubs(:is_a?).with(Vagrant::VM).returns(true)
|
129
|
-
end
|
130
|
-
|
131
|
-
should "delete the uuid from the list of a VM" do
|
132
|
-
@list.remove(@vm)
|
133
|
-
assert @the_list.empty?
|
134
|
-
end
|
135
|
-
|
136
|
-
should "delete just the string if a string is given" do
|
137
|
-
@the_list << "zoo"
|
138
|
-
@list.remove("zoo")
|
139
|
-
assert !@the_list.include?("zoo")
|
140
|
-
end
|
141
|
-
|
142
|
-
should "save after removing" do
|
143
|
-
save_seq = sequence('save')
|
144
|
-
@the_list.expects(:delete).in_sequence(save_seq)
|
145
|
-
@list.expects(:save).in_sequence(save_seq)
|
146
|
-
@list.remove(@vm)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context "saving" do
|
151
|
-
setup do
|
152
|
-
@filtered = ["zoo"]
|
153
|
-
@list.stubs(:filter_list).returns(@filtered)
|
154
|
-
end
|
155
|
-
|
156
|
-
should "open the JSON path and save to it" do
|
157
|
-
file = mock("file")
|
158
|
-
File.expects(:open).with(@list.path, "w+").yields(file)
|
159
|
-
file.expects(:write).with(@filtered.to_json)
|
160
|
-
@list.save
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context "path" do
|
165
|
-
setup do
|
166
|
-
@env.stubs(:home_path).returns("foo")
|
167
|
-
end
|
168
|
-
|
169
|
-
should "return the active file within the home path" do
|
170
|
-
assert_equal File.join(@env.home_path, Vagrant::ActiveList::FILENAME), @list.path
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class CommandTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@klass = Vagrant::Command
|
6
|
-
end
|
7
|
-
|
8
|
-
context "initializing" do
|
9
|
-
setup do
|
10
|
-
@env = mock("environment")
|
11
|
-
end
|
12
|
-
|
13
|
-
should "set the env attribute" do
|
14
|
-
@instance = @klass.new(@env)
|
15
|
-
assert_equal @env, @instance.env
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "class methods" do
|
20
|
-
context "executing" do
|
21
|
-
should "load the environment then send the command on commands" do
|
22
|
-
env = mock("env")
|
23
|
-
commands = mock("commands")
|
24
|
-
env.stubs(:commands).returns(commands)
|
25
|
-
Vagrant::Environment.expects(:load!).returns(env)
|
26
|
-
commands.expects(:subcommand).with(1,2,3).once
|
27
|
-
|
28
|
-
@klass.execute(1,2,3)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "with an instance" do
|
34
|
-
setup do
|
35
|
-
@env = mock_environment
|
36
|
-
@instance = @klass.new(@env)
|
37
|
-
end
|
38
|
-
|
39
|
-
context "subcommands" do
|
40
|
-
setup do
|
41
|
-
@raw_name = :bar
|
42
|
-
@name = :foo
|
43
|
-
@instance.stubs(:camelize).with(@raw_name).returns(@name)
|
44
|
-
end
|
45
|
-
|
46
|
-
should "send the env, name, and args to the base class" do
|
47
|
-
args = [1,2,3]
|
48
|
-
Vagrant::Commands::Base.expects(:dispatch).with(@env, @name, *args)
|
49
|
-
@instance.subcommand(@name, *args)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,139 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class CommandsBaseTest < Test::Unit::TestCase
|
4
|
-
setup do
|
5
|
-
@klass = Vagrant::Commands::Base
|
6
|
-
end
|
7
|
-
|
8
|
-
context "initializing" do
|
9
|
-
should "setup the env attribute" do
|
10
|
-
env = mock("env")
|
11
|
-
instance = @klass.new(env)
|
12
|
-
assert_equal env, instance.env
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "class methods" do
|
17
|
-
setup do
|
18
|
-
@env = mock_environment
|
19
|
-
@klass.subcommands.clear
|
20
|
-
end
|
21
|
-
|
22
|
-
context "registering commands" do
|
23
|
-
should "register commands" do
|
24
|
-
klass = mock("klass")
|
25
|
-
@klass.subcommand("init", klass)
|
26
|
-
assert_equal klass, @klass.subcommands["init"]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "dispatching to subcommands" do
|
31
|
-
setup do
|
32
|
-
@command_klass = mock("klass")
|
33
|
-
@name = "init"
|
34
|
-
@klass.subcommand(@name, @command_klass)
|
35
|
-
|
36
|
-
@args = [1,2,3]
|
37
|
-
end
|
38
|
-
|
39
|
-
should "call dispatch on child if subcommand is found" do
|
40
|
-
@command_klass.expects(:dispatch).with(@env, *@args)
|
41
|
-
@klass.dispatch(@env, @name, *@args)
|
42
|
-
end
|
43
|
-
|
44
|
-
should "instantiate and execute when no subcommand is found" do
|
45
|
-
instance = mock("instance")
|
46
|
-
@klass.expects(:new).with(@env).returns(instance)
|
47
|
-
instance.expects(:execute).with(@args)
|
48
|
-
@klass.dispatch(@env, *@args)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "descriptions" do
|
53
|
-
should "be able to set description" do
|
54
|
-
description = "The lazy fox yada yada"
|
55
|
-
@klass.description(description)
|
56
|
-
assert_equal description, @klass.description
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "instance methods" do
|
62
|
-
setup do
|
63
|
-
@env = mock_environment
|
64
|
-
@instance = @klass.new(@env)
|
65
|
-
end
|
66
|
-
|
67
|
-
context "executing" do
|
68
|
-
should "show version if flag is set" do
|
69
|
-
@instance.expects(:puts_version).once
|
70
|
-
@instance.expects(:show_help).never
|
71
|
-
@instance.execute(["--version"])
|
72
|
-
end
|
73
|
-
|
74
|
-
should "just print the help by default" do
|
75
|
-
@instance.expects(:puts_version).never
|
76
|
-
@instance.expects(:show_help).once
|
77
|
-
@instance.execute([])
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "all or single methods" do
|
82
|
-
should "call the single method if a name is given" do
|
83
|
-
name = "bar"
|
84
|
-
@instance.expects(:foo_single).with(name).once
|
85
|
-
@instance.all_or_single(["bar"], :foo)
|
86
|
-
end
|
87
|
-
|
88
|
-
should "call the single method for each VM if no name is given" do
|
89
|
-
vms = { :foo => nil, :bar => nil }
|
90
|
-
vms.keys.each do |name|
|
91
|
-
@instance.expects(:foo_single).with(name).once
|
92
|
-
end
|
93
|
-
|
94
|
-
@env.stubs(:vms).returns(vms)
|
95
|
-
@instance.all_or_single([], :foo)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "getting the option parser" do
|
100
|
-
should "create it with the options spec if it hasn't been created yet" do
|
101
|
-
opts = mock("opts")
|
102
|
-
opts.stubs(:on)
|
103
|
-
|
104
|
-
result = mock("result")
|
105
|
-
OptionParser.expects(:new).yields(opts).returns(result)
|
106
|
-
@instance.expects(:options_spec).with(opts)
|
107
|
-
|
108
|
-
assert_equal result, @instance.option_parser(true)
|
109
|
-
end
|
110
|
-
|
111
|
-
should "not create it once its been created" do
|
112
|
-
result = mock("result")
|
113
|
-
OptionParser.expects(:new).once.returns(result)
|
114
|
-
|
115
|
-
assert_equal result, @instance.option_parser(true)
|
116
|
-
assert_equal result, @instance.option_parser
|
117
|
-
assert_equal result, @instance.option_parser
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "parsing options" do
|
122
|
-
setup do
|
123
|
-
@args = []
|
124
|
-
|
125
|
-
@options = mock("options")
|
126
|
-
@option_parser = mock("option_parser")
|
127
|
-
|
128
|
-
@instance.stubs(:option_parser).returns(@option_parser)
|
129
|
-
@instance.stubs(:options).returns(@options)
|
130
|
-
end
|
131
|
-
|
132
|
-
should "parse the options with the args" do
|
133
|
-
result = mock("result")
|
134
|
-
@option_parser.expects(:parse!).with(@args).once.returns(result)
|
135
|
-
assert_equal result, @instance.parse_options(@args)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|