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

Function TestOnCloseHooks_Unregister

internal_test.go:882–903  ·  view source on GitHub ↗

TestOnCloseHooks_Unregister verifies that unregister removes a hook and that running after unregister does not invoke it.

(t *testing.T)

Source from the content-addressed store, hash-verified

880// TestOnCloseHooks_Unregister verifies that unregister removes a hook and
881// that running after unregister does not invoke it.
882func TestOnCloseHooks_Unregister(t *testing.T) {
883 h := &onCloseHooks{}
884 var aCalled, bCalled bool
885
886 h.register("a", func() error { aCalled = true; return nil })
887 h.register("b", func() error { bCalled = true; return nil })
888 h.unregister("a")
889 h.unregister("missing") // no-op must not panic
890
891 if err := h.run(); err != nil {
892 t.Fatalf("unexpected error: %v", err)
893 }
894 if aCalled {
895 t.Fatal("unregistered hook was invoked")
896 }
897 if !bCalled {
898 t.Fatal("remaining hook was not invoked")
899 }
900 if got := len(h.order); got != 1 {
901 t.Fatalf("order length = %d, want 1", got)
902 }
903}
904
905// TestOnCloseHooks_AllRunOnError confirms every hook is invoked even if an
906// earlier one returns an error, and that the first error is returned.

Callers

nothing calls this directly

Calls 3

registerMethod · 0.95
unregisterMethod · 0.95
runMethod · 0.95

Tested by

no test coverage detected