lib/runner.rb in tdi-0.1.6 vs lib/runner.rb in tdi-0.1.7
- old
+ new
@@ -1,7 +1,7 @@
#
-# Copyright (C) 2013-2014 Globo.com
+# Copyright (C) 2013-2015 Globo.com
#
# This file is part of TDI.
# TDI is free software: you can redistribute it and/or modify
@@ -17,10 +17,11 @@
# You should have received a copy of the GNU General Public License
# along with TDI. If not, see <http://www.gnu.org/licenses/>.
require 'os'
require_relative 'tdi'
+require_relative 'util'
# Run tests.
def runner(opts, filename, plan)
puts 'Running tests...'.cyan if opts[:verbose] > 1
@@ -57,22 +58,20 @@
if role_content['desc'].nil?
puts "* #{role_name.capitalize}".cyan
else
puts "* #{role_name.capitalize} - #{role_content['desc']}".cyan
end
-# puts "Running tests for role: #{role_name}".cyan if opts[:verbose] > 0
puts "Total test plans to run for this role: #{total_plans}".cyan if opts[:verbose] > 1
# Test plan.
# Ex: {"acl": {"domain1": {"port": 80}...}...}
role_content.select { |key, val|
val.is_a?(Hash)
}.each_pair do |plan_name, plan_content|
total_cases = plan_content.select { |key, val| val.is_a?(Hash) }.size
puts "* #{plan_name.upcase}".cyan
-# puts "Test plan: #{role_name}::#{plan_name}".cyan if opts[:verbose] > 0
puts "Total test cases to run for this plan: #{total_cases}".cyan if opts[:verbose] > 1
if opts[:verbose] > 3
puts "Plan: #{plan_name}"
puts 'Plan content:'
@@ -80,11 +79,11 @@
end
# Test plan content (test cases).
# Ex: {"domain1": {"port": 80}, "domain2": {"port": 80}...}
if tdiplan.respond_to?(plan_name)
- tdiplan.send(plan_name, plan_content)
+ tdiplan.send(plan_name, role_name, plan_name, plan_content)
else
puts "Skipping not supported test plan type \"#{plan_name}\" for \"#{role_name}::#{plan_name}\".".yellow
tdiplan.skip = tdiplan.skip + total_cases
end
end
@@ -93,11 +92,44 @@
end
# Summary.
summary(opts, tdiplan)
+ # Report file.
+ report(opts, tdiplan)
+
# Shred.
+ shred(opts, filename, tdiplan)
+
+ puts 'Running tests... done.'.green if opts[:verbose] > 1
+
+ ret = tdiplan.plan_passed? ? 0 : 1
+ ret = 0 if opts.nofail?
+ ret
+end
+
+# Display test summary.
+def summary(opts, tdiplan)
+ puts '=' * 79
+ puts "Total: #{tdiplan.total} | Skip: #{tdiplan.skip} | Pass: #{tdiplan.pass} | Warn: #{tdiplan.warn} | Fail: #{tdiplan.fail}"
+end
+
+# Generate report file.
+def report(opts, tdiplan)
+ if opts[:verbose] > 2
+ puts 'Report:'.cyan
+ a_p tdiplan.report
+ end
+
+ if opts.reportfile?
+ puts "Generating report file: \"#{opts[:reportfile]}\"".cyan if opts[:verbose] > 1
+ File.open(opts[:reportfile], 'w') { |file| file.write(JSON.pretty_generate(tdiplan.report)) }
+ end
+end
+
+# Remove tdi plan file.
+def shred(opts, filename, tdiplan)
if opts.shred?
puts "Shreding and removing test plan file: \"#{filename}\"...".cyan if opts[:verbose] > 2
if OS.linux?
shred_cmd = "shred -f -n 38 -u -z #{filename}"
elsif OS.mac?
@@ -110,18 +142,6 @@
puts "Shreding and removing test plan file: \"#{filename}\"... done.".green if opts[:verbose] > 2
else
puts "ERR: Shreding and removing test plan file: \"#{filename}\".".light_magenta
end
end
-
- puts 'Running tests... done.'.green if opts[:verbose] > 1
-
- ret = tdiplan.plan_passed? ? 0 : 1
- ret = 0 if opts.nofail?
- ret
-end
-
-# Display test summary.
-def summary(opts, tdiplan)
- puts '=' * 79
- puts "Total: #{tdiplan.total} | Skip: #{tdiplan.skip} | Pass: #{tdiplan.pass} | Warn: #{tdiplan.warn} | Fail: #{tdiplan.fail}"
end