Class: Reagan::TestReagan

Inherits:
Object
  • Object
show all
Defined in:
lib/reagan/test_reagan.rb

Overview

tests cookbooks using tests defined in reagan_test.yml files

Instance Method Summary collapse

Constructor Details

#initialize(cookbook) ⇒ TestReagan

Returns a new instance of TestReagan.



22
23
24
# File 'lib/reagan/test_reagan.rb', line 22

def initialize(cookbook)
  @cookbook = cookbook
end

Instance Method Details

#testObject

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/reagan/test_reagan.rb', line 27

def test
  puts 'Running reagan_test.yml defined tests:'
  # check to see if a reagan_test.yml file exists
  if File.exist?(File.join(Config.settings['jenkins']['workspace_dir'], 'cookbooks', @cookbook, 'reagan_test.yml'))

    # load the reagan config file
    reagan_def = YAML.load_file(File.join(Config.settings['jenkins']['workspace_dir'], 'cookbooks', @cookbook, 'reagan_test.yml'))

    # change into the cookbook dir so rake tests run locally
    Dir.chdir(File.join(Config.settings['jenkins']['workspace_dir'], 'cookbooks', @cookbook))

    status = true
    reagan_def['tests'].each do |test|
      puts "  reagan_test.yml test: '#{test}'"
      result = system test
      status = false if result == false
    end
    puts status ? 'PASS: reagan_test.yml test was successful' : '    FAIL: reagan_test.yml test was NOT successful'.indent.to_red
    status
  else
    puts 'SKIP: No reagan_test.yml file found in the cookbook path. Skipping test'.indent
    status
  end
end