forked from Mic92/mina-sidekiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_helper.rb
62 lines (56 loc) · 1.32 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require "minitest/autorun"
require 'pathname'
TEST_ROOT = Pathname.new(File.dirname(__FILE__))
module MiniTestWithHooks
class Unit < MiniTest::Unit
def before_suites; end
def after_suites; end
def _run_suites(suites, type)
begin
before_suites
super(suites, type)
ensure
after_suites
end
end
def _run_suite(suite, type)
begin
suite.before_suite
super(suite, type)
ensure
suite.after_suite
end
end
end
end
module MiniTestWithTransactions
class Unit < MiniTestWithHooks::Unit
def before_suites
super
if ENV["FORCE_ADD_SSH_KEY"]
force_add_ssh_key
end
end
def force_add_ssh_key(&block)
ssh_key = File.expand_path("~/.ssh/id_rsa.pub")
unless File.exists?(ssh_key)
sh "ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa"
end
file = File.open(ssh_key)
pub_key = file.readline
file.close
authorized_keys = File.expand_path("~/.ssh/authorized_keys")
begin
File.open(authorized_keys, "a+") do |f|
File.chmod(0600, authorized_keys)
f.puts(pub_key)
end
rescue Exception => e
puts e.message
puts e.backtrace.inspect
ensure
File.chmod(0400, authorized_keys)
end
end
end
end