Module: Linecook::Test
- Extended by:
- ModuleMethods
- Includes:
- FileTest, ShellTest
- Defined in:
- lib/linecook/test.rb,
lib/linecook/test/file_test.rb,
lib/linecook/test/shell_test.rb,
lib/linecook/test/regexp_escape.rb,
lib/linecook/test/command_parser.rb
Defined Under Namespace
Modules: ClassMethods, FileTest, ModuleMethods, ShellTest
Classes: CommandParser, RegexpEscape
Constant Summary
collapse
- LINECOOK_DIR =
File.expand_path('../../..', __FILE__)
- LINECOOK =
File.join(LINECOOK_DIR, 'bin/linecook')
Instance Method Summary
collapse
-
#assert_recipe(expected, recipe = setup_recipe, &block) ⇒ Object
-
#assert_recipe_matches(expected, recipe = setup_recipe, &block) ⇒ Object
-
#build_package(host = self.host) ⇒ Object
-
#build_project(options = {}) ⇒ Object
-
#cookbook ⇒ Object
-
#helpers ⇒ Object
-
#host ⇒ Object
-
#linecook(cmd, options = {}, *args) ⇒ Object
-
#linecook_cmd(cmd, options = {}, *args) ⇒ Object
-
#method_dir ⇒ Object
-
#package ⇒ Object
-
#recipe ⇒ Object
-
#remote_dir ⇒ Object
-
#run_package(options = {}, host = self.host) ⇒ Object
-
#run_project(options = {}, *package_names) ⇒ Object
pick up user dir as a gem…
-
#runlist ⇒ Object
-
#setup_cookbook(configs = nil, project_dir = method_dir) ⇒ Object
-
#setup_package(env = {}) ⇒ Object
-
#setup_recipe(target_name = package.next_target_name('recipe'), mode = 0700, &block) ⇒ Object
-
#ssh_config_file ⇒ Object
-
#use_helpers(*helpers) ⇒ Object
-
#use_host(host) ⇒ Object
included
Methods included from ShellTest
#_assert_alike, #_assert_output_equal, #_assert_script, #_assert_script_match, #assert_alike, #assert_output_equal, #assert_script, #assert_script_match, #outdent, #set_env, #setup, #sh, #verbose?, #whitespace_escape, #with_env
Methods included from FileTest
#class_dir, #cleanup, #cleanup_methods, #path, #prepare, #remove, #setup, #teardown, #user_dir
included
Instance Method Details
#assert_recipe(expected, recipe = setup_recipe, &block) ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/linecook/test.rb', line 115
def assert_recipe(expected, recipe=setup_recipe, &block)
recipe.instance_eval(&block) if block_given?
recipe.close
assert_output_equal expected, recipe.result
recipe
end
|
#assert_recipe_matches(expected, recipe = setup_recipe, &block) ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/linecook/test.rb', line 123
def assert_recipe_matches(expected, recipe=setup_recipe, &block)
recipe.instance_eval(&block) if block_given?
recipe.close
assert_alike expected, recipe.result
recipe
end
|
#build_package(host = self.host) ⇒ Object
131
132
133
134
135
136
137
138
|
# File 'lib/linecook/test.rb', line 131
def build_package(host=self.host)
package_dir = path("packages/#{host}")
package.build
package.export package_dir
package_dir
end
|
#build_project(options = {}) ⇒ Object
147
148
149
150
151
152
153
154
|
# File 'lib/linecook/test.rb', line 147
def build_project(options={})
options = {
'project_dir' => method_dir,
'quiet' => true
}.merge(options)
linecook('build', options)
end
|
#cookbook ⇒ Object
69
70
71
|
# File 'lib/linecook/test.rb', line 69
def cookbook
@cookbook ||= setup_cookbook
end
|
#helpers ⇒ Object
85
86
87
|
# File 'lib/linecook/test.rb', line 85
def helpers
@helpers ||= []
end
|
#host ⇒ Object
93
94
95
|
# File 'lib/linecook/test.rb', line 93
def host
@host ||= self.class.host
end
|
#linecook(cmd, options = {}, *args) ⇒ Object
168
169
170
171
172
173
174
175
176
|
# File 'lib/linecook/test.rb', line 168
def linecook(cmd, options={}, *args)
stdout = prepare("log/#{cmd}.out")
stderr = prepare("log/#{cmd}.err")
command = "#{linecook_cmd(cmd, options, *args)} 2> '#{stderr}' > '#{stdout}'"
system(command)
[File.read(stdout), "% #{command}\n#{File.read(stderr)}"]
end
|
#linecook_cmd(cmd, options = {}, *args) ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/linecook/test.rb', line 178
def linecook_cmd(cmd, options={}, *args)
opts = []
options.each_pair do |key, value|
key = key.to_s.gsub('_', '-')
key = key.length == 1 ? "-#{key}" : "--#{key}"
case value
when true
opts << key
when nil, false
else
opts << "#{key} '#{value}'"
end
end
args = args.collect! {|arg| "'#{arg}'" }
cmd = [LINECOOK, cmd] + opts.sort + args
cmd.join(' ')
end
|
#method_dir ⇒ Object
45
46
47
48
49
50
51
52
53
|
# File 'lib/linecook/test.rb', line 45
def method_dir
@host_method_dir ||= begin
if test_host = ENV['LINECOOK_TEST_HOST']
File.join(super, test_host)
else
super
end
end
end
|
#package ⇒ Object
77
78
79
|
# File 'lib/linecook/test.rb', line 77
def package
@package ||= setup_package
end
|
#recipe ⇒ Object
111
112
113
|
# File 'lib/linecook/test.rb', line 111
def recipe
@recipe ||= setup_recipe
end
|
#remote_dir ⇒ Object
55
56
57
|
# File 'lib/linecook/test.rb', line 55
def remote_dir
method_dir[(user_dir.length + 1)..-1]
end
|
#run_package(options = {}, host = self.host) ⇒ Object
140
141
142
143
144
145
|
# File 'lib/linecook/test.rb', line 140
def run_package(options={}, host=self.host)
options['remote_script'] ||= runlist.join(',')
build_package host
run_project options, host
end
|
#run_project(options = {}, *package_names) ⇒ Object
pick up user dir as a gem… bundler!
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/linecook/test.rb', line 157
def run_project(options={}, *package_names)
options = {
'ssh_config_file' => ssh_config_file,
'project_dir' => method_dir,
'remote_dir' => remote_dir,
'quiet' => true,
}.merge(options)
linecook('run', options, *package_names)
end
|
#runlist ⇒ Object
97
98
99
|
# File 'lib/linecook/test.rb', line 97
def runlist
@runlist ||= []
end
|
#setup_cookbook(configs = nil, project_dir = method_dir) ⇒ Object
64
65
66
67
|
# File 'lib/linecook/test.rb', line 64
def setup_cookbook(configs=nil, project_dir=method_dir)
configs ||= Cookbook.config_file(project_dir)
@cookbook = Cookbook.setup(configs, project_dir)
end
|
#setup_package(env = {}) ⇒ Object
73
74
75
|
# File 'lib/linecook/test.rb', line 73
def setup_package(env={})
@package = Package.setup(env, cookbook)
end
|
#setup_recipe(target_name = package.next_target_name('recipe'), mode = 0700, &block) ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'lib/linecook/test.rb', line 101
def setup_recipe(target_name=package.next_target_name('recipe'), mode=0700, &block)
recipe = package.setup_recipe(target_name, mode)
helpers.each {|helper| recipe.extend helper }
recipe.instance_eval(&block) if block_given?
runlist << target_name
@recipe = recipe
end
|
#ssh_config_file ⇒ Object
59
60
61
62
|
# File 'lib/linecook/test.rb', line 59
def ssh_config_file
method_ssh_config_file = path('config/ssh')
File.file?(method_ssh_config_file) ? method_ssh_config_file : 'config/ssh'
end
|
#use_helpers(*helpers) ⇒ Object
81
82
83
|
# File 'lib/linecook/test.rb', line 81
def use_helpers(*helpers)
@helpers = helpers
end
|
#use_host(host) ⇒ Object
89
90
91
|
# File 'lib/linecook/test.rb', line 89
def use_host(host)
@host = host
end
|