Class: Toaster::TestCase
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Toaster::TestCase
- Defined in:
- lib/toaster/test/test_case.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(obj) ⇒ Object
- #create_chef_node_attrs ⇒ Object
- #delete_test_result ⇒ Object
- #eql?(obj) ⇒ Boolean
- #executed? ⇒ Boolean
- #executed_task_uuids ⇒ Object
- #get_gross_duration ⇒ Object
- #get_net_duration ⇒ Object
- #hash ⇒ Object
-
#initialize(attr_hash) ⇒ TestCase
constructor
A new instance of TestCase.
-
#load_associations ⇒ Object
force loading of associations from DB.
- #repeated_tasks(only_task_names = false) ⇒ Object
- #run_attributes ⇒ Object
- #running_or_scheduled? ⇒ Boolean
- #scheduled? ⇒ Boolean
- #success ⇒ Object
- #task_execution(task_uuid) ⇒ Object
- #task_executions(task_uuid = []) ⇒ Object
Constructor Details
#initialize(attr_hash) ⇒ TestCase
Returns a new instance of TestCase.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/toaster/test/test_case.rb', line 23 def initialize(attr_hash) if !attr_hash[:uuid] attr_hash[:uuid] = Util.generate_short_uid() end if !attr_hash[:skip_task_uuids] attr_hash[:skip_task_uuids] = [] end if !attr_hash[:repeat_task_uuids] attr_hash[:repeat_task_uuids] = [] end super(attr_hash) end |
Class Method Details
.find(criteria = {}) ⇒ Object
175 176 177 |
# File 'lib/toaster/test/test_case.rb', line 175 def self.find(criteria={}) DB.find_activerecord(TestCase, criteria) end |
Instance Method Details
#==(obj) ⇒ Object
160 161 162 |
# File 'lib/toaster/test/test_case.rb', line 160 def ==(obj) return eql?(obj) end |
#create_chef_node_attrs ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/toaster/test/test_case.rb', line 60 def create_chef_node_attrs() attrs = { "toaster" => { # set task IDs which are to be skipped during the test execution "skip_tasks" => skip_task_uuids.dup, # set task IDs which are to be repeated during the test execution # (for testing idempotence) "repeat_tasks" => repeat_task_uuids.dup, "user_id" => test_suite.user.id, "automation_uuid" => test_suite.automation.uuid } } return attrs end |
#delete_test_result ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/toaster/test/test_case.rb', line 46 def delete_test_result() # delete all task executions automation_run.task_executions.each do |exe| exe.destroy end # delete automation run automation_run.destroy # reset properties and save automation_run = nil start_time = 0 end_time = nil save() end |
#eql?(obj) ⇒ Boolean
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/toaster/test/test_case.rb', line 164 def eql?(obj) return false if !obj.kind_of?(TestCase) return true if uuid && (uuid == obj.uuid) attr1 = test_attributes(false) ? test_attributes(false) : {} attr2 = obj.test_attributes(false) ? obj.test_attributes(false) : {} return skip_task_uuids == obj.skip_task_uuids && repeat_task_uuids == obj.repeat_task_uuids && test_suite.uuid == obj.test_suite.uuid && attr1 == attr2 end |
#executed? ⇒ Boolean
36 37 38 |
# File 'lib/toaster/test/test_case.rb', line 36 def executed? return !automation_run.nil? && !automation_run.end_time.nil? end |
#executed_task_uuids ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/toaster/test/test_case.rb', line 80 def executed_task_uuids() result = [] if automation_run automation_run.task_executions.each do |exec| result << exec.task.uuid end end return result end |
#get_gross_duration ⇒ Object
108 109 110 |
# File 'lib/toaster/test/test_case.rb', line 108 def get_gross_duration() return (end_time && start_time) ? (end_time.to_i - start_time.to_i) : 0 end |
#get_net_duration ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/toaster/test/test_case.rb', line 112 def get_net_duration() r = automation_run time = 0 if r r.task_executions.each do |exec| time += exec.end_time - exec.start_time end end return time end |
#hash ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/toaster/test/test_case.rb', line 151 def hash() h = 0 h += skip_task_uuids.hash h += repeat_task_uuids.hash h += test_suite.uuid.hash if test_suite h += test_attributes ? test_attributes.hash : 0 return h end |
#load_associations ⇒ Object
force loading of associations from DB
147 148 149 |
# File 'lib/toaster/test/test_case.rb', line 147 def load_associations hash() # loads all end |
#repeated_tasks(only_task_names = false) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/toaster/test/test_case.rb', line 90 def repeated_tasks(only_task_names=false) if !automation_run return [] end result = repeat_task_uuids.collect { |t| if t.kind_of?(Array) t.collect { |t1| task = automation_run.automation.get_task(t1, true) only_task_names ? task.name : task } else task = automation_run.automation.get_task(t, true) only_task_names ? task.name : task end } return result end |
#run_attributes ⇒ Object
75 76 77 78 |
# File 'lib/toaster/test/test_case.rb', line 75 def run_attributes() return [] if !automation_run return automation_run.run_attributes.to_a.dup end |
#running_or_scheduled? ⇒ Boolean
42 43 44 |
# File 'lib/toaster/test/test_case.rb', line 42 def running_or_scheduled? return scheduled? && !executed? end |
#scheduled? ⇒ Boolean
39 40 41 |
# File 'lib/toaster/test/test_case.rb', line 39 def scheduled? return !start_time.nil? end |
#success ⇒ Object
142 143 144 |
# File 'lib/toaster/test/test_case.rb', line 142 def success return automation_run ? automation_run.success : nil end |
#task_execution(task_uuid) ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/toaster/test/test_case.rb', line 133 def task_execution(task_uuid) list = task_executions(task_uuid) return nil if list.empty? if list.size != 1 puts "WARN: Expected 1 task execution, got #{list.size}; for task uuid: #{task_uuid}" end return list[0] end |
#task_executions(task_uuid = []) ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/toaster/test/test_case.rb', line 123 def task_executions(task_uuid=[]) task_uuid = [task_uuid] if !task_uuid.kind_of?(Array) return [] if !automation_run automation_run.task_executions.each do |exec| if task_uuid.empty? || task_uuid.include?(exec.task.uuid) result << exec end end end |