Class: Datadog::CI::TestImpactAnalysis::Coverage::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/test_impact_analysis/coverage/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_id:, test_suite_id:, test_session_id:, files:) ⇒ Event

Returns a new instance of Event.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/datadog/ci/test_impact_analysis/coverage/event.rb', line 14

def initialize(
  test_id:,
  test_suite_id:,
  test_session_id:,
  files:
)
  @test_id = test_id
  @test_suite_id = test_suite_id
  @test_session_id = test_session_id
  @files = files
end

Instance Attribute Details

#test_idObject (readonly)

Returns the value of attribute test_id.



12
13
14
# File 'lib/datadog/ci/test_impact_analysis/coverage/event.rb', line 12

def test_id
  @test_id
end

#test_session_idObject (readonly)

Returns the value of attribute test_session_id.



12
13
14
# File 'lib/datadog/ci/test_impact_analysis/coverage/event.rb', line 12

def test_session_id
  @test_session_id
end

#test_suite_idObject (readonly)

Returns the value of attribute test_suite_id.



12
13
14
# File 'lib/datadog/ci/test_impact_analysis/coverage/event.rb', line 12

def test_suite_id
  @test_suite_id
end

Instance Method Details

#inspect_coverageObject



26
27
28
# File 'lib/datadog/ci/test_impact_analysis/coverage/event.rb', line 26

def inspect_coverage
  @files.inspect_coverage
end

#pretty_print(q) ⇒ Object

Return a human readable version of the event



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/datadog/ci/test_impact_analysis/coverage/event.rb', line 75

def pretty_print(q)
  q.group 0 do
    q.breakable
    q.text "Test ID: #{@test_id}\n"
    q.text "Test Suite ID: #{@test_suite_id}\n"
    q.text "Test Session ID: #{@test_session_id}\n"
    q.group(2, "Files: [", "]\n") do
      q.seplist @files do |filename|
        q.text filename
      end
    end
  end
end

#to_msgpack(packer = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/datadog/ci/test_impact_analysis/coverage/event.rb', line 44

def to_msgpack(packer = nil)
  packer ||= MessagePack::Packer.new

  packer.write_map_header(test_id.nil? ? 3 : 4)

  packer.write("test_session_id")
  packer.write(test_session_id.to_i)

  packer.write("test_suite_id")
  packer.write(test_suite_id.to_i)

  unless test_id.nil?
    packer.write("span_id")
    packer.write(test_id.to_i)
  end

  packer.write("files")
  packer.write_array_header(@files.size)
  @files.each do |filename|
    packer.write_map_header(1)
    packer.write("filename")
    packer.write(filename)
  end
end

#to_sObject



69
70
71
72
# File 'lib/datadog/ci/test_impact_analysis/coverage/event.rb', line 69

def to_s
  coverage_value = @files.nil? ? nil : inspect_coverage
  "Coverage::Event[test_id=#{test_id}, test_suite_id=#{test_suite_id}, test_session_id=#{test_session_id}, coverage=#{coverage_value}]"
end

#valid?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/datadog/ci/test_impact_analysis/coverage/event.rb', line 30

def valid?
  valid = true

  %i[test_suite_id test_session_id files].each do |key|
    value = (key == :files) ? @files : send(key)
    next unless value.nil?

    Datadog.logger.warn("citestcov event is invalid: [#{key}] is nil. Event: #{self}")
    valid = false
  end

  valid
end