MCPcopy
hub / github.com/sirupsen/logrus / TestRegister

Function TestRegister

alt_exit_test.go:14–42  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestRegister(t *testing.T) {
15 current := len(handlers)
16
17 var results []string
18
19 h1 := func() { results = append(results, "first") }
20 h2 := func() { results = append(results, "second") }
21
22 RegisterExitHandler(h1)
23 RegisterExitHandler(h2)
24
25 if len(handlers) != current+2 {
26 t.Fatalf("expected %d handlers, got %d", current+2, len(handlers))
27 }
28
29 runHandlers()
30
31 if len(results) != 2 {
32 t.Fatalf("expected 2 handlers to be run, ran %d", len(results))
33 }
34
35 if results[0] != "first" {
36 t.Fatal("expected handler h1 to be run first, but it wasn't")
37 }
38
39 if results[1] != "second" {
40 t.Fatal("expected handler h2 to be run second, but it wasn't")
41 }
42}
43
44func TestDefer(t *testing.T) {
45 current := len(handlers)

Callers

nothing calls this directly

Calls 4

RegisterExitHandlerFunction · 0.85
runHandlersFunction · 0.85
FatalfMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected