Sha256: 638837fa61b2d49d7de7a85e75332b9cde7350ad2a543d738132028477578a0b

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Rimless
  # Some general RSpec testing stuff.
  module RSpec
    # A collection of Rimless/RSpec helpers.
    module Helpers
      # A simple helper to parse a blob of Apache Avro data.
      #
      # @param data [String] the Apache Avro blob
      # @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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rimless-1.1.1 lib/rimless/rspec/helpers.rb
rimless-1.1.0 lib/rimless/rspec/helpers.rb
rimless-1.0.4 lib/rimless/rspec/helpers.rb
rimless-1.0.3 lib/rimless/rspec/helpers.rb
rimless-1.0.2 lib/rimless/rspec/helpers.rb
rimless-1.0.1 lib/rimless/rspec/helpers.rb
rimless-1.0.0 lib/rimless/rspec/helpers.rb