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

Methods included from ModuleMethods

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

Methods included from FileTest::ModuleMethods

included

Instance Method Details

#assert_recipe(expected, recipe = setup_recipe, &block) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/linecook/test.rb', line 144

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



152
153
154
155
156
157
158
# File 'lib/linecook/test.rb', line 152

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



160
161
162
163
164
165
166
167
# File 'lib/linecook/test.rb', line 160

def build_package(host=self.host)
  package_dir = path("packages/#{host}")
  
  package.build
  package.export package_dir
  
  package_dir
end

#build_project(options = {}) ⇒ Object



176
177
178
179
180
181
182
183
# File 'lib/linecook/test.rb', line 176

def build_project(options={})
  options = {
    'project_dir' => method_dir,
    'quiet'       => true
  }.merge(options)
  
  linecook('build', options)
end

#cookbookObject



98
99
100
# File 'lib/linecook/test.rb', line 98

def cookbook
  @cookbook ||= setup_cookbook
end

#helpersObject



114
115
116
# File 'lib/linecook/test.rb', line 114

def helpers
  @helpers ||= []
end

#hostObject



122
123
124
# File 'lib/linecook/test.rb', line 122

def host
  @host ||= self.class.host
end

#linecook(cmd, options = {}, *args) ⇒ Object



197
198
199
200
201
202
203
204
205
# File 'lib/linecook/test.rb', line 197

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



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/linecook/test.rb', line 207

def linecook_cmd(cmd, options={}, *args)
  opts = []
  options.each_pair do |key, value|
    key = key.gsub('_', '-')
    
    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_dirObject



74
75
76
77
78
79
80
81
82
# File 'lib/linecook/test.rb', line 74

def method_dir
  @host_method_dir ||= begin
    if test_host = ENV['LINECOOK_TEST_HOST']
      File.join(super, test_host)
    else
      super
    end
  end
end

#packageObject



106
107
108
# File 'lib/linecook/test.rb', line 106

def package
  @package ||= setup_package
end

#recipeObject



140
141
142
# File 'lib/linecook/test.rb', line 140

def recipe
  @recipe ||= setup_recipe
end

#remote_dirObject



84
85
86
# File 'lib/linecook/test.rb', line 84

def remote_dir
  method_dir[(user_dir.length + 1)..-1]
end

#run_package(options = {}, host = self.host) ⇒ Object



169
170
171
172
173
174
# File 'lib/linecook/test.rb', line 169

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!



186
187
188
189
190
191
192
193
194
195
# File 'lib/linecook/test.rb', line 186

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

#runlistObject



126
127
128
# File 'lib/linecook/test.rb', line 126

def runlist
  @runlist ||= []
end

#setup_cookbook(configs = nil, project_dir = method_dir) ⇒ Object



93
94
95
96
# File 'lib/linecook/test.rb', line 93

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



102
103
104
# File 'lib/linecook/test.rb', line 102

def setup_package(env={})
  @package = Package.setup(env, cookbook)
end

#setup_recipe(target_name = package.next_target_name('recipe'), mode = 0700, &block) ⇒ Object



130
131
132
133
134
135
136
137
138
# File 'lib/linecook/test.rb', line 130

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_fileObject



88
89
90
91
# File 'lib/linecook/test.rb', line 88

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



110
111
112
# File 'lib/linecook/test.rb', line 110

def use_helpers(*helpers)
  @helpers = helpers
end

#use_host(host) ⇒ Object



118
119
120
# File 'lib/linecook/test.rb', line 118

def use_host(host)
  @host = host
end