Class: JetstreamBridge::TestHelpers::MockNats::MockJetStream
- Inherits:
-
Object
- Object
- JetstreamBridge::TestHelpers::MockNats::MockJetStream
- Defined in:
- lib/jetstream_bridge/test_helpers/mock_nats.rb
Instance Attribute Summary collapse
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #account_info ⇒ Object
- #add_consumer(stream_name, **config) ⇒ Object
- #add_stream(config) ⇒ Object
- #consumer_info(stream_name, durable_name) ⇒ Object
- #delete_consumer(stream_name, consumer_name) ⇒ Object
- #delete_stream(name) ⇒ Object
-
#initialize(storage = nil) ⇒ MockJetStream
constructor
A new instance of MockJetStream.
- #publish(subject, data, header: {}) ⇒ Object
- #pull_subscribe(subject, durable_name, **options) ⇒ Object
- #stream_info(stream_name) ⇒ Object
Constructor Details
#initialize(storage = nil) ⇒ MockJetStream
Returns a new instance of MockJetStream.
122 123 124 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 122 def initialize(storage = nil) @storage = storage || MockNats.storage end |
Instance Attribute Details
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
120 121 122 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 120 def storage @storage end |
Instance Method Details
#account_info ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 126 def account_info OpenStruct.new( memory: 1024 * 1024 * 100, storage: 1024 * 1024 * 1000, streams: @storage.streams.count, consumers: @storage.consumers.count ) end |
#add_consumer(stream_name, **config) ⇒ Object
165 166 167 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 165 def add_consumer(stream_name, **config) @storage.add_consumer(stream_name, config) end |
#add_stream(config) ⇒ Object
157 158 159 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 157 def add_stream(config) @storage.add_stream(config) end |
#consumer_info(stream_name, durable_name) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 143 def consumer_info(stream_name, durable_name) consumer = @storage.find_consumer(stream_name, durable_name) raise NATS::JetStream::Error, 'consumer not found' unless consumer consumer.info end |
#delete_consumer(stream_name, consumer_name) ⇒ Object
169 170 171 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 169 def delete_consumer(stream_name, consumer_name) @storage.delete_consumer(stream_name, consumer_name) end |
#delete_stream(name) ⇒ Object
161 162 163 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 161 def delete_stream(name) @storage.delete_stream(name) end |
#publish(subject, data, header: {}) ⇒ Object
135 136 137 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 135 def publish(subject, data, header: {}) @storage.publish(subject, data, header) end |
#pull_subscribe(subject, durable_name, **options) ⇒ Object
139 140 141 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 139 def pull_subscribe(subject, durable_name, **) @storage.create_subscription(subject, durable_name, ) end |
#stream_info(stream_name) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 150 def stream_info(stream_name) stream = @storage.find_stream(stream_name) raise NATS::JetStream::Error, 'stream not found' unless stream stream.info end |