tddium-old 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ require "tddium_loader.rb"
@@ -0,0 +1,110 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{tddium-old}
8
+ s.version = "0.4.7"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jay Moorthi"]
12
+ s.date = %q{2011-12-26}
13
+ s.default_executable = %q{tddium-old}
14
+ s.description = %q{tddium gets your rspec+selenium tests into the cloud by running them on your VMs}
15
+ s.email = %q{info@tddium.com}
16
+ s.executables = ["tddium-old"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "CHANGELOG",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "doc/aws-keypair-example.tiff",
31
+ "doc/aws-secgroup-example.tiff",
32
+ "lib/spec_storm/action_controller_ext.rb",
33
+ "lib/spec_storm/action_view_ext.rb",
34
+ "lib/spec_storm/active_record_ext.rb",
35
+ "lib/tddium.rb",
36
+ "lib/tddium/config.rb",
37
+ "lib/tddium/instance.rb",
38
+ "lib/tddium/parallel.rb",
39
+ "lib/tddium/rails.rb",
40
+ "lib/tddium/reporting.rb",
41
+ "lib/tddium/ssh.rb",
42
+ "lib/tddium/taskalias.rb",
43
+ "lib/tddium/tasks.rb",
44
+ "lib/tddium_helper.rb",
45
+ "lib/tddium_loader.rb",
46
+ "parallelrun",
47
+ "rails/init.rb",
48
+ "tddium-old.gemspec",
49
+ "test/helper.rb",
50
+ "test/test_config.rb",
51
+ "test/test_parallel.rb",
52
+ "test/test_tddium.rb"
53
+ ]
54
+ s.homepage = %q{http://www.tddium.com/}
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.6.2}
57
+ s.summary = %q{tddium Cloud Test Runner}
58
+ s.test_files = [
59
+ "test/helper.rb",
60
+ "test/test_config.rb",
61
+ "test/test_parallel.rb",
62
+ "test/test_tddium.rb"
63
+ ]
64
+
65
+ if s.respond_to? :specification_version then
66
+ s.specification_version = 3
67
+
68
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
69
+ s.add_runtime_dependency(%q<highline>, [">= 0"])
70
+ s.add_runtime_dependency(%q<rspec>, ["< 2.0.0", "> 1.2.6"])
71
+ s.add_runtime_dependency(%q<parallel>, [">= 0"])
72
+ s.add_runtime_dependency(%q<selenium-client>, [">= 1.2.18"])
73
+ s.add_runtime_dependency(%q<fog>, ["= 0.4.0"])
74
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
75
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
76
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
77
+ s.add_development_dependency(%q<rcov>, [">= 0"])
78
+ s.add_development_dependency(%q<mocha>, [">= 0"])
79
+ s.add_development_dependency(%q<fakefs>, [">= 0.3.1"])
80
+ s.add_development_dependency(%q<rails>, ["= 2.3.8"])
81
+ else
82
+ s.add_dependency(%q<highline>, [">= 0"])
83
+ s.add_dependency(%q<rspec>, ["< 2.0.0", "> 1.2.6"])
84
+ s.add_dependency(%q<parallel>, [">= 0"])
85
+ s.add_dependency(%q<selenium-client>, [">= 1.2.18"])
86
+ s.add_dependency(%q<fog>, ["= 0.4.0"])
87
+ s.add_dependency(%q<shoulda>, [">= 0"])
88
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
89
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
90
+ s.add_dependency(%q<rcov>, [">= 0"])
91
+ s.add_dependency(%q<mocha>, [">= 0"])
92
+ s.add_dependency(%q<fakefs>, [">= 0.3.1"])
93
+ s.add_dependency(%q<rails>, ["= 2.3.8"])
94
+ end
95
+ else
96
+ s.add_dependency(%q<highline>, [">= 0"])
97
+ s.add_dependency(%q<rspec>, ["< 2.0.0", "> 1.2.6"])
98
+ s.add_dependency(%q<parallel>, [">= 0"])
99
+ s.add_dependency(%q<selenium-client>, [">= 1.2.18"])
100
+ s.add_dependency(%q<fog>, ["= 0.4.0"])
101
+ s.add_dependency(%q<shoulda>, [">= 0"])
102
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
103
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
104
+ s.add_dependency(%q<rcov>, [">= 0"])
105
+ s.add_dependency(%q<mocha>, [">= 0"])
106
+ s.add_dependency(%q<fakefs>, [">= 0.3.1"])
107
+ s.add_dependency(%q<rails>, ["= 2.3.8"])
108
+ end
109
+ end
110
+
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'tddium'
16
+
17
+ class Test::Unit::TestCase
18
+ end
19
+
20
+ require 'fakefs'
21
+ class FakeFS::File::Stat
22
+ @@themode = 0600
23
+ def mode
24
+ return @@themode
25
+ end
26
+
27
+ def self.mode=(newmode)
28
+ @@themode = newmode
29
+ end
30
+ end
31
+
@@ -0,0 +1,194 @@
1
+ =begin
2
+ Copyright (c) 2010 tddium.com All Rights Reserved
3
+ =end
4
+
5
+ require 'helper'
6
+ require 'fakefs'
7
+ require 'fileutils'
8
+ require 'mocha'
9
+
10
+ class TestFileops < Test::Unit::TestCase
11
+ context "init task" do
12
+ setup do
13
+ @path = File.expand_path(get_config_paths[0])
14
+ end
15
+
16
+ context "when ~/.tddium doesn't exist" do
17
+ setup do
18
+ FakeFS::FileSystem.clear
19
+ HighLine.any_instance.stubs(:ask).returns('abc', 'def', 'ghi')
20
+ @keys = %w(aws_key aws_secret test_pattern key_directory key_name result_directory server_tag ssh_tunnel)
21
+ init_task
22
+ end
23
+
24
+ should "write ~/.tddium" do
25
+ assert File.exists?(@path), "#{@path} doesn't exist"
26
+ end
27
+
28
+ should "have the right contents" do
29
+ f = FakeFS::FileSystem.find(@path)
30
+ assert f.content.include?('abc'), "Should contain magic string"
31
+ @keys.each do |field|
32
+ assert f.content.include?(field), "Should contain #{field}"
33
+ end
34
+ end
35
+
36
+ should "write a YAML file with the right fields" do
37
+ result = YAML::load_file(@path)
38
+ @keys.each do |field|
39
+ assert result.has_key?(field.to_sym), "Should contain #{field}"
40
+ end
41
+ end
42
+ end
43
+
44
+ context "when ~/.tddium exists" do
45
+ setup do
46
+ File.new(@path, 'w').write('a')
47
+ end
48
+
49
+ should "print a warning message" do
50
+ HighLine.expects(:ask).never
51
+ init_task
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ class TestConfigRead < Test::Unit::TestCase
58
+ context "read config" do
59
+ context "file exists" do
60
+ setup do
61
+ @path = File.expand_path(get_config_paths[0])
62
+ end
63
+
64
+ should "read config file values into a dict" do
65
+ File.open(@path, 'w') do |f|
66
+ f.write <<EOF
67
+ ---
68
+ :aws_secret: abc
69
+ :aws_key: abx
70
+ :test_pattern: **/*_spec.rb
71
+ EOF
72
+ end
73
+ conf = read_config
74
+ assert_equal conf[:aws_key], 'abx'
75
+ assert_equal conf[:aws_secret], 'abc'
76
+ assert_equal conf[:test_pattern], '**/*_spec.rb'
77
+ end
78
+ end
79
+
80
+ context "file doesn't exist" do
81
+ should "return nils" do
82
+ conf = read_config
83
+ assert_nil conf[:aws_key]
84
+ assert_nil conf[:aws_secret]
85
+ end
86
+ end
87
+ end
88
+
89
+ context "find_config" do
90
+ should "check rails root if it's set" do
91
+ oldroot = ENV['RAILS_ROOT']
92
+ ENV['RAILS_ROOT'] = '/home/rails'
93
+ File.expects(:exists?).with('/home/rails/.tddium')
94
+ File.expects(:exists?).with(File.expand_path('~/.tddium'))
95
+ File.expects(:exists?).with('.tddium')
96
+ assert_nil find_config
97
+ ENV['RAILS_ROOT'] = oldroot
98
+ end
99
+
100
+ should "find rails root file if it's there" do
101
+ oldroot = ENV['RAILS_ROOT']
102
+ ENV['RAILS_ROOT'] = '/home/rails'
103
+ path = get_config_paths[0]
104
+ assert_equal '/home/rails/.tddium', path
105
+ File.open(path, 'w') {|f| f.write('a')}
106
+ assert_equal path, find_config
107
+ ENV['RAILS_ROOT'] = oldroot
108
+ end
109
+ end
110
+ end
111
+
112
+ class TestKeyFile < Test::Unit::TestCase
113
+ context "get_keyfile" do
114
+ setup do
115
+ @config = {:key_directory => 'dir', :key_name => 'key'}
116
+ stubs(:read_config => @config).once
117
+ FakeFS::FileSystem.clear
118
+ end
119
+
120
+ context "no keyfile present" do
121
+ should "return nil" do
122
+ STDERR.expects(:puts).once
123
+ assert_nil get_keyfile
124
+ end
125
+ end
126
+
127
+ context "keyfile wrong perms" do
128
+ should "return nil" do
129
+ FileUtils.mkdir_p @config[:key_directory]
130
+ File.open(key_file_name(@config), 'w') do |f|
131
+ f.write 'abc'
132
+ end
133
+ FakeFS::File::Stat.mode=0644
134
+ STDERR.expects(:puts).once
135
+ assert_nil get_keyfile
136
+ end
137
+ end
138
+
139
+ context "keyfile OK" do
140
+ should "return keyfile name" do
141
+ @name = key_file_name(@config)
142
+ FileUtils.mkdir_p @config[:key_directory]
143
+ File.open(@name, 'w') do |f|
144
+ f.write 'abc'
145
+ end
146
+ FakeFS::File::Stat.mode=0600
147
+ STDERR.expects(:puts).never
148
+ assert_equal @name, get_keyfile
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+ class TestFiles < Test::Unit::TestCase
155
+ context "find_test_files" do
156
+ setup do
157
+ @config = {:test_pattern => 'a'}
158
+ stubs(:read_config => @config)
159
+ end
160
+
161
+ should "be callable" do
162
+ assert find_test_files
163
+ end
164
+ end
165
+ end
166
+
167
+ class TestSpecOpts < Test::Unit::TestCase
168
+ context "spec_opts" do
169
+ should "return a list" do
170
+ stubs(:read_config => CONFIG_DEFAULTS)
171
+ opts = spec_opts('a')
172
+ assert opts.is_a?(Array)
173
+ assert_equal 1, opts.select{|x| /require/.match(x)}.size
174
+ end
175
+
176
+ should "include require_files" do
177
+ stubs(:read_config => {:require_files => 'a.rb'})
178
+ opts = spec_opts('a')
179
+ assert opts.is_a?(Array)
180
+ assert_equal 2, opts.select{|x| /require/.match(x)}.size
181
+ end
182
+
183
+ should "read TDDIUM_SPEC_OPTS environment" do
184
+ stubs(:read_config => CONFIG_DEFAULTS)
185
+ specopts = 'abcdefgh'
186
+ oldenv = ENV['TDDIUM_SPEC_OPTS']
187
+ ENV['TDDIUM_SPEC_OPTS'] = specopts
188
+ opts = spec_opts('a')
189
+ ENV['TDDIUM_SPEC_OPTS'] = oldenv
190
+ assert opts.is_a?(Array)
191
+ assert_equal 1, opts.select{|x| /#{specopts}/.match(x)}.size
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,47 @@
1
+ require 'helper'
2
+ require 'mocha'
3
+ require 'fakefs'
4
+ require 'tddium/parallel'
5
+
6
+ class TestParallel < Test::Unit::TestCase
7
+ context "make_spec_cmd" do
8
+ should "raise if no result_path specified" do
9
+ assert_raise RuntimeError do
10
+ make_spec_cmd([1], 'a', nil)
11
+ end
12
+ end
13
+ should "suppress RSPEC_COLOR if stdout is not tty" do
14
+ $stdout.stubs(:tty? => false)
15
+ assert_no_match /RSPEC_COLOR/, make_spec_cmd(['a'], 'a', 'a')
16
+ end
17
+ end
18
+
19
+ context "test_batches" do
20
+ setup do
21
+ @config = {:test_pattern => '*.rb'}
22
+ stubs(:read_config => @config)
23
+ @files = %w{a b c d e}
24
+ @files.each { |f| File.open("#{f}.rb", 'w') { |o| o.write('a') } }
25
+ end
26
+ should "find batches" do
27
+ [1,2,3,4,5,6].each do |n|
28
+ b = test_batches(n)
29
+ assert_equal n, b.size
30
+ end
31
+ end
32
+ end
33
+
34
+ context "parallel_task" do
35
+ setup do
36
+ @batches = [['a', 'b'], ['c']]
37
+ stubs(:test_batches => @batches)
38
+ stubs(:execute_command => 'a')
39
+ end
40
+ should "run with defaults" do
41
+ args = mock()
42
+ args.expects(:with_defaults)
43
+ args.stubs(:threads => 5, :inspect => 'args', :environment => 'selenium', :result_directory => '.')
44
+ parallel_task(args)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,372 @@
1
+ =begin
2
+ Copyright (c) 2010 tddium.com All Rights Reserved
3
+ =end
4
+
5
+ require 'helper'
6
+ require 'fakefs'
7
+ require 'fileutils'
8
+ require 'mocha'
9
+
10
+ class FakeFS::File::Stat
11
+ @@themode = 0600
12
+ def mode
13
+ return @@themode
14
+ end
15
+
16
+ def self.mode=(newmode)
17
+ @@themode = newmode
18
+ end
19
+ end
20
+
21
+ class TestEC2 < Test::Unit::TestCase
22
+ context "start instances" do
23
+ setup do
24
+ Fog.mock!
25
+ @config = {:aws_key => 'abc', :aws_secret => 'def'}
26
+ stubs(:read_config => @config)
27
+ stubs(:system => 0)
28
+ mockstart
29
+ end
30
+
31
+ should "create new EC2 instance with configured key" do
32
+ server = start_instance
33
+ assert_equal server.image_id, AMI_NAME
34
+ assert_equal nil, $tunnel_pid
35
+ end
36
+
37
+ should "not crash if keyfile is not provided"
38
+
39
+ should "set SELENIUM_RC_HOST environment variable" do
40
+ server = start_instance
41
+ assert_equal server.dns_name, ENV['SELENIUM_RC_HOST']
42
+ end
43
+
44
+ should "set TDDIUM environment variable" do
45
+ server = start_instance
46
+ assert_equal '1', ENV['TDDIUM']
47
+ end
48
+
49
+ context "if ssh_tunnel is needed" do
50
+ setup do
51
+ @config[:ssh_tunnel] = 1
52
+ @config[:key_name] = 'sg-keypair'
53
+ @config[:key_directory] = '.'
54
+ FakeFS::FileSystem.clear
55
+ File.open(key_file_name(@config), 'w', 0600) do |f|
56
+ f.write('foo')
57
+ end
58
+ @testpid = 10000
59
+ Process.stubs(:fork => @testpid)
60
+ end
61
+
62
+ should "set up an ssh tunnel and save its pid" do
63
+ server = start_instance
64
+ assert_equal @testpid, $tunnel_pid
65
+ $tunnel_pid = nil
66
+ end
67
+
68
+ should "set the SELENIUM_RC_HOST environment variable to localhost" do
69
+ server = start_instance
70
+ assert_equal 'localhost', ENV['SELENIUM_RC_HOST']
71
+ $tunnel_pid = nil
72
+ end
73
+ end
74
+ end
75
+
76
+ context "stop instance" do
77
+ setup do
78
+ Fog.mock!
79
+ config = {:aws_key => 'abc', :aws_secret => 'def'}
80
+ stub(:read_config => config)
81
+ mockstart
82
+ end
83
+
84
+ should "stop instances" do
85
+ server = start_instance
86
+ assert server.ready?
87
+ stop_instance
88
+ assert server.terminated?
89
+ end
90
+ end
91
+
92
+ context "find_instances" do
93
+ setup do
94
+ Fog.mock!
95
+ config = {:aws_key => 'abc', :aws_secret => 'def'}
96
+ stub(:read_config => config)
97
+ end
98
+
99
+ should "exist as a method" do
100
+ find_instances
101
+ end
102
+
103
+ should "not find any instances" do
104
+ result = find_instances
105
+ assert_nil result
106
+ end
107
+
108
+ should "find an instance" do
109
+ mockstart
110
+ server = start_instance
111
+ result = find_instances
112
+ assert_equal server.id, result[0].id
113
+ end
114
+
115
+ should "not filter by tag"
116
+ end
117
+
118
+ context "session_instances" do
119
+ setup do
120
+ Fog.mock!
121
+ config = {:aws_key => 'abc', :aws_secret => 'def'}
122
+ stub(:read_config => config)
123
+ stop_all_instances
124
+ end
125
+
126
+ should "exist as a method" do
127
+ session_instances('a')
128
+ end
129
+
130
+ should "not find any instances" do
131
+ result = session_instances('b')
132
+ assert_nil result
133
+ end
134
+
135
+ should "find an instance" do
136
+ mockstart
137
+ server = start_instance
138
+ result = session_instances(@tddium_session)
139
+ assert_equal server.id, result[0].id
140
+ end
141
+ end
142
+
143
+ context "stopall instances" do
144
+ setup do
145
+ Fog.mock!
146
+ config = {:aws_key => 'abc', :aws_secret => 'def'}
147
+ stub(:read_config => config)
148
+ end
149
+
150
+ should "exist as a method" do
151
+ stop_all_instances
152
+ end
153
+
154
+ should "destroy all instances" do
155
+ instancemock1 = mock().expects(:destroy)
156
+ instancemock2 = mock().expects(:destroy)
157
+ instances = [instancemock1, instancemock2]
158
+ stub(:find_instances => instances)
159
+ stop_all_instances
160
+ end
161
+ end
162
+
163
+ context "checkstart dev instance" do
164
+ setup do
165
+ Fog.mock!
166
+ config = {:aws_key => 'abc', :aws_secret => 'def'}
167
+ stub(:read_config => config)
168
+ mockstart
169
+ end
170
+
171
+ should "exist as a method" do
172
+ checkstart_dev_instance
173
+ end
174
+
175
+ should "only start 1 instance" do
176
+ server1 = checkstart_dev_instance
177
+ server2 = checkstart_dev_instance
178
+ assert_equal server1.id, server2.id
179
+ end
180
+ end
181
+
182
+ private
183
+
184
+ def mockstart
185
+ httpmock = mock()
186
+ httpmock.expects(:open_timeout=)
187
+ httpmock.expects(:read_timeout=)
188
+ httpmock.expects(:request)
189
+ Net::HTTP.stubs(:new).returns(httpmock)
190
+ getmock = mock()
191
+ Net::HTTP::Get.stubs(:new).returns(getmock)
192
+ end
193
+ end
194
+
195
+ class TestSshTunnel < Test::Unit::TestCase
196
+ should "have ssh tunnel method" do
197
+ stubs(:system => true)
198
+ ssh_tunnel('abc')
199
+ end
200
+
201
+ context "kill_tunnel" do
202
+ should "kill tunnel" do
203
+ @testpid = 10000
204
+ $tunnel_pid = @testpid
205
+ Process.expects(:kill).with("TERM", @testpid)
206
+ Process.expects(:waitpid).with(@testpid)
207
+ kill_tunnel
208
+ end
209
+
210
+ should "not kill if no tunnel" do
211
+ $tunnel_pid = nil
212
+ Process.expects(:kill).never
213
+ kill_tunnel
214
+ end
215
+ end
216
+ end
217
+
218
+ class TestEnvSet < Test::Unit::TestCase
219
+ context "setup_environment" do
220
+ setup do
221
+ @smock = mock()
222
+ @smock.stubs(:dns_name => 'a')
223
+ end
224
+
225
+ should "always set TDDIUM environment" do
226
+ setup_environment(@smock)
227
+ assert_equal ENV['TDDIUM'], '1'
228
+ end
229
+
230
+ should "set RC_HOST to remote if no tunnel" do
231
+ setup_environment(@smock)
232
+ assert_equal ENV['SELENIUM_RC_HOST'], @smock.dns_name
233
+ end
234
+
235
+ should "set RC_HOST to localhost if tunnel" do
236
+ $tunnel_pid = 1
237
+ setup_environment(@smock)
238
+ assert_equal ENV['SELENIUM_RC_HOST'], 'localhost'
239
+ $tunnel_pid = nil
240
+ end
241
+ end
242
+ end
243
+
244
+ class TestLogRotate < Test::Unit::TestCase
245
+ context "calling result_directory" do
246
+ setup do
247
+ @config = {:result_directory => 'results'}
248
+ @latest = File.join(@config[:result_directory], 'latest')
249
+ stubs(:read_config => @config)
250
+ end
251
+ context "regardless" do
252
+ should "return directory name" do
253
+ x = result_directory
254
+ assert_equal @latest, x
255
+ end
256
+ end
257
+ context "with no results" do
258
+ setup do
259
+ FakeFS::FileSystem.clear
260
+ end
261
+ should "create results/latest/" do
262
+ result_directory
263
+ assert File.directory?(@latest)
264
+ end
265
+ end
266
+
267
+ context "with existing <results>/latest directory" do
268
+ setup do
269
+ FileUtils.mkdir_p @latest
270
+ end
271
+
272
+ should "rotate latest to date-extended directory name" do
273
+ result_directory
274
+ files = Dir.glob("#{@config[:result_directory]}/*")
275
+ assert_equal 2, files.length
276
+ end
277
+
278
+ should "preserve contents of rotated report" do
279
+ fname = File.join(@latest, 'report.html')
280
+ File.open(fname, 'w') do |f|
281
+ f.write('foo')
282
+ end
283
+ result_directory
284
+ assert !File.exists?(fname)
285
+ files = Dir.glob('**/report.html')
286
+ assert_equal 1, files.length
287
+ assert_equal 'foo', File.open(files[0]).read
288
+ end
289
+ end
290
+ end
291
+
292
+ context "default result path" do
293
+ setup do
294
+ @config = {:result_directory => "results"}
295
+ stubs(:read_config => @config)
296
+ end
297
+ should "return the right path" do
298
+ x = default_report_path
299
+ expected = File.join(@config[:result_directory], 'latest', REPORT_FILENAME)
300
+ assert_equal expected, x
301
+ end
302
+ end
303
+ end
304
+
305
+ class TestCollectLogs < Test::Unit::TestCase
306
+ context "no keyfile" do
307
+ setup do
308
+ stubs(:get_keyfile => nil)
309
+ end
310
+ should "raise an error" do
311
+ assert_raise RuntimeError do
312
+ collect_syslog
313
+ end
314
+ end
315
+ end
316
+
317
+ context "normal mode" do
318
+ context "no host started" do
319
+ setup do
320
+ stubs(:system => true).never
321
+ stubs(:session_instances => [])
322
+ stubs(:get_keyfile => 'a')
323
+ end
324
+ should "fail gracefully" do
325
+ collect_syslog
326
+ end
327
+ end
328
+
329
+ context "host started" do
330
+ setup do
331
+ @host = 'somehost'
332
+ mockinst = mock()
333
+ mockinst.stubs(:dns_name => @host)
334
+ stubs(:session_instances => [mockinst])
335
+ @keyfile = 'keyfile'
336
+ stubs(:get_keyfile => @keyfile)
337
+ end
338
+ should "scp from host" do
339
+ stubs(:system).twice.with() do |cmd|
340
+ (cmd =~ /#{@host}/ &&
341
+ cmd =~ /^scp/ &&
342
+ cmd =~ /#{@keyfile}/ &&
343
+ cmd =~ /\.\/selenium-rc.#{@host}/) ||
344
+ (cmd =~ /#{@host}/ &&
345
+ cmd =~ /^scp/ &&
346
+ cmd =~ /#{@keyfile}/ &&
347
+ cmd =~ /\.\/selenium-hub.#{@host}/)
348
+ end
349
+ collect_syslog
350
+ end
351
+
352
+ should "let target directory be specified" do
353
+ target = 'targetdir'
354
+ stubs(:system).twice.with() do |cmd|
355
+ (cmd =~ /#{@host}/ &&
356
+ cmd =~ /^scp/ &&
357
+ cmd =~ /#{@keyfile}/ &&
358
+ cmd =~ /#{target}\/selenium-rc.#{@host}/) ||
359
+ (cmd =~ /#{@host}/ &&
360
+ cmd =~ /^scp/ &&
361
+ cmd =~ /#{@keyfile}/ &&
362
+ cmd =~ /#{target}\/selenium-hub.#{@host}/)
363
+ end
364
+ collect_syslog(target)
365
+ end
366
+ end
367
+ end
368
+
369
+ context "dev mode" do
370
+ should "use dev mode host"
371
+ end
372
+ end