Skip to content

Commit

Permalink
Merge pull request #661 from bugsnag/arrayAttributesComparison
Browse files Browse the repository at this point in the history
add support for double attribute and array attribute comparison
twometresteve authored Jul 5, 2024
2 parents 5ba62f1 + 7f4e493 commit 0ed678e
Showing 4 changed files with 58 additions and 201 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 9.11.0 - 2024/07/05

## Enhancements

- add support for comparing double and array attributes in spans [661](https://github.com/bugsnag/maze-runner/pull/661)

# 9.10.0 - 2024/07/02

## Enhancements
198 changes: 0 additions & 198 deletions Gemfile.lock

This file was deleted.

53 changes: 51 additions & 2 deletions lib/features/steps/trace_steps.rb
Original file line number Diff line number Diff line change
@@ -96,6 +96,10 @@
assert_attribute field, key, { 'boolValue' => false }
end

Then('the trace payload field {string} double attribute {string} equals {float}') do |field, attribute, expected|
check_attribute_equal field, attribute, 'doubleValue', expected
end

# @!group Span steps
Then('a span {word} equals {string}') do |attribute, expected|
spans = spans_from_request_list(Maze::Server.list_for('traces'))
@@ -259,8 +263,10 @@ def attribute_value_matches?(attribute_value, expected_type, expected_value)
expected_value.to_f.eql?(attribute_value[expected_type])
when 'boolValue'
expected_value.eql?('true').eql?(attribute_value[expected_type])
when 'arrayValue', 'kvlistValue'
$logger.error('Span attribute validation does not currently support the "arrayValue" or "kvlistValue" types')
when 'arrayValue'
expected_value == attribute_value[expected_type]['values']
when 'kvlistValue'
$logger.error('Span attribute validation does not currently support the "kvlistValue" type')
false
else
$logger.error("An invalid attribute type was expected: '#{expected_type}'")
@@ -323,3 +329,46 @@ def assert_attribute(field, key, expected)
attributes = Maze::Helper.read_key_path(list.current[:body], "#{field}.attributes")
Maze.check.equal({ 'key' => key, 'value' => expected }, attributes.find { |a| a['key'] == key })
end

def check_array_attribute_equal(field, attribute, expected_values)
actual_values = get_attribute_value(field, attribute, 'arrayValue')['values']

# Convert string representations of integers to integers for comparison
actual_values.map! do |value|
if value.key?('intValue')
value['intValue'].to_i
else
value
end
end

expected_values.map! do |value|
if value.key?('intValue')
value['intValue'].to_i
else
value
end
end

Maze.check.equal(expected_values, actual_values)
end

Then('the trace payload field {string} string array attribute {string} equals the array:') do |field, attribute, expected_values|
expected_values_list = expected_values.raw.flatten.map { |v| { 'stringValue' => v } }
check_array_attribute_equal field, attribute, expected_values_list
end

Then('the trace payload field {string} integer array attribute {string} equals the array:') do |field, attribute, expected_values|
expected_values_list = expected_values.raw.flatten.map { |v| { 'intValue' => v.to_i } }
check_array_attribute_equal(field, attribute, expected_values_list)
end

Then('the trace payload field {string} double array attribute {string} equals the array:') do |field, attribute, expected_values|
expected_values_list = expected_values.raw.flatten.map { |v| { 'doubleValue' => v.to_f } }
check_array_attribute_equal field, attribute, expected_values_list
end

Then('the trace payload field {string} boolean array attribute {string} equals the array:') do |field, attribute, expected_values|
expected_values_list = expected_values.raw.flatten.map { |v| { 'boolValue' => v == 'true' } }
check_array_attribute_equal field, attribute, expected_values_list
end
2 changes: 1 addition & 1 deletion lib/maze.rb
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
# Glues the various parts of MazeRunner together that need to be accessed globally,
# providing an alternative to the proliferation of global variables or singletons.
module Maze
VERSION = '9.10.0'
VERSION = '9.11.0'

class << self
attr_accessor :check, :driver, :internal_hooks, :mode, :start_time, :dynamic_retry, :public_address,

0 comments on commit 0ed678e

Please sign in to comment.