From 7d5e38736efbd281253a927d93b7a1e578f95ed1 Mon Sep 17 00:00:00 2001 From: Sebastian Arcila-Valenzuela Date: Mon, 26 Nov 2018 13:49:12 +0000 Subject: [PATCH] Use custom fake message to mock value to be a 'json' string --- lib/fake/kafka.rb | 6 ++---- lib/fake/kafka/message.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 lib/fake/kafka/message.rb diff --git a/lib/fake/kafka.rb b/lib/fake/kafka.rb index accf811..d7682d9 100644 --- a/lib/fake/kafka.rb +++ b/lib/fake/kafka.rb @@ -1,12 +1,10 @@ require 'fake/kafka/version' require 'fake/kafka/consumer' require 'fake/kafka/producer' -#require 'fake/kafka/message' +require 'fake/kafka/message' module Fake class Kafka - FakeMessage = Struct.new(:value, :key, :topic, :partition, :offset) - # Your code goes here... attr_reader :messages, :paused_partitions def initialize(*options) @@ -20,7 +18,7 @@ def paused?(topic, partition) end def deliver_message(value, topic:) - @messages << FakeMessage.new(value, nil, topic, 0, 0) + @messages << Message.new(value, nil, topic, 0, 0) end def messages_in(topic) diff --git a/lib/fake/kafka/message.rb b/lib/fake/kafka/message.rb new file mode 100644 index 0000000..5ec3d13 --- /dev/null +++ b/lib/fake/kafka/message.rb @@ -0,0 +1,14 @@ +class Fake::Kafka::Message + attr_reader :key, :topic, :partition, :offset + def initialize(value, key, topic, partition, offset) + @value = value + @key = key + @topic = topic + @partition = partition + @offset = offset + end + + def value + @value.to_json + end +end