Class: CemAcpt::Bolt::Tests::TestResult

Inherits:
Object
  • Object
show all
Defined in:
lib/cem_acpt/bolt/tests.rb

Overview

Contains the results of a single Bolt task test

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, command_result, validation_results, **details) ⇒ TestResult

Returns a new instance of TestResult.



103
104
105
106
107
108
# File 'lib/cem_acpt/bolt/tests.rb', line 103

def initialize(name, command_result, validation_results, **details)
  @name = name
  @command_result = command_result
  @validation_results = validation_results
  @details = details
end

Instance Attribute Details

#command_resultObject (readonly)

Returns the value of attribute command_result.



101
102
103
# File 'lib/cem_acpt/bolt/tests.rb', line 101

def command_result
  @command_result
end

#detailsObject (readonly)

Returns the value of attribute details.



101
102
103
# File 'lib/cem_acpt/bolt/tests.rb', line 101

def details
  @details
end

#nameObject (readonly)

Returns the value of attribute name.



101
102
103
# File 'lib/cem_acpt/bolt/tests.rb', line 101

def name
  @name
end

#validation_resultsObject (readonly)

Returns the value of attribute validation_results.



101
102
103
# File 'lib/cem_acpt/bolt/tests.rb', line 101

def validation_results
  @validation_results
end

Instance Method Details

#actionObject



122
123
124
125
126
127
128
129
130
# File 'lib/cem_acpt/bolt/tests.rb', line 122

def action
  @action ||= if @command_result.is_a?(CemAcpt::Bolt::BoltActionError)
                @command_result.bolt_action
              elsif @command_result.respond_to?(:action)
                @command_result.action
              else
                'unknown'
              end
end

#errorObject



164
165
166
# File 'lib/cem_acpt/bolt/tests.rb', line 164

def error
  @command_result.error if error?
end

#error?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/cem_acpt/bolt/tests.rb', line 160

def error?
  @command_result.error?
end

#failed_validation_resultsObject



110
111
112
# File 'lib/cem_acpt/bolt/tests.rb', line 110

def failed_validation_results
  @failed_validation_results ||= validation_results.select { |vr| vr[:result] == 'failure' }
end

#objectObject



142
143
144
145
146
147
148
149
150
# File 'lib/cem_acpt/bolt/tests.rb', line 142

def object
  @object ||= if @command_result.is_a?(CemAcpt::Bolt::BoltActionError)
                @command_result.bolt_object
              elsif @command_result.respond_to?(:object)
                @command_result.object
              else
                'unknown'
              end
end

#skipped_validation_resultsObject



114
115
116
# File 'lib/cem_acpt/bolt/tests.rb', line 114

def skipped_validation_results
  @skipped_validation_results ||= validation_results.select { |vr| vr[:result] == 'skipped' }
end

#statusObject



156
157
158
# File 'lib/cem_acpt/bolt/tests.rb', line 156

def status
  @status ||= success? ? 'success' : 'failure'
end

#success?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/cem_acpt/bolt/tests.rb', line 152

def success?
  @validation_results.none? { |vr| vr[:result] == 'failure' }
end

#success_validation_resultsObject



118
119
120
# File 'lib/cem_acpt/bolt/tests.rb', line 118

def success_validation_results
  @success_validation_results ||= validation_results.select { |vr| vr[:result] == 'success' }
end

#targetObject



132
133
134
135
136
137
138
139
140
# File 'lib/cem_acpt/bolt/tests.rb', line 132

def target
  @target ||= if @command_result.is_a?(CemAcpt::Bolt::BoltActionError)
                @command_result.bolt_target
              elsif @command_result.respond_to?(:target)
                @command_result.target
              else
                'unknown'
              end
end

#to_hObject



168
169
170
171
172
173
174
175
176
# File 'lib/cem_acpt/bolt/tests.rb', line 168

def to_h
  {
    name: name,
    success: success?,
    command_result: command_result.to_h,
    validation_results: validation_results,
    details: details,
  }
end