Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*options) error
Option configures the PrefixHook.
func WithDelimiter ¶
WithDelimiter overrides the default delimiter ":" with a custom delimiter; cannot be empty.
func WithOptions ¶
WithOptions wraps the given options into one which is useful for delegating options at higher levels without having to worry about append.
type PrefixHook ¶
type PrefixHook struct {
// contains filtered or unexported fields
}
PrefixHook is a hook that transparently prefixes each command with the name of the test it is instantiated in. It encapsulates all necessary data for modification, including the prefix string and the delimiter used to separate the namespace from the original command.
func New ¶
func New(tb testing.TB, opts ...Option) *PrefixHook
New returns a new PrefixHook instance intended for use in test environments only. By default, it prefixes commands with the test name obtained from tb.Name() and uses ":" as the delimiter. To customize the delimiter, provide alternative Options as needed.
Example ¶
var t *testing.T client := redis.NewClient(&redis.Options{ Addr: "localhost:6379", }) client.AddHook(redisprefixtest.New(t))
Output:
func (*PrefixHook) DialHook ¶
func (h *PrefixHook) DialHook(next redis.DialHook) redis.DialHook
DialHook is invoked whenever a new connection is established. Since our implementation doesn't require any specific actions during the dialing process, it delegates the call to the next underlying hook in the chain.
func (*PrefixHook) ProcessHook ¶
func (h *PrefixHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook
ProcessHook is invoked each time a new Redis command is processed. It transparently prefixes the key in the command under the following assumptions: each Redis command references its key only once and the key is always the second argument in the command. Commands that do not meet these criteria (i.e., those with fewer arguments) are left unchanged.
func (*PrefixHook) ProcessPipelineHook ¶
func (h *PrefixHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook
ProcessPipelineHook is invoked for pipelined Redis requests. It serves as the pipeline-specific counterpart to ProcessHook by prefixing each command within the pipeline. This ensures that all commands are properly namespaced, preventing data races and conflicts when tests are executed in parallel.