vagrantup 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/vagrant +5 -13
- data/config/default.rb +1 -0
- data/keys/README.md +8 -1
- data/keys/vagrant.ppk +26 -0
- data/lib/vagrant.rb +3 -3
- data/lib/vagrant/actions/base.rb +15 -4
- data/lib/vagrant/actions/box/add.rb +1 -1
- data/lib/vagrant/actions/box/download.rb +72 -66
- data/lib/vagrant/actions/box/unpackage.rb +1 -4
- data/lib/vagrant/actions/runner.rb +1 -1
- data/lib/vagrant/actions/vm/boot.rb +5 -7
- data/lib/vagrant/actions/vm/customize.rb +2 -2
- data/lib/vagrant/actions/vm/destroy.rb +2 -2
- data/lib/vagrant/actions/vm/down.rb +7 -0
- data/lib/vagrant/actions/vm/export.rb +10 -4
- data/lib/vagrant/actions/vm/forward_ports.rb +5 -15
- data/lib/vagrant/actions/vm/halt.rb +5 -3
- data/lib/vagrant/actions/vm/import.rb +10 -3
- data/lib/vagrant/actions/vm/move_hard_drive.rb +1 -3
- data/lib/vagrant/actions/vm/package.rb +33 -10
- data/lib/vagrant/actions/vm/provision.rb +4 -4
- data/lib/vagrant/actions/vm/reload.rb +1 -1
- data/lib/vagrant/actions/vm/resume.rb +1 -1
- data/lib/vagrant/actions/vm/shared_folders.rb +7 -7
- data/lib/vagrant/actions/vm/start.rb +3 -2
- data/lib/vagrant/actions/vm/suspend.rb +2 -2
- data/lib/vagrant/actions/vm/up.rb +7 -17
- data/lib/vagrant/active_list.rb +52 -45
- data/lib/vagrant/box.rb +18 -11
- data/lib/vagrant/busy.rb +7 -0
- data/lib/vagrant/command.rb +27 -0
- data/lib/vagrant/commands/base.rb +163 -0
- data/lib/vagrant/commands/box.rb +16 -0
- data/lib/vagrant/commands/box/add.rb +24 -0
- data/lib/vagrant/commands/box/list.rb +30 -0
- data/lib/vagrant/commands/box/remove.rb +31 -0
- data/lib/vagrant/commands/destroy.rb +23 -0
- data/lib/vagrant/commands/down.rb +16 -0
- data/lib/vagrant/commands/halt.rb +23 -0
- data/lib/vagrant/commands/init.rb +32 -0
- data/lib/vagrant/commands/package.rb +46 -0
- data/lib/vagrant/commands/reload.rb +22 -0
- data/lib/vagrant/commands/resume.rb +22 -0
- data/lib/vagrant/commands/ssh.rb +22 -0
- data/lib/vagrant/commands/ssh_config.rb +30 -0
- data/lib/vagrant/commands/status.rb +58 -0
- data/lib/vagrant/commands/suspend.rb +23 -0
- data/lib/vagrant/commands/up.rb +26 -0
- data/lib/vagrant/config.rb +21 -11
- data/lib/vagrant/downloaders/file.rb +5 -5
- data/lib/vagrant/downloaders/http.rb +10 -15
- data/lib/vagrant/environment.rb +259 -0
- data/lib/vagrant/provisioners/base.rb +7 -0
- data/lib/vagrant/provisioners/chef.rb +24 -9
- data/lib/vagrant/provisioners/chef_server.rb +23 -48
- data/lib/vagrant/provisioners/chef_solo.rb +48 -22
- data/lib/vagrant/ssh.rb +95 -46
- data/lib/vagrant/util.rb +2 -2
- data/lib/vagrant/util/errors.rb +36 -0
- data/lib/vagrant/util/platform.rb +12 -0
- data/lib/vagrant/util/progress_meter.rb +33 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/vm.rb +1 -0
- data/templates/{Vagrantfile → Vagrantfile.erb} +2 -2
- data/templates/chef_server_client.erb +16 -0
- data/templates/chef_solo_solo.erb +4 -0
- data/templates/errors.yml +157 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/ssh_config.erb +7 -0
- data/test/test_helper.rb +12 -15
- data/test/vagrant/actions/box/add_test.rb +1 -2
- data/test/vagrant/actions/box/destroy_test.rb +0 -1
- data/test/vagrant/actions/box/download_test.rb +40 -15
- data/test/vagrant/actions/box/unpackage_test.rb +2 -3
- data/test/vagrant/actions/collection_test.rb +8 -5
- data/test/vagrant/actions/runner_test.rb +8 -6
- data/test/vagrant/actions/vm/boot_test.rb +12 -11
- data/test/vagrant/actions/vm/customize_test.rb +2 -3
- data/test/vagrant/actions/vm/destroy_test.rb +2 -3
- data/test/vagrant/actions/vm/down_test.rb +16 -3
- data/test/vagrant/actions/vm/export_test.rb +4 -5
- data/test/vagrant/actions/vm/forward_ports_test.rb +6 -5
- data/test/vagrant/actions/vm/halt_test.rb +8 -2
- data/test/vagrant/actions/vm/import_test.rb +5 -5
- data/test/vagrant/actions/vm/move_hard_drive_test.rb +4 -6
- data/test/vagrant/actions/vm/package_test.rb +60 -22
- data/test/vagrant/actions/vm/provision_test.rb +7 -16
- data/test/vagrant/actions/vm/reload_test.rb +3 -2
- data/test/vagrant/actions/vm/resume_test.rb +0 -1
- data/test/vagrant/actions/vm/shared_folders_test.rb +17 -12
- data/test/vagrant/actions/vm/start_test.rb +10 -3
- data/test/vagrant/actions/vm/suspend_test.rb +1 -2
- data/test/vagrant/actions/vm/up_test.rb +19 -11
- data/test/vagrant/active_list_test.rb +148 -129
- data/test/vagrant/box_test.rb +26 -14
- data/test/vagrant/busy_test.rb +15 -6
- data/test/vagrant/command_test.rb +53 -0
- data/test/vagrant/commands/base_test.rb +118 -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/destroy_test.rb +32 -0
- data/test/vagrant/commands/down_test.rb +17 -0
- data/test/vagrant/commands/halt_test.rb +28 -0
- data/test/vagrant/commands/init_test.rb +55 -0
- data/test/vagrant/commands/package_test.rb +84 -0
- data/test/vagrant/commands/reload_test.rb +28 -0
- data/test/vagrant/commands/resume_test.rb +33 -0
- data/test/vagrant/commands/ssh_config_test.rb +54 -0
- data/test/vagrant/commands/ssh_test.rb +32 -0
- data/test/vagrant/commands/status_test.rb +20 -0
- data/test/vagrant/commands/suspend_test.rb +33 -0
- data/test/vagrant/commands/up_test.rb +41 -0
- data/test/vagrant/config_test.rb +42 -17
- data/test/vagrant/downloaders/file_test.rb +7 -0
- data/test/vagrant/downloaders/http_test.rb +12 -0
- data/test/vagrant/environment_test.rb +595 -0
- data/test/vagrant/provisioners/base_test.rb +7 -1
- data/test/vagrant/provisioners/chef_server_test.rb +41 -51
- data/test/vagrant/provisioners/chef_solo_test.rb +93 -62
- data/test/vagrant/provisioners/chef_test.rb +61 -15
- data/test/vagrant/ssh_test.rb +166 -38
- data/test/vagrant/util/errors_test.rb +57 -0
- data/test/vagrant/util/progress_meter_test.rb +33 -0
- data/test/vagrant/{stacked_proc_runner_test.rb → util/stacked_proc_runner_test.rb} +3 -3
- data/test/vagrant/util/template_renderer_test.rb +138 -0
- data/test/vagrant/vm_test.rb +3 -2
- data/vagrant.gemspec +88 -33
- metadata +92 -49
- data/bin/vagrant-box +0 -34
- data/bin/vagrant-down +0 -27
- data/bin/vagrant-halt +0 -28
- data/bin/vagrant-init +0 -27
- data/bin/vagrant-package +0 -29
- data/bin/vagrant-reload +0 -29
- data/bin/vagrant-resume +0 -27
- data/bin/vagrant-ssh +0 -27
- data/bin/vagrant-status +0 -29
- data/bin/vagrant-suspend +0 -27
- data/bin/vagrant-up +0 -29
- data/lib/vagrant/commands.rb +0 -234
- data/lib/vagrant/env.rb +0 -189
- data/lib/vagrant/stacked_proc_runner.rb +0 -33
- data/test/vagrant/commands_test.rb +0 -269
- data/test/vagrant/env_test.rb +0 -418
data/test/vagrant/ssh_test.rb
CHANGED
@@ -1,124 +1,252 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
2
|
|
3
3
|
class SshTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
4
|
+
def mock_ssh
|
5
|
+
@env = mock_environment do |config|
|
6
|
+
yield config if block_given?
|
7
|
+
end
|
8
|
+
|
9
|
+
@ssh = Vagrant::SSH.new(@env)
|
6
10
|
end
|
7
11
|
|
8
|
-
context "connecting to SSH" do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
Vagrant::
|
12
|
+
context "connecting to external SSH" do
|
13
|
+
setup do
|
14
|
+
mock_ssh
|
15
|
+
@ssh.stubs(:check_key_permissions)
|
16
|
+
@ssh.stubs(:error_and_exit)
|
17
|
+
Kernel.stubs(:exec)
|
18
|
+
|
19
|
+
Vagrant::Util::Platform.stubs(:leopard?).returns(false)
|
16
20
|
end
|
17
21
|
|
18
|
-
|
22
|
+
should "check key permissions prior to exec" do
|
23
|
+
exec_seq = sequence("exec_seq")
|
24
|
+
@ssh.expects(:check_key_permissions).with(@env.config.ssh.private_key_path).once.in_sequence(exec_seq)
|
25
|
+
Kernel.expects(:exec).in_sequence(exec_seq)
|
26
|
+
@ssh.connect
|
27
|
+
end
|
28
|
+
|
29
|
+
should "call exec with defaults when no options are supplied" do
|
30
|
+
ssh_exec_expect(@ssh.port,
|
31
|
+
@env.config.ssh.private_key_path,
|
32
|
+
@env.config.ssh.username,
|
33
|
+
@env.config.ssh.host)
|
34
|
+
@ssh.connect
|
35
|
+
end
|
36
|
+
|
37
|
+
should "call exec with supplied params" do
|
19
38
|
args = {:username => 'bar', :private_key_path => 'baz', :host => 'bak', :port => 'bag'}
|
20
39
|
ssh_exec_expect(args[:port], args[:private_key_path], args[:username], args[:host])
|
21
|
-
|
40
|
+
@ssh.connect(args)
|
41
|
+
end
|
42
|
+
|
43
|
+
context "on leopard" do
|
44
|
+
setup do
|
45
|
+
Vagrant::Util::Platform.stubs(:leopard?).returns(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
should "fork, exec, and wait" do
|
49
|
+
pid = mock("pid")
|
50
|
+
@ssh.expects(:fork).once.returns(pid)
|
51
|
+
Process.expects(:wait).with(pid)
|
52
|
+
|
53
|
+
@ssh.connect
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "checking windows" do
|
58
|
+
should "error and exit if the platform is windows" do
|
59
|
+
Mario::Platform.expects(:windows?).returns(true)
|
60
|
+
@ssh.expects(:error_and_exit).with do |error_name, opts|
|
61
|
+
opts[:key_path] && opts[:ssh_port]
|
62
|
+
end
|
63
|
+
@ssh.connect
|
64
|
+
end
|
65
|
+
|
66
|
+
should "not error and exit if the platform is anything other that windows" do
|
67
|
+
Mario::Platform.expects(:windows?).returns(false)
|
68
|
+
@ssh.expects(:error_and_exit).never
|
69
|
+
@ssh.connect
|
70
|
+
end
|
22
71
|
end
|
23
72
|
|
24
73
|
def ssh_exec_expect(port, key_path, uname, host)
|
25
|
-
|
74
|
+
Kernel.expects(:exec).with() do |arg|
|
26
75
|
assert arg =~ /^ssh/
|
27
76
|
assert arg =~ /-p #{port}/
|
28
77
|
assert arg =~ /-i #{key_path}/
|
29
78
|
assert arg =~ /#{uname}@#{host}/
|
30
|
-
# TODO options not tested for as they may be removed
|
79
|
+
# TODO options not tested for as they may be removed
|
31
80
|
true
|
32
81
|
end
|
33
82
|
end
|
34
83
|
end
|
35
84
|
|
36
85
|
context "executing ssh commands" do
|
86
|
+
setup do
|
87
|
+
mock_ssh
|
88
|
+
end
|
89
|
+
|
37
90
|
should "call net::ssh.start with the proper names" do
|
38
91
|
Net::SSH.expects(:start).once.with() do |host, username, opts|
|
39
|
-
assert_equal
|
40
|
-
assert_equal
|
41
|
-
assert_equal
|
42
|
-
assert_equal [
|
92
|
+
assert_equal @env.config.ssh.host, host
|
93
|
+
assert_equal @env.config.ssh.username, username
|
94
|
+
assert_equal @ssh.port, opts[:port]
|
95
|
+
assert_equal [@env.config.ssh.private_key_path], opts[:keys]
|
43
96
|
true
|
44
97
|
end
|
45
|
-
|
98
|
+
@ssh.execute
|
46
99
|
end
|
47
100
|
|
48
101
|
should "use custom host if set" do
|
49
|
-
|
50
|
-
Net::SSH.expects(:start).with(
|
51
|
-
|
102
|
+
@env.config.ssh.host = "foo"
|
103
|
+
Net::SSH.expects(:start).with(@env.config.ssh.host, @env.config.ssh.username, anything).once
|
104
|
+
@ssh.execute
|
52
105
|
end
|
53
106
|
end
|
54
107
|
|
55
108
|
context "SCPing files to the remote host" do
|
109
|
+
setup do
|
110
|
+
mock_ssh
|
111
|
+
end
|
112
|
+
|
56
113
|
should "use Vagrant::SSH execute to setup an SCP connection and upload" do
|
57
114
|
scp = mock("scp")
|
58
115
|
ssh = mock("ssh")
|
59
116
|
scp.expects(:upload!).with("foo", "bar").once
|
60
117
|
Net::SCP.expects(:new).with(ssh).returns(scp).once
|
61
|
-
|
62
|
-
|
118
|
+
@ssh.expects(:execute).yields(ssh).once
|
119
|
+
@ssh.upload!("foo", "bar")
|
63
120
|
end
|
64
121
|
end
|
65
122
|
|
66
123
|
context "checking if host is up" do
|
67
124
|
setup do
|
68
|
-
|
125
|
+
mock_ssh
|
69
126
|
end
|
70
127
|
|
71
128
|
should "return true if SSH connection works" do
|
72
129
|
Net::SSH.expects(:start).yields("success")
|
73
|
-
assert
|
130
|
+
assert @ssh.up?
|
74
131
|
end
|
75
132
|
|
76
133
|
should "return false if SSH connection times out" do
|
77
134
|
Net::SSH.expects(:start)
|
78
|
-
assert
|
135
|
+
assert !@ssh.up?
|
79
136
|
end
|
80
137
|
|
81
138
|
should "allow the thread the configured timeout time" do
|
82
139
|
@thread = mock("thread")
|
83
140
|
@thread.stubs(:[])
|
84
141
|
Thread.expects(:new).returns(@thread)
|
85
|
-
@thread.expects(:join).with(
|
86
|
-
|
142
|
+
@thread.expects(:join).with(@env.config.ssh.timeout).once
|
143
|
+
@ssh.up?
|
87
144
|
end
|
88
145
|
|
89
146
|
should "return false if the connection is refused" do
|
90
147
|
Net::SSH.expects(:start).raises(Errno::ECONNREFUSED)
|
91
148
|
assert_nothing_raised {
|
92
|
-
assert
|
149
|
+
assert !@ssh.up?
|
93
150
|
}
|
94
151
|
end
|
95
152
|
|
96
153
|
should "return false if the connection is dropped" do
|
97
154
|
Net::SSH.expects(:start).raises(Net::SSH::Disconnect)
|
98
155
|
assert_nothing_raised {
|
99
|
-
assert
|
156
|
+
assert !@ssh.up?
|
100
157
|
}
|
101
158
|
end
|
102
159
|
|
103
160
|
should "specifity the timeout as an option to execute" do
|
104
|
-
|
105
|
-
assert
|
161
|
+
@ssh.expects(:execute).with(:timeout => @env.config.ssh.timeout).yields(true)
|
162
|
+
assert @ssh.up?
|
106
163
|
end
|
107
164
|
|
108
165
|
should "error and exit if a Net::SSH::AuthenticationFailed is raised" do
|
109
|
-
|
110
|
-
|
111
|
-
|
166
|
+
@ssh.expects(:execute).raises(Net::SSH::AuthenticationFailed)
|
167
|
+
@ssh.expects(:error_and_exit).with(:vm_ssh_auth_failed).once
|
168
|
+
@ssh.up?
|
112
169
|
end
|
113
170
|
end
|
114
171
|
|
115
172
|
context "getting the ssh port" do
|
173
|
+
setup do
|
174
|
+
mock_ssh
|
175
|
+
end
|
176
|
+
|
116
177
|
should "return the configured port by default" do
|
117
|
-
assert_equal
|
178
|
+
assert_equal @env.config.vm.forwarded_ports[@env.config.ssh.forwarded_port_key][:hostport], @ssh.port
|
118
179
|
end
|
119
180
|
|
120
181
|
should "return the port given in options if it exists" do
|
121
|
-
assert_equal "47",
|
182
|
+
assert_equal "47", @ssh.port({ :port => "47" })
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context "checking key permissions" do
|
187
|
+
setup do
|
188
|
+
mock_ssh
|
189
|
+
@ssh.stubs(:file_perms)
|
190
|
+
|
191
|
+
@key_path = "foo"
|
192
|
+
|
193
|
+
|
194
|
+
@stat = mock("stat")
|
195
|
+
@stat.stubs(:owned?).returns(true)
|
196
|
+
File.stubs(:stat).returns(@stat)
|
197
|
+
end
|
198
|
+
|
199
|
+
should "do nothing if the user is not the owner" do
|
200
|
+
@stat.expects(:owned?).returns(false)
|
201
|
+
File.expects(:chmod).never
|
202
|
+
@ssh.check_key_permissions(@key_path)
|
203
|
+
end
|
204
|
+
|
205
|
+
should "do nothing if the file perms equal 600" do
|
206
|
+
@ssh.expects(:file_perms).with(@key_path).returns("600")
|
207
|
+
File.expects(:chmod).never
|
208
|
+
@ssh.check_key_permissions(@key_path)
|
209
|
+
end
|
210
|
+
|
211
|
+
should "chmod the file if the file perms aren't 600" do
|
212
|
+
perm_sequence = sequence("perm_seq")
|
213
|
+
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
214
|
+
File.expects(:chmod).with(0600, @key_path).once.in_sequence(perm_sequence)
|
215
|
+
@ssh.expects(:file_perms).returns("600").in_sequence(perm_sequence)
|
216
|
+
@ssh.expects(:error_and_exit).never
|
217
|
+
@ssh.check_key_permissions(@key_path)
|
218
|
+
end
|
219
|
+
|
220
|
+
should "error and exit if the resulting chmod doesn't work" do
|
221
|
+
perm_sequence = sequence("perm_seq")
|
222
|
+
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
223
|
+
File.expects(:chmod).with(0600, @key_path).once.in_sequence(perm_sequence)
|
224
|
+
@ssh.expects(:file_perms).returns("900").in_sequence(perm_sequence)
|
225
|
+
@ssh.expects(:error_and_exit).once.with(:ssh_bad_permissions, :key_path => @key_path).in_sequence(perm_sequence)
|
226
|
+
@ssh.check_key_permissions(@key_path)
|
227
|
+
end
|
228
|
+
|
229
|
+
should "error and exit if a bad file perm is raised" do
|
230
|
+
@ssh.expects(:file_perms).with(@key_path).returns("900")
|
231
|
+
File.expects(:chmod).raises(Errno::EPERM)
|
232
|
+
@ssh.expects(:error_and_exit).once.with(:ssh_bad_permissions, :key_path => @key_path)
|
233
|
+
@ssh.check_key_permissions(@key_path)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context "getting file permissions" do
|
238
|
+
setup do
|
239
|
+
mock_ssh
|
240
|
+
end
|
241
|
+
|
242
|
+
should "return the last 3 characters of the file mode" do
|
243
|
+
path = "foo"
|
244
|
+
mode = "10000foo"
|
245
|
+
stat = mock("stat")
|
246
|
+
File.expects(:stat).with(path).returns(stat)
|
247
|
+
stat.expects(:mode).returns(mode)
|
248
|
+
@ssh.expects(:sprintf).with("%o", mode).returns(mode)
|
249
|
+
assert_equal path, @ssh.file_perms(path)
|
122
250
|
end
|
123
251
|
end
|
124
252
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class ErrorsUtilTest < Test::Unit::TestCase
|
4
|
+
include Vagrant::Util
|
5
|
+
|
6
|
+
context "loading the errors from the YML" do
|
7
|
+
setup do
|
8
|
+
YAML.stubs(:load_file)
|
9
|
+
Errors.reset!
|
10
|
+
end
|
11
|
+
|
12
|
+
should "load the file initially, then never again unless reset" do
|
13
|
+
YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "errors.yml")).once
|
14
|
+
Errors.errors
|
15
|
+
Errors.errors
|
16
|
+
Errors.errors
|
17
|
+
Errors.errors
|
18
|
+
end
|
19
|
+
|
20
|
+
should "reload if reset! is called" do
|
21
|
+
YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "errors.yml")).twice
|
22
|
+
Errors.errors
|
23
|
+
Errors.reset!
|
24
|
+
Errors.errors
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "getting the error string" do
|
29
|
+
setup do
|
30
|
+
@errors = {}
|
31
|
+
@errors[:foo] = "foo bar baz"
|
32
|
+
Errors.stubs(:errors).returns(@errors)
|
33
|
+
end
|
34
|
+
|
35
|
+
should "render the error string" do
|
36
|
+
TemplateRenderer.expects(:render_string).with(@errors[:foo], anything).once
|
37
|
+
Errors.error_string(:foo)
|
38
|
+
end
|
39
|
+
|
40
|
+
should "pass in any data entries" do
|
41
|
+
data = mock("data")
|
42
|
+
TemplateRenderer.expects(:render_string).with(@errors[:foo], data).once
|
43
|
+
Errors.error_string(:foo, data)
|
44
|
+
end
|
45
|
+
|
46
|
+
should "return the result of the render" do
|
47
|
+
result = mock("result")
|
48
|
+
TemplateRenderer.expects(:render_string).returns(result)
|
49
|
+
assert_equal result, Errors.error_string(:foo)
|
50
|
+
end
|
51
|
+
|
52
|
+
should "return an unknown if the key doesn't exist" do
|
53
|
+
result = Errors.error_string(:unknown)
|
54
|
+
assert result =~ /Unknown/i
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class ProgressMeterUtilTest < Test::Unit::TestCase
|
4
|
+
class TestProgressMeter
|
5
|
+
include Vagrant::Util::ProgressMeter
|
6
|
+
end
|
7
|
+
|
8
|
+
setup do
|
9
|
+
@instance = TestProgressMeter.new
|
10
|
+
|
11
|
+
Mario::Platform.logger(nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
context "on windows" do
|
15
|
+
setup do
|
16
|
+
Mario::Platform.forced = Mario::Platform::Windows7
|
17
|
+
end
|
18
|
+
|
19
|
+
should "just return \\r for the clear screen" do
|
20
|
+
assert_equal "\r", @instance.cl_reset
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "on other platforms" do
|
25
|
+
setup do
|
26
|
+
Mario::Platform.forced = Mario::Platform::Linux
|
27
|
+
end
|
28
|
+
|
29
|
+
should "return the full clear screen" do
|
30
|
+
assert_equal "\r\e[0K", @instance.cl_reset
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class
|
3
|
+
class StackedProcRunnerUtilTest < Test::Unit::TestCase
|
4
4
|
class TestClass
|
5
|
-
include Vagrant::StackedProcRunner
|
5
|
+
include Vagrant::Util::StackedProcRunner
|
6
6
|
end
|
7
7
|
|
8
8
|
setup do
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class TemplateRendererUtilTest < Test::Unit::TestCase
|
4
|
+
context "initializing" do
|
5
|
+
should "set the template to the given argument" do
|
6
|
+
r = Vagrant::Util::TemplateRenderer.new("foo")
|
7
|
+
assert_equal "foo", r.template
|
8
|
+
end
|
9
|
+
|
10
|
+
should "set any additional variables" do
|
11
|
+
r = Vagrant::Util::TemplateRenderer.new("foo", {:bar => :baz})
|
12
|
+
assert_equal :baz, r.bar
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "rendering" do
|
17
|
+
setup do
|
18
|
+
@template = "foo"
|
19
|
+
@r = Vagrant::Util::TemplateRenderer.new(@template)
|
20
|
+
@r.stubs(:full_template_path).returns(@template + "!")
|
21
|
+
|
22
|
+
@contents = "bar"
|
23
|
+
|
24
|
+
@file = mock("file")
|
25
|
+
@file.stubs(:read).returns(@contents)
|
26
|
+
File.stubs(:open).yields(@file)
|
27
|
+
end
|
28
|
+
|
29
|
+
should "open the template file for reading" do
|
30
|
+
File.expects(:open).with(@r.full_template_path, 'r').once
|
31
|
+
@r.render
|
32
|
+
end
|
33
|
+
|
34
|
+
should "set the template to the file contents, render, then set it back" do
|
35
|
+
result = "bar"
|
36
|
+
|
37
|
+
template_seq = sequence("template_seq")
|
38
|
+
@r.expects(:template=).with(@file.read).in_sequence(template_seq)
|
39
|
+
@r.expects(:render_string).returns(result).in_sequence(template_seq)
|
40
|
+
@r.expects(:template=).with(@template).in_sequence(template_seq)
|
41
|
+
assert_equal result, @r.render
|
42
|
+
end
|
43
|
+
|
44
|
+
should "render the ERB file in the context of the renderer" do
|
45
|
+
result = "bar"
|
46
|
+
template = "<%= foo %>"
|
47
|
+
@r.foo = result
|
48
|
+
@file.expects(:read).returns(template)
|
49
|
+
assert_equal result, @r.render
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "rendering as string" do
|
54
|
+
setup do
|
55
|
+
@result = "foo"
|
56
|
+
@erb = mock("erb")
|
57
|
+
@erb.stubs(:result).returns(@result)
|
58
|
+
|
59
|
+
@r = Vagrant::Util::TemplateRenderer.new("foo")
|
60
|
+
end
|
61
|
+
|
62
|
+
should "simply render the template as a string" do
|
63
|
+
ERB.expects(:new).with(@r.template).returns(@erb)
|
64
|
+
assert_equal @result, @r.render_string
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "the full template path" do
|
69
|
+
setup do
|
70
|
+
@template = "foo"
|
71
|
+
@r = Vagrant::Util::TemplateRenderer.new(@template)
|
72
|
+
end
|
73
|
+
|
74
|
+
should "be the ERB file in the templates directory" do
|
75
|
+
result = File.join(PROJECT_ROOT, "templates", "#{@template}.erb")
|
76
|
+
assert_equal result, @r.full_template_path
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "class methods" do
|
81
|
+
context "render_with method" do
|
82
|
+
setup do
|
83
|
+
@template = "foo"
|
84
|
+
@r = Vagrant::Util::TemplateRenderer.new(@template)
|
85
|
+
@r.stubs(:render)
|
86
|
+
|
87
|
+
@method = :rawr
|
88
|
+
|
89
|
+
Vagrant::Util::TemplateRenderer.stubs(:new).with(@template, {}).returns(@r)
|
90
|
+
end
|
91
|
+
|
92
|
+
should "use the second argument as the template" do
|
93
|
+
Vagrant::Util::TemplateRenderer.expects(:new).with(@template, {}).returns(@r)
|
94
|
+
Vagrant::Util::TemplateRenderer.render_with(@method, @template)
|
95
|
+
end
|
96
|
+
|
97
|
+
should "send in additional argument to the renderer" do
|
98
|
+
data = {:hey => :foo}
|
99
|
+
Vagrant::Util::TemplateRenderer.expects(:new).with(@template, data).returns(@r)
|
100
|
+
Vagrant::Util::TemplateRenderer.render_with(@method, @template, data)
|
101
|
+
end
|
102
|
+
|
103
|
+
should "yield a block if given with the renderer as the argument" do
|
104
|
+
@r.expects(:yielded=).with(true).once
|
105
|
+
Vagrant::Util::TemplateRenderer.render_with(@method, @template) do |r|
|
106
|
+
r.yielded = true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
should "render the result using the given method" do
|
111
|
+
result = mock('result')
|
112
|
+
@r.expects(@method).returns(result)
|
113
|
+
assert_equal result, Vagrant::Util::TemplateRenderer.render_with(@method, @template)
|
114
|
+
end
|
115
|
+
|
116
|
+
should "convert the given method to a sym prior to calling" do
|
117
|
+
@r.expects(@method.to_sym).returns(nil)
|
118
|
+
Vagrant::Util::TemplateRenderer.render_with(@method.to_s, @template)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "render method" do
|
123
|
+
should "call render_with the render! method" do
|
124
|
+
args = ["foo", "bar", "baz"]
|
125
|
+
Vagrant::Util::TemplateRenderer.expects(:render_with).with(:render, *args)
|
126
|
+
Vagrant::Util::TemplateRenderer.render(*args)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "render_string method" do
|
131
|
+
should "call render_with the render! method" do
|
132
|
+
args = ["foo", "bar", "baz"]
|
133
|
+
Vagrant::Util::TemplateRenderer.expects(:render_with).with(:render_string, *args)
|
134
|
+
Vagrant::Util::TemplateRenderer.render_string(*args)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|