-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infrastructure for capturing Redis commands in tests (#304)
- Loading branch information
KJ Tsanaktsidis
authored
Dec 13, 2023
1 parent
8a3d03e
commit 11d4b68
Showing
3 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module CommandCaptureMiddleware | ||
CapturedCommand = Struct.new(:server_url, :command, :pipelined, keyword_init: true) do | ||
def inspect | ||
"#<#{self.class.name} [on #{server_url}] #{command.join(' ')} >" | ||
end | ||
end | ||
|
||
def call(command, redis_config) | ||
redis_config.custom[:captured_commands] << CapturedCommand.new( | ||
server_url: redis_config.server_url, | ||
command: command, | ||
pipelined: false | ||
) | ||
super | ||
end | ||
|
||
def call_pipelined(commands, redis_config) | ||
commands.map do |command| | ||
redis_config.custom[:captured_commands] << CapturedCommand.new( | ||
server_url: redis_config.server_url, | ||
command: command, | ||
pipelined: true | ||
) | ||
end | ||
super | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters