module Reagan
main Reagan
application to which gathers configs, determines changes, and runs tests
- Author
-
Tim Smith (<tim@cozy.co>)
- Copyright
-
Copyright © 2014 Tim Smith
- License
-
Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- Author
-
Tim Smith (<tim@cozy.co>)
- Copyright
-
Copyright © 2014 Tim Smith
- License
-
Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Public Class Methods
exit with a friendly message if nothing we test has been changed
# File lib/reagan.rb 30 def self::check_empty_update 31 if ChangeSet.empty? 32 'No objects to test. Exiting'.marquee 33 exit 0 34 end 35 end
check and see if the -p flag was passed and if so print the config hash
# File lib/reagan.rb 38 def self::check_print_config 39 return unless Config.settings['flags']['print_config'] 40 'Current config file / CLI flag values'.marquee 41 Config.pretty_print 42 exit 0 43 end
run tests on each changed cookbook
# File lib/reagan.rb 46 def self::run 47 # ensure output syncs to the console so jenkins can record it 48 $stdout.sync = $stderr.sync = true 49 50 Config.validate 51 check_print_config 52 check_empty_update 53 54 # print objects that will be tested 55 'The following chef objects will be tested'.marquee 56 %w(cookbooks roles environments data_bags).each do |type| 57 unless ChangeSet.files[type].empty? 58 puts "#{type}:" 59 ChangeSet.files[type].each { |obj| puts ' ' + obj } 60 end 61 end 62 63 results = [] 64 ChangeSet.files['cookbooks'].each do |cookbook| 65 "Testing cookbook #{cookbook}".marquee 66 results << Reagan::TestKnife.new(cookbook).test 67 results << Reagan::TestVersion.new(cookbook).test 68 results << Reagan::TestReagan.new(cookbook).test 69 end 70 71 %w(data_bags roles environments).each do |type| 72 ChangeSet.files[type].each do |file| 73 "Testing #{type} file #{file}".marquee 74 results << TestJSON.new(file).test 75 end 76 end 77 78 # print success or failure 79 failure = results.include?(false) 80 text = failure ? 'Reagan testing has failed'.to_red : 'All Reagan tests have suceeded'.to_green 81 text.marquee 82 83 # if any test failed then exit 1 so jenkins can pick up the failure 84 exit 1 if failure 85 end