lib/rimless/rspec/helpers.rb in rimless-0.3.0 vs lib/rimless/rspec/helpers.rb in rimless-1.0.0
- old
+ new
@@ -11,8 +11,33 @@
# @param opts [Hash{Symbol => Mixed}] additional options
# @return [Hash{String => Mixed}] the parsed payload
def avro_parse(data, **opts)
Rimless.avro_decode(data, **opts)
end
+
+ # A simple helper to fake a deserialized Apache Kafka message for
+ # consuming.
+ #
+ # @param payload [Hash{Symbol => Mixed}] the message payload
+ # @param topic [String, Hash{Symbol => Mixed}] the actual message
+ # topic (full as string, or parts via hash)
+ # @return [OpenStruct] the fake deserialized Kafka message
+ #
+ # rubocop:disable Metrics/MethodLength because of the various properties
+ def kafka_message(topic: nil, headers: {}, **payload)
+ OpenStruct.new(
+ topic: Rimless.topic(topic),
+ headers: headers,
+ payload: payload,
+ is_control_record: false,
+ key: nil,
+ offset: 206,
+ partition: 0,
+ create_time: Time.current,
+ receive_time: Time.current,
+ deserialized: true
+ )
+ end
+ # rubocop:enable Metrics/MethodLength
end
end
end