vagrantup 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/CHANGELOG.md +48 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +49 -0
- data/README.md +2 -2
- data/Rakefile +22 -0
- data/bin/.gitignore +0 -0
- data/lib/vagrant/provisioners/chef_solo.rb +1 -1
- data/lib/vagrant/util/template_renderer.rb +2 -2
- data/lib/vagrant/version.rb +1 -1
- data/templates/Vagrantfile.erb +1 -1
- data/templates/nfs/exports.erb +4 -2
- data/test/test_helper.rb +128 -0
- data/test/vagrant/action/box/destroy_test.rb +30 -0
- data/test/vagrant/action/box/download_test.rb +141 -0
- data/test/vagrant/action/box/package_test.rb +25 -0
- data/test/vagrant/action/box/unpackage_test.rb +103 -0
- data/test/vagrant/action/box/verify_test.rb +39 -0
- data/test/vagrant/action/builder_test.rb +218 -0
- data/test/vagrant/action/env/error_halt_test.rb +21 -0
- data/test/vagrant/action/env/set_test.rb +24 -0
- data/test/vagrant/action/environment_test.rb +45 -0
- data/test/vagrant/action/exception_catcher_test.rb +30 -0
- data/test/vagrant/action/general/package_test.rb +254 -0
- data/test/vagrant/action/vm/boot_test.rb +83 -0
- data/test/vagrant/action/vm/check_box_test.rb +48 -0
- data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/vagrant/action/vm/clean_machine_folder_test.rb +82 -0
- data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
- data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
- data/test/vagrant/action/vm/customize_test.rb +29 -0
- data/test/vagrant/action/vm/destroy_test.rb +26 -0
- data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +46 -0
- data/test/vagrant/action/vm/disable_networks_test.rb +39 -0
- data/test/vagrant/action/vm/discard_state_test.rb +36 -0
- data/test/vagrant/action/vm/export_test.rb +135 -0
- data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
- data/test/vagrant/action/vm/forward_ports_test.rb +191 -0
- data/test/vagrant/action/vm/halt_test.rb +69 -0
- data/test/vagrant/action/vm/import_test.rb +50 -0
- data/test/vagrant/action/vm/match_mac_address_test.rb +28 -0
- data/test/vagrant/action/vm/network_test.rb +246 -0
- data/test/vagrant/action/vm/nfs_helpers_test.rb +23 -0
- data/test/vagrant/action/vm/nfs_test.rb +269 -0
- data/test/vagrant/action/vm/package_test.rb +25 -0
- data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/vagrant/action/vm/persist_test.rb +50 -0
- data/test/vagrant/action/vm/provision_test.rb +134 -0
- data/test/vagrant/action/vm/resume_test.rb +35 -0
- data/test/vagrant/action/vm/share_folders_test.rb +215 -0
- data/test/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/vagrant/action_test.rb +111 -0
- data/test/vagrant/active_list_test.rb +173 -0
- data/test/vagrant/box_test.rb +166 -0
- data/test/vagrant/command_test.rb +53 -0
- data/test/vagrant/commands/base_test.rb +139 -0
- data/test/vagrant/commands/box/add_test.rb +34 -0
- data/test/vagrant/commands/box/list_test.rb +32 -0
- data/test/vagrant/commands/box/remove_test.rb +41 -0
- data/test/vagrant/commands/box/repackage_test.rb +52 -0
- data/test/vagrant/commands/destroy_test.rb +44 -0
- data/test/vagrant/commands/halt_test.rb +50 -0
- data/test/vagrant/commands/init_test.rb +71 -0
- data/test/vagrant/commands/package_test.rb +97 -0
- data/test/vagrant/commands/provision_test.rb +60 -0
- data/test/vagrant/commands/reload_test.rb +47 -0
- data/test/vagrant/commands/resume_test.rb +44 -0
- data/test/vagrant/commands/ssh_config_test.rb +77 -0
- data/test/vagrant/commands/ssh_test.rb +129 -0
- data/test/vagrant/commands/status_test.rb +40 -0
- data/test/vagrant/commands/suspend_test.rb +44 -0
- data/test/vagrant/commands/up_test.rb +49 -0
- data/test/vagrant/config_test.rb +307 -0
- data/test/vagrant/downloaders/base_test.rb +28 -0
- data/test/vagrant/downloaders/file_test.rb +33 -0
- data/test/vagrant/downloaders/http_test.rb +70 -0
- data/test/vagrant/environment_test.rb +770 -0
- data/test/vagrant/hosts/base_test.rb +46 -0
- data/test/vagrant/hosts/bsd_test.rb +56 -0
- data/test/vagrant/hosts/linux_test.rb +56 -0
- data/test/vagrant/provisioners/base_test.rb +36 -0
- data/test/vagrant/provisioners/chef_server_test.rb +182 -0
- data/test/vagrant/provisioners/chef_solo_test.rb +197 -0
- data/test/vagrant/provisioners/chef_test.rb +178 -0
- data/test/vagrant/ssh_session_test.rb +46 -0
- data/test/vagrant/ssh_test.rb +317 -0
- data/test/vagrant/systems/linux_test.rb +179 -0
- data/test/vagrant/util/busy_test.rb +106 -0
- data/test/vagrant/util/plain_logger_test.rb +17 -0
- data/test/vagrant/util/platform_test.rb +18 -0
- data/test/vagrant/util/resource_logger_test.rb +145 -0
- data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/vagrant/util/template_renderer_test.rb +145 -0
- data/test/vagrant/util/translator_test.rb +61 -0
- data/test/vagrant/util_test.rb +27 -0
- data/test/vagrant/vm_test.rb +228 -0
- data/vagrant.gemspec +34 -0
- metadata +130 -9
|
@@ -0,0 +1,53 @@
|
|
|
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
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CommandsBoxAddTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Commands::Box::Add
|
|
6
|
+
|
|
7
|
+
@persisted_vm = mock("persisted_vm")
|
|
8
|
+
@persisted_vm.stubs(:execute!)
|
|
9
|
+
|
|
10
|
+
@env = mock_environment
|
|
11
|
+
@env.stubs(:require_persisted_vm)
|
|
12
|
+
@env.stubs(:vm).returns(@persisted_vm)
|
|
13
|
+
|
|
14
|
+
@instance = @klass.new(@env)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "executing" do
|
|
18
|
+
setup do
|
|
19
|
+
@name = "foo"
|
|
20
|
+
@path = "bar"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
should "execute the add action with the name and path" do
|
|
24
|
+
Vagrant::Box.expects(:add).with(@env, @name, @path).once
|
|
25
|
+
@instance.execute([@name, @path])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should "show help if not enough arguments" do
|
|
29
|
+
Vagrant::Box.expects(:add).never
|
|
30
|
+
@instance.expects(:show_help).once
|
|
31
|
+
@instance.execute([])
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CommandsBoxListTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Commands::Box::List
|
|
6
|
+
|
|
7
|
+
@persisted_vm = mock("persisted_vm")
|
|
8
|
+
@persisted_vm.stubs(:execute!)
|
|
9
|
+
|
|
10
|
+
@env = mock_environment
|
|
11
|
+
@env.stubs(:require_persisted_vm)
|
|
12
|
+
@env.stubs(:vm).returns(@persisted_vm)
|
|
13
|
+
|
|
14
|
+
@instance = @klass.new(@env)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "executing" do
|
|
18
|
+
setup do
|
|
19
|
+
@boxes = ["foo", "bar"]
|
|
20
|
+
|
|
21
|
+
Vagrant::Box.stubs(:all).returns(@boxes)
|
|
22
|
+
@instance.stubs(:wrap_output)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
should "call all on box and sort the results" do
|
|
26
|
+
@all = mock("all")
|
|
27
|
+
@all.expects(:sort).returns(@boxes)
|
|
28
|
+
Vagrant::Box.expects(:all).with(@env).returns(@all)
|
|
29
|
+
@instance.execute
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CommandsBoxRemoveTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Commands::Box::Remove
|
|
6
|
+
|
|
7
|
+
@persisted_vm = mock("persisted_vm")
|
|
8
|
+
@persisted_vm.stubs(:execute!)
|
|
9
|
+
|
|
10
|
+
@env = mock_environment
|
|
11
|
+
@env.stubs(:require_persisted_vm)
|
|
12
|
+
@env.stubs(:vm).returns(@persisted_vm)
|
|
13
|
+
|
|
14
|
+
@instance = @klass.new(@env)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "executing" do
|
|
18
|
+
setup do
|
|
19
|
+
@name = "foo"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
should "show help if not enough arguments" do
|
|
23
|
+
Vagrant::Box.expects(:find).never
|
|
24
|
+
@instance.expects(:show_help).once
|
|
25
|
+
@instance.execute([])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should "error and exit if the box doesn't exist" do
|
|
29
|
+
Vagrant::Box.expects(:find).returns(nil)
|
|
30
|
+
@instance.expects(:error_and_exit).with(:box_remove_doesnt_exist).once
|
|
31
|
+
@instance.execute([@name])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
should "call destroy on the box if it exists" do
|
|
35
|
+
@box = mock("box")
|
|
36
|
+
Vagrant::Box.expects(:find).with(@env, @name).returns(@box)
|
|
37
|
+
@box.expects(:destroy).once
|
|
38
|
+
@instance.execute([@name])
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CommandsBoxRepackageTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Commands::Box::Repackage
|
|
6
|
+
|
|
7
|
+
@persisted_vm = mock("persisted_vm")
|
|
8
|
+
@persisted_vm.stubs(:execute!)
|
|
9
|
+
|
|
10
|
+
@env = mock_environment
|
|
11
|
+
@env.stubs(:require_persisted_vm)
|
|
12
|
+
@env.stubs(:vm).returns(@persisted_vm)
|
|
13
|
+
|
|
14
|
+
@instance = @klass.new(@env)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "executing" do
|
|
18
|
+
setup do
|
|
19
|
+
@name = "foo"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
should "show help if not enough arguments" do
|
|
23
|
+
Vagrant::Box.expects(:find).never
|
|
24
|
+
@instance.expects(:show_help).once
|
|
25
|
+
@instance.execute(["--include", "x,y,z"])
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should "error and exit if the box doesn't exist" do
|
|
29
|
+
Vagrant::Box.expects(:find).returns(nil)
|
|
30
|
+
@instance.expects(:error_and_exit).with(:box_repackage_doesnt_exist).once
|
|
31
|
+
@instance.execute([@name])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
should "call repackage on the box if it exists" do
|
|
35
|
+
@box = mock("box")
|
|
36
|
+
Vagrant::Box.expects(:find).with(@env, @name).returns(@box)
|
|
37
|
+
@box.expects(:repackage).once
|
|
38
|
+
@instance.execute([@name])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
should "pass given options into repackage" do
|
|
42
|
+
@box = mock("box")
|
|
43
|
+
Vagrant::Box.expects(:find).with(@env, @name).returns(@box)
|
|
44
|
+
@box.expects(:repackage).once.with() do |opts|
|
|
45
|
+
assert opts.is_a?(Hash)
|
|
46
|
+
assert_equal "filename.box", opts["package.output"]
|
|
47
|
+
true
|
|
48
|
+
end
|
|
49
|
+
@instance.execute([@name, "--output", "filename.box"])
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CommandsDestroyTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Commands::Destroy
|
|
6
|
+
|
|
7
|
+
@env = mock_environment
|
|
8
|
+
|
|
9
|
+
@instance = @klass.new(@env)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "executing" do
|
|
13
|
+
should "call all or single for the method" do
|
|
14
|
+
@instance.expects(:all_or_single).with([], :destroy)
|
|
15
|
+
@instance.execute
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "destroying a single VM" do
|
|
20
|
+
setup do
|
|
21
|
+
@foo_vm = mock("vm")
|
|
22
|
+
@foo_vm.stubs(:env).returns(@env)
|
|
23
|
+
vms = { :foo => @foo_vm }
|
|
24
|
+
@env.stubs(:vms).returns(vms)
|
|
25
|
+
end
|
|
26
|
+
should "error and exit if the VM doesn't exist" do
|
|
27
|
+
@env.stubs(:vms).returns({})
|
|
28
|
+
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once
|
|
29
|
+
@instance.destroy_single(:foo)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
should "destroy if its created" do
|
|
33
|
+
@foo_vm.stubs(:created?).returns(true)
|
|
34
|
+
@foo_vm.expects(:destroy).once
|
|
35
|
+
@instance.destroy_single(:foo)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
should "do nothing if its not created" do
|
|
39
|
+
@foo_vm.stubs(:created?).returns(false)
|
|
40
|
+
@foo_vm.expects(:destroy).never
|
|
41
|
+
@instance.destroy_single(:foo)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CommandsHaltTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Commands::Halt
|
|
6
|
+
|
|
7
|
+
@env = mock_environment
|
|
8
|
+
@instance = @klass.new(@env)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "executing" do
|
|
12
|
+
should "call all or single for the method" do
|
|
13
|
+
@instance.expects(:all_or_single).with([], :halt)
|
|
14
|
+
@instance.execute
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "halting a single VM" do
|
|
19
|
+
setup do
|
|
20
|
+
@foo_vm = mock("vm")
|
|
21
|
+
@foo_vm.stubs(:env).returns(@env)
|
|
22
|
+
vms = { :foo => @foo_vm }
|
|
23
|
+
@env.stubs(:vms).returns(vms)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
should "error and exit if the VM doesn't exist" do
|
|
27
|
+
@env.stubs(:vms).returns({})
|
|
28
|
+
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once
|
|
29
|
+
@instance.halt_single(:foo)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
should "halt if its created" do
|
|
33
|
+
@foo_vm.stubs(:created?).returns(true)
|
|
34
|
+
@foo_vm.expects(:halt).with(:force => false).once
|
|
35
|
+
@instance.execute(["foo"])
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
should "halt and force if specified" do
|
|
39
|
+
@foo_vm.stubs(:created?).returns(true)
|
|
40
|
+
@foo_vm.expects(:halt).with(:force => true).once
|
|
41
|
+
@instance.execute(["foo", "--force"])
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
should "do nothing if its not created" do
|
|
45
|
+
@foo_vm.stubs(:created?).returns(false)
|
|
46
|
+
@foo_vm.expects(:halt).never
|
|
47
|
+
@instance.halt_single(:foo)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CommandsInitTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Commands::Init
|
|
6
|
+
|
|
7
|
+
@env = mock_environment
|
|
8
|
+
@instance = @klass.new(@env)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "execute" do
|
|
12
|
+
should "create a vagrant file without any args" do
|
|
13
|
+
args = []
|
|
14
|
+
@instance.expects(:create_vagrantfile).with(:default_box => nil, :default_box_url => nil)
|
|
15
|
+
@instance.execute(args)
|
|
16
|
+
end
|
|
17
|
+
context "when any arg is provided" do
|
|
18
|
+
should "create the vagrant file using the first arg as default_box and the second as default_box_url" do
|
|
19
|
+
args = []
|
|
20
|
+
args[0] = "foo"
|
|
21
|
+
args[1] = "foo.box"
|
|
22
|
+
|
|
23
|
+
@instance.expects(:create_vagrantfile).with(:default_box => "foo", :default_box_url => "foo.box")
|
|
24
|
+
@instance.execute(args)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "creating the vagrantfile" do
|
|
30
|
+
setup do
|
|
31
|
+
@file = mock("file")
|
|
32
|
+
@file.stubs(:write)
|
|
33
|
+
File.stubs(:open).yields(@file)
|
|
34
|
+
@rootfile_path = File.join(Dir.pwd, Vagrant::Environment::ROOTFILE_NAME)
|
|
35
|
+
|
|
36
|
+
Vagrant::Util::TemplateRenderer.stubs(:render)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
should "error and exit if a rootfile already exists" do
|
|
40
|
+
File.expects(:exist?).with(@rootfile_path).returns(true)
|
|
41
|
+
@instance.expects(:error_and_exit).with(:rootfile_already_exists).once
|
|
42
|
+
@instance.create_vagrantfile
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
should "write to the rootfile path using the template renderer" do
|
|
46
|
+
result = "foo"
|
|
47
|
+
Vagrant::Util::TemplateRenderer.expects(:render).returns(result).once
|
|
48
|
+
@file.expects(:write).with(result).once
|
|
49
|
+
File.expects(:open).with(@rootfile_path, 'w+').yields(@file)
|
|
50
|
+
|
|
51
|
+
@instance.create_vagrantfile
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
should "use the given base box if given" do
|
|
55
|
+
box = "zooo"
|
|
56
|
+
Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => box)
|
|
57
|
+
@instance.create_vagrantfile :default_box => box
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
should "use the box_url if given" do
|
|
61
|
+
box_url = "fubar.box"
|
|
62
|
+
Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => "base", :default_box_url => "fubar.box")
|
|
63
|
+
@instance.create_vagrantfile :default_box_url => box_url
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
should "use the default `base` if no box is given" do
|
|
67
|
+
Vagrant::Util::TemplateRenderer.expects(:render).with(Vagrant::Environment::ROOTFILE_NAME, :default_box => "base")
|
|
68
|
+
@instance.create_vagrantfile
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CommandsPackageTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Commands::Package
|
|
6
|
+
|
|
7
|
+
@env = mock_environment
|
|
8
|
+
@instance = @klass.new(@env)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "executing" do
|
|
12
|
+
should "package base if a base is given" do
|
|
13
|
+
@instance.expects(:package_base).once
|
|
14
|
+
@instance.execute(["--base","foo"])
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
should "package single if no name is given" do
|
|
18
|
+
@instance.expects(:package_single).with(nil).once
|
|
19
|
+
@instance.execute
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
should "package single if a name is given" do
|
|
23
|
+
@instance.expects(:package_single).with("foo").once
|
|
24
|
+
@instance.execute(["foo"])
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "packaging base" do
|
|
29
|
+
should "error and exit if no VM is found" do
|
|
30
|
+
Vagrant::VM.expects(:find).with("foo", @instance.env).returns(nil)
|
|
31
|
+
@instance.expects(:error_and_exit).with(:vm_base_not_found, :name => "foo").once
|
|
32
|
+
@instance.execute(["--base", "foo"])
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
should "package the VM like any other VM" do
|
|
36
|
+
vm = mock("vm")
|
|
37
|
+
Vagrant::VM.expects(:find).with("foo", @instance.env).returns(vm)
|
|
38
|
+
@instance.expects(:package_vm).with(vm).once
|
|
39
|
+
@instance.execute(["--base", "foo"])
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "packaging a single VM" do
|
|
44
|
+
setup do
|
|
45
|
+
@vm = mock("vm")
|
|
46
|
+
@vm.stubs(:created?).returns(true)
|
|
47
|
+
|
|
48
|
+
@vms = {:bar => @vm}
|
|
49
|
+
@env.stubs(:vms).returns(@vms)
|
|
50
|
+
@env.stubs(:multivm?).returns(false)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
should "error and exit if no name is given in a multi-vm env" do
|
|
54
|
+
@env.stubs(:multivm?).returns(true)
|
|
55
|
+
@instance.expects(:error_and_exit).with(:package_multivm).once
|
|
56
|
+
@instance.package_single(nil)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
should "error and exit if the VM doesn't exist" do
|
|
60
|
+
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once
|
|
61
|
+
@instance.package_single(:foo)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
should "error and exit if the VM is not created" do
|
|
65
|
+
@vm.stubs(:created?).returns(false)
|
|
66
|
+
@instance.expects(:error_and_exit).with(:environment_not_created).once
|
|
67
|
+
@instance.package_single(:bar)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
should "use the first VM is no name is given in a single VM environment" do
|
|
71
|
+
@instance.expects(:package_vm).with(@vm).once
|
|
72
|
+
@instance.package_single(nil)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
should "package the VM" do
|
|
76
|
+
@instance.expects(:package_vm).with(@vm).once
|
|
77
|
+
@instance.package_single(:bar)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context "packaging a VM" do
|
|
82
|
+
setup do
|
|
83
|
+
@vm = mock("vm")
|
|
84
|
+
|
|
85
|
+
@options = {}
|
|
86
|
+
@instance.stubs(:options).returns(@options)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
should "package the VM with the proper arguments" do
|
|
90
|
+
@options[:output] = "foo.box"
|
|
91
|
+
@options[:include] = :bar
|
|
92
|
+
|
|
93
|
+
@vm.expects(:package).with(@options).once
|
|
94
|
+
@instance.package_vm(@vm)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class CommandsProvisionTest < Test::Unit::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@klass = Vagrant::Commands::Provision
|
|
6
|
+
@env = mock_environment
|
|
7
|
+
@instance = @klass.new(@env)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "executing" do
|
|
11
|
+
should "provision all if no name is given" do
|
|
12
|
+
@instance.expects(:all_or_single).with([], :provision).once
|
|
13
|
+
@instance.execute
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "provisioning a single VM" do
|
|
18
|
+
setup do
|
|
19
|
+
@foo_vm = mock("vm")
|
|
20
|
+
@foo_vm.stubs(:env).returns(@env)
|
|
21
|
+
@foo_vm.stubs(:created?).returns(true)
|
|
22
|
+
|
|
23
|
+
@vm_for_real = mock("vm for real")
|
|
24
|
+
@foo_vm.stubs(:vm).returns(@vm_for_real)
|
|
25
|
+
vms = { :foo => @foo_vm }
|
|
26
|
+
@env.stubs(:vms).returns(vms)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
should "error and exit if the VM doesn't exist" do
|
|
30
|
+
@env.stubs(:vms).returns({})
|
|
31
|
+
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => 'foo').once
|
|
32
|
+
@instance.execute(["foo"])
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
should "reload if it's running" do
|
|
36
|
+
@vm_for_real.stubs(:running?).returns(true)
|
|
37
|
+
@foo_vm.expects(:provision).once
|
|
38
|
+
@instance.execute(["foo"])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
should "do log to info if it's not running" do
|
|
42
|
+
logger = mock("logger")
|
|
43
|
+
logger.expects(:info)
|
|
44
|
+
@env.stubs(:logger).returns(logger)
|
|
45
|
+
@vm_for_real.stubs(:running?).returns(false)
|
|
46
|
+
@foo_vm.expects(:provision).never
|
|
47
|
+
@instance.execute(["foo"])
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
should "do log to info if it's not created" do
|
|
51
|
+
logger = mock("logger")
|
|
52
|
+
logger.expects(:info)
|
|
53
|
+
@env.stubs(:logger).returns(logger)
|
|
54
|
+
@foo_vm.stubs(:created?).returns(false)
|
|
55
|
+
@foo_vm.expects(:provision).never
|
|
56
|
+
@instance.execute(["foo"])
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|