class Reagan::TestReagan

tests cookbooks using tests defined in reagan_test.yml files

Public Class Methods

new(cookbook) click to toggle source
   # File lib/reagan/test_reagan.rb
22 def initialize(cookbook)
23   @cookbook = cookbook
24 end

Public Instance Methods

test() click to toggle source

returns true if tests defined in reagan_test.yml passed/don't exist or false if it failed

   # File lib/reagan/test_reagan.rb
27 def test
28   puts 'Running reagan_test.yml defined tests:'
29   # check to see if a reagan_test.yml file exists
30   if File.exist?(File.join(Config.settings['jenkins']['workspace_dir'], 'cookbooks', @cookbook, 'reagan_test.yml'))
31 
32     # load the reagan config file
33     reagan_def = YAML.load_file(File.join(Config.settings['jenkins']['workspace_dir'], 'cookbooks', @cookbook, 'reagan_test.yml'))
34 
35     # change into the cookbook dir so rake tests run locally
36     Dir.chdir(File.join(Config.settings['jenkins']['workspace_dir'], 'cookbooks', @cookbook))
37 
38     status = true
39     reagan_def['tests'].each do |test|
40       puts "  reagan_test.yml test: '#{test}'"
41       result = system test
42       status = false if result == false
43     end
44     puts status ? 'PASS: reagan_test.yml test was successful' : 'FAIL: reagan_test.yml test was NOT successful'.indent.to_red
45     status
46   else
47     puts 'SKIP: No reagan_test.yml file found in the cookbook path. Skipping test'.indent
48     status
49   end
50 end