TestOnCloseHooks_RunInRegistrationOrder verifies that hooks registered under distinct ids are all invoked on run() in the order they were registered.
(t *testing.T)
| 810 | // TestOnCloseHooks_RunInRegistrationOrder verifies that hooks registered under |
| 811 | // distinct ids are all invoked on run() in the order they were registered. |
| 812 | func TestOnCloseHooks_RunInRegistrationOrder(t *testing.T) { |
| 813 | h := &onCloseHooks{} |
| 814 | var calls []string |
| 815 | |
| 816 | h.register("a", func() error { calls = append(calls, "a"); return nil }) |
| 817 | h.register("b", func() error { calls = append(calls, "b"); return nil }) |
| 818 | h.register("c", func() error { calls = append(calls, "c"); return nil }) |
| 819 | |
| 820 | if err := h.run(); err != nil { |
| 821 | t.Fatalf("unexpected error: %v", err) |
| 822 | } |
| 823 | want := []string{"a", "b", "c"} |
| 824 | if !reflect.DeepEqual(calls, want) { |
| 825 | t.Fatalf("run order = %v, want %v", calls, want) |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | // TestOnCloseHooks_RegisterSameIDReplaces is the regression test for issue |
| 830 | // #3772. Registering the same id repeatedly must replace the existing |