TestRegisterAndErrorAtCleaning tests if the registered order was kept by checking the returned errors
(t *testing.T)
| 10 | |
| 11 | // TestRegisterAndErrorAtCleaning tests if the registered order was kept by checking the returned errors |
| 12 | func TestRegisterAndErrorAtCleaning(t *testing.T) { |
| 13 | handlerCreated = true // this prevents goroutine from being started during the tests |
| 14 | |
| 15 | f1 := func() error { |
| 16 | return errors.New("1") |
| 17 | } |
| 18 | f2 := func() error { |
| 19 | return errors.New("2") |
| 20 | } |
| 21 | f3 := func() error { |
| 22 | return nil |
| 23 | } |
| 24 | |
| 25 | RegisterCleaner(f1) |
| 26 | RegisterCleaner(f2) |
| 27 | RegisterCleaner(f3) |
| 28 | |
| 29 | errl := clean() |
| 30 | |
| 31 | require.Len(t, errl, 2) |
| 32 | |
| 33 | // cleaners should execute in the reverse order they have been defined |
| 34 | assert.Equal(t, "2", errl[0].Error()) |
| 35 | assert.Equal(t, "1", errl[1].Error()) |
| 36 | } |
| 37 | |
| 38 | func TestRegisterAndClean(t *testing.T) { |
| 39 | handlerCreated = true // this prevents goroutine from being started during the tests |
nothing calls this directly
no test coverage detected