MCPcopy
hub / github.com/redis/go-redis / TestTracingHook_ProcessHook_LongCommand

Function TestTracingHook_ProcessHook_LongCommand

extra/redisotel/tracing_test.go:501–576  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

499}
500
501func TestTracingHook_ProcessHook_LongCommand(t *testing.T) {
502 imsb := tracetest.NewInMemoryExporter()
503 provider := sdktrace.NewTracerProvider(sdktrace.WithSyncer(imsb))
504 hook := newTracingHook(
505 "redis://localhost:6379",
506 WithTracerProvider(provider),
507 )
508 longValue := strings.Repeat("a", 102400)
509
510 tests := []struct {
511 name string
512 cmd redis.Cmder
513 expected string
514 }{
515 {
516 name: "short command",
517 cmd: redis.NewCmd(context.Background(), "SET", "key", "value"),
518 expected: "SET key value",
519 },
520 {
521 name: "set command with long key",
522 cmd: redis.NewCmd(context.Background(), "SET", longValue, "value"),
523 expected: "SET " + longValue + " value",
524 },
525 {
526 name: "set command with long value",
527 cmd: redis.NewCmd(context.Background(), "SET", "key", longValue),
528 expected: "SET key " + longValue,
529 },
530 {
531 name: "set command with long key and value",
532 cmd: redis.NewCmd(context.Background(), "SET", longValue, longValue),
533 expected: "SET " + longValue + " " + longValue,
534 },
535 {
536 name: "short command with many arguments",
537 cmd: redis.NewCmd(context.Background(), "MSET", "key1", "value1", "key2", "value2", "key3", "value3", "key4", "value4", "key5", "value5"),
538 expected: "MSET key1 value1 key2 value2 key3 value3 key4 value4 key5 value5",
539 },
540 {
541 name: "long command",
542 cmd: redis.NewCmd(context.Background(), longValue, "key", "value"),
543 expected: longValue + " key value",
544 },
545 }
546
547 for _, tt := range tests {
548 t.Run(tt.name, func(t *testing.T) {
549 defer imsb.Reset()
550
551 processHook := hook.ProcessHook(func(ctx context.Context, cmd redis.Cmder) error {
552 return nil
553 })
554
555 if err := processHook(context.Background(), tt.cmd); err != nil {
556 t.Fatal(err)
557 }
558

Callers

nothing calls this directly

Calls 6

newTracingHookFunction · 0.85
WithTracerProviderFunction · 0.85
assertEqualFunction · 0.85
ProcessHookMethod · 0.65
RunMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected