vagrant 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +10 -0
  2. data/CHANGELOG.md +48 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +49 -0
  5. data/README.md +2 -2
  6. data/Rakefile +22 -0
  7. data/bin/.gitignore +0 -0
  8. data/lib/vagrant/provisioners/chef_solo.rb +1 -1
  9. data/lib/vagrant/util/template_renderer.rb +2 -2
  10. data/lib/vagrant/version.rb +1 -1
  11. data/templates/Vagrantfile.erb +1 -1
  12. data/templates/nfs/exports.erb +4 -2
  13. data/test/test_helper.rb +128 -0
  14. data/test/vagrant/action/box/destroy_test.rb +30 -0
  15. data/test/vagrant/action/box/download_test.rb +141 -0
  16. data/test/vagrant/action/box/package_test.rb +25 -0
  17. data/test/vagrant/action/box/unpackage_test.rb +103 -0
  18. data/test/vagrant/action/box/verify_test.rb +39 -0
  19. data/test/vagrant/action/builder_test.rb +218 -0
  20. data/test/vagrant/action/env/error_halt_test.rb +21 -0
  21. data/test/vagrant/action/env/set_test.rb +24 -0
  22. data/test/vagrant/action/environment_test.rb +45 -0
  23. data/test/vagrant/action/exception_catcher_test.rb +30 -0
  24. data/test/vagrant/action/general/package_test.rb +254 -0
  25. data/test/vagrant/action/vm/boot_test.rb +83 -0
  26. data/test/vagrant/action/vm/check_box_test.rb +48 -0
  27. data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
  28. data/test/vagrant/action/vm/clean_machine_folder_test.rb +82 -0
  29. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
  30. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
  31. data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
  32. data/test/vagrant/action/vm/customize_test.rb +29 -0
  33. data/test/vagrant/action/vm/destroy_test.rb +26 -0
  34. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +46 -0
  35. data/test/vagrant/action/vm/disable_networks_test.rb +39 -0
  36. data/test/vagrant/action/vm/discard_state_test.rb +36 -0
  37. data/test/vagrant/action/vm/export_test.rb +135 -0
  38. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
  39. data/test/vagrant/action/vm/forward_ports_test.rb +191 -0
  40. data/test/vagrant/action/vm/halt_test.rb +69 -0
  41. data/test/vagrant/action/vm/import_test.rb +50 -0
  42. data/test/vagrant/action/vm/match_mac_address_test.rb +28 -0
  43. data/test/vagrant/action/vm/network_test.rb +246 -0
  44. data/test/vagrant/action/vm/nfs_helpers_test.rb +23 -0
  45. data/test/vagrant/action/vm/nfs_test.rb +269 -0
  46. data/test/vagrant/action/vm/package_test.rb +25 -0
  47. data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
  48. data/test/vagrant/action/vm/persist_test.rb +50 -0
  49. data/test/vagrant/action/vm/provision_test.rb +134 -0
  50. data/test/vagrant/action/vm/resume_test.rb +35 -0
  51. data/test/vagrant/action/vm/share_folders_test.rb +215 -0
  52. data/test/vagrant/action/vm/suspend_test.rb +35 -0
  53. data/test/vagrant/action_test.rb +111 -0
  54. data/test/vagrant/active_list_test.rb +173 -0
  55. data/test/vagrant/box_test.rb +166 -0
  56. data/test/vagrant/command_test.rb +53 -0
  57. data/test/vagrant/commands/base_test.rb +139 -0
  58. data/test/vagrant/commands/box/add_test.rb +34 -0
  59. data/test/vagrant/commands/box/list_test.rb +32 -0
  60. data/test/vagrant/commands/box/remove_test.rb +41 -0
  61. data/test/vagrant/commands/box/repackage_test.rb +52 -0
  62. data/test/vagrant/commands/destroy_test.rb +44 -0
  63. data/test/vagrant/commands/halt_test.rb +50 -0
  64. data/test/vagrant/commands/init_test.rb +71 -0
  65. data/test/vagrant/commands/package_test.rb +97 -0
  66. data/test/vagrant/commands/provision_test.rb +60 -0
  67. data/test/vagrant/commands/reload_test.rb +47 -0
  68. data/test/vagrant/commands/resume_test.rb +44 -0
  69. data/test/vagrant/commands/ssh_config_test.rb +77 -0
  70. data/test/vagrant/commands/ssh_test.rb +129 -0
  71. data/test/vagrant/commands/status_test.rb +40 -0
  72. data/test/vagrant/commands/suspend_test.rb +44 -0
  73. data/test/vagrant/commands/up_test.rb +49 -0
  74. data/test/vagrant/config_test.rb +307 -0
  75. data/test/vagrant/downloaders/base_test.rb +28 -0
  76. data/test/vagrant/downloaders/file_test.rb +33 -0
  77. data/test/vagrant/downloaders/http_test.rb +70 -0
  78. data/test/vagrant/environment_test.rb +770 -0
  79. data/test/vagrant/hosts/base_test.rb +46 -0
  80. data/test/vagrant/hosts/bsd_test.rb +56 -0
  81. data/test/vagrant/hosts/linux_test.rb +56 -0
  82. data/test/vagrant/provisioners/base_test.rb +36 -0
  83. data/test/vagrant/provisioners/chef_server_test.rb +182 -0
  84. data/test/vagrant/provisioners/chef_solo_test.rb +197 -0
  85. data/test/vagrant/provisioners/chef_test.rb +178 -0
  86. data/test/vagrant/ssh_session_test.rb +46 -0
  87. data/test/vagrant/ssh_test.rb +317 -0
  88. data/test/vagrant/systems/linux_test.rb +179 -0
  89. data/test/vagrant/util/busy_test.rb +106 -0
  90. data/test/vagrant/util/plain_logger_test.rb +17 -0
  91. data/test/vagrant/util/platform_test.rb +18 -0
  92. data/test/vagrant/util/resource_logger_test.rb +145 -0
  93. data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
  94. data/test/vagrant/util/template_renderer_test.rb +145 -0
  95. data/test/vagrant/util/translator_test.rb +61 -0
  96. data/test/vagrant/util_test.rb +27 -0
  97. data/test/vagrant/vm_test.rb +228 -0
  98. data/vagrant.gemspec +34 -0
  99. metadata +158 -43
@@ -0,0 +1,166 @@
1
+ require "test_helper"
2
+
3
+ class BoxTest < Test::Unit::TestCase
4
+ context "class methods" do
5
+ setup do
6
+ @env = mock_environment
7
+ end
8
+
9
+ context "listing all boxes" do
10
+ setup do
11
+ Dir.stubs(:open)
12
+ File.stubs(:directory?).returns(true)
13
+
14
+ @boxes_path = "foo"
15
+ @env.stubs(:boxes_path).returns(@boxes_path)
16
+ end
17
+
18
+ should "open the boxes directory" do
19
+ Dir.expects(:open).with(@env.boxes_path)
20
+ Vagrant::Box.all(@env)
21
+ end
22
+
23
+ should "return an array" do
24
+ result = Vagrant::Box.all(@env)
25
+ assert result.is_a?(Array)
26
+ end
27
+
28
+ should "not return the '.' and '..' directories" do
29
+ dir = [".", "..", "..", ".", ".."]
30
+ Dir.expects(:open).yields(dir)
31
+ result = Vagrant::Box.all(@env)
32
+ assert result.empty?
33
+ end
34
+
35
+ should "return the other directories" do
36
+ dir = [".", "foo", "bar", "baz"]
37
+ Dir.expects(:open).yields(dir)
38
+ result = Vagrant::Box.all(@env)
39
+ assert_equal ["foo", "bar", "baz"], result
40
+ end
41
+
42
+ should "ignore the files" do
43
+ dir = ["foo", "bar"]
44
+ files = [true, false]
45
+ Dir.expects(:open).yields(dir)
46
+ dir_sequence = sequence("directory")
47
+ dir.each_with_index do |dir, index|
48
+ File.expects(:directory?).with(File.join(@boxes_path, dir)).returns(files[index]).in_sequence(dir_sequence)
49
+ end
50
+
51
+ result = Vagrant::Box.all(@env)
52
+ assert_equal ["foo"], result
53
+ end
54
+ end
55
+
56
+ context "finding" do
57
+ setup do
58
+ @dir = "foo"
59
+ @name = "bar"
60
+ Vagrant::Box.stubs(:directory).with(@env, @name).returns(@dir)
61
+ end
62
+
63
+ should "return nil if the box doesn't exist" do
64
+ File.expects(:directory?).with(@dir).once.returns(false)
65
+ assert_nil Vagrant::Box.find(@env, @name)
66
+ end
67
+
68
+ should "return a box object with the proper name set" do
69
+ File.expects(:directory?).with(@dir).once.returns(true)
70
+ result = Vagrant::Box.find(@env, @name)
71
+ assert result
72
+ assert_equal @name, result.name
73
+ end
74
+
75
+ should "return a box object with the proper env set" do
76
+ File.expects(:directory?).with(@dir).once.returns(true)
77
+ result = Vagrant::Box.find(@env, @name)
78
+ assert result
79
+ assert_equal @env, result.env
80
+ end
81
+ end
82
+
83
+ context "adding" do
84
+ setup do
85
+ @name = "foo"
86
+ @uri = "bar"
87
+ end
88
+
89
+ should "create a new instance, set the variables, and add it" do
90
+ box = mock("box")
91
+ box.expects(:name=).with(@name)
92
+ box.expects(:uri=).with(@uri)
93
+ box.expects(:env=).with(@env)
94
+ box.expects(:add).once
95
+ Vagrant::Box.expects(:new).returns(box)
96
+ Vagrant::Box.add(@env, @name, @uri)
97
+ end
98
+ end
99
+
100
+ context "box directory" do
101
+ setup do
102
+ @name = "foo"
103
+ @box_dir = File.join(@env.boxes_path, @name)
104
+ end
105
+
106
+ should "return the boxes_path joined with the name" do
107
+ assert_equal @box_dir, Vagrant::Box.directory(@env, @name)
108
+ end
109
+ end
110
+ end
111
+
112
+ context "instance methods" do
113
+ setup do
114
+ @box = Vagrant::Box.new
115
+ @box.env = mock_environment
116
+ end
117
+
118
+ should "execute the Add action when add is called" do
119
+ @box.env.actions.expects(:run).with(:box_add, { "box" => @box })
120
+ @box.add
121
+ end
122
+
123
+ context "box directory" do
124
+ setup do
125
+ @box.name = "foo"
126
+ end
127
+
128
+ should "return the boxes_path joined with the name" do
129
+ result = mock("object")
130
+ Vagrant::Box.expects(:directory).with(@box.env, @box.name).returns(result)
131
+ assert result.equal?(@box.directory)
132
+ end
133
+ end
134
+
135
+ context "destroying" do
136
+ should "execute the destroy action" do
137
+ @box.env.actions.expects(:run).with(:box_remove, { "box" => @box })
138
+ @box.destroy
139
+ end
140
+ end
141
+
142
+ context "repackaging" do
143
+ should "execute the repackage action" do
144
+ @box.env.actions.expects(:run).with(:box_repackage, { "box" => @box })
145
+ @box.repackage
146
+ end
147
+
148
+ should "forward given options into the action" do
149
+ @box.env.actions.expects(:run).with(:box_repackage, { "box" => @box, "foo" => "bar" })
150
+ @box.repackage("foo" => "bar")
151
+ end
152
+ end
153
+
154
+ context "ovf file" do
155
+ setup do
156
+ @box.stubs(:directory).returns("foo")
157
+
158
+ @box.env.config.vm.box_ovf = "foo.ovf"
159
+ end
160
+
161
+ should "be the directory joined with the config ovf file" do
162
+ assert_equal File.join(@box.directory, @box.env.config.vm.box_ovf), @box.ovf_file
163
+ end
164
+ end
165
+ end
166
+ end
@@ -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