Class: QaServer::ScenarioLogger

Inherits:
Object
  • Object
show all
Defined in:
app/loggers/qa_server/scenario_logger.rb

Constant Summary collapse

PASS =
ScenarioValidator::PASS
FAIL =
ScenarioValidator::FAIL
UNKNOWN =
ScenarioValidator::UNKNOWN

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_count = 0, failure_count = 0) ⇒ ScenarioLogger

Returns a new instance of ScenarioLogger.



10
11
12
13
14
# File 'app/loggers/qa_server/scenario_logger.rb', line 10

def initialize(test_count = 0, failure_count = 0)
  @log = []
  @test_count = test_count
  @failure_count = failure_count
end

Instance Attribute Details

#failure_count ⇒ Object (readonly)

Returns the value of attribute failure_count.



4
5
6
# File 'app/loggers/qa_server/scenario_logger.rb', line 4

def failure_count
  @failure_count
end

#test_count ⇒ Object (readonly)

Returns the value of attribute test_count.



4
5
6
# File 'app/loggers/qa_server/scenario_logger.rb', line 4

def test_count
  @test_count
end

Instance Method Details

#add(authority_name:, validation_type: '', status:, subauth: '', service: '', action: '', url: '', error_message: '', expected: nil, actual: nil, target: nil) ⇒ Object

Add a scenario to the log

Parameters:

  • authority_name (String) —

    name of the authority the scenario was run against

  • status (Symbol) —

    indicating whether the scenario passed, failed, or has unknown status (see PASS, FAIL, UNKNOWN constants)

  • validation_type (Symbol) (defaults to: '') —

    the type of validation this status data describes (e.g. :connection, :accuracy)

  • subauth (String) (defaults to: '') —

    name of the subauthority the scenario was run against

  • service (String) (defaults to: '') —

    identifies the primary service provider (e.g. 'ld4l_cache', 'direct', etc.)

  • action (String) (defaults to: '') —

    type of scenario (i.e. 'term', 'search')

  • url (String) (defaults to: '') —

    example url that was used to test a specific term fetch or search query

  • error_message (String) (defaults to: '') —

    error message if scenario failed

  • expected (Integer) (defaults to: nil) —

    the expected result (e.g. min size of result OR max position of subject within results)

  • actual (Integer) (defaults to: nil) —

    the actual result (e.g. actual size of results OR actual position of subject within results)

  • target (String) (defaults to: nil) —

    the expected target that was validated (e.g. subject_uri for query, pref label for term fetch)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/loggers/qa_server/scenario_logger.rb', line 28

def add(authority_name:, validation_type: '', status:, subauth: '', service: '', action: '', url: '', error_message: '', expected: nil, actual: nil, target: nil)
  @test_count += 1
  case status
    when PASS
      status_label = '√'
    when UNKNOWN
      status_label = '?'
      @failure_count += 1
    when FAIL
      status_label = 'X'
      @failure_count += 1
  end
  @log << { type: validation_type,
            status: status,
            status_label: status_label,
            authority_name: authority_name,
            subauthority_name: subauth,
            service: service,
            action: action,
            url: url,
            expected: expected,
            actual: actual,
            target: target,
            err_message: error_message }
end

#append(other) ⇒ Object

Append a log to this log.

Parameters:

  • the (ScenarioLog) —

    log to append to this log



61
62
63
64
65
66
# File 'app/loggers/qa_server/scenario_logger.rb', line 61

def append(other)
  return unless other.present?
  @log += other.to_a
  @test_count += other.test_count
  @failure_count += other.failure_count
end

#delete_passing ⇒ Object

Delete from the log any tests that passed.



55
56
57
# File 'app/loggers/qa_server/scenario_logger.rb', line 55

def delete_passing
  @log.delete_if { |entry| entry[:status] == PASS }
end

#filter(type: nil) ⇒ Object

Returns selected scenario test results data as an array limited to the specified type or all scenarios if type is nil.

Returns:

  • selected scenario test results data as an array limited to the specified type or all scenarios if type is nil



69
70
71
72
# File 'app/loggers/qa_server/scenario_logger.rb', line 69

def filter(type: nil)
  return @log if type.blank?
  @log.select { |entry| entry[:type] == type }
end

#size ⇒ Object

Returns the number of scenarios recorded in the log.

Returns:

  • the number of scenarios recorded in the log



80
81
82
# File 'app/loggers/qa_server/scenario_logger.rb', line 80

def size
  to_a.size
end

#to_a ⇒ Object

Returns the scenario test results data as an array.

Returns:

  • the scenario test results data as an array



75
76
77
# File 'app/loggers/qa_server/scenario_logger.rb', line 75

def to_a
  @log
end