diff options
Diffstat (limited to 'util/interrupt/cleaner_test.go')
-rw-r--r-- | util/interrupt/cleaner_test.go | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/util/interrupt/cleaner_test.go b/util/interrupt/cleaner_test.go index f839c0dc..c4e5c9b3 100644 --- a/util/interrupt/cleaner_test.go +++ b/util/interrupt/cleaner_test.go @@ -1,33 +1,50 @@ package interrupt import ( + "errors" "testing" ) -func TestRegister(t *testing.T) { +// TestRegisterAndErrorAtCleaning tests if the registered order was kept by checking the returned errors +func TestRegisterAndErrorAtCleaning(t *testing.T) { active = true // this prevents goroutine from being started during the tests f := func() error { - return nil + return errors.New("X") } f2 := func() error { - return nil + return errors.New("Y") } f3 := func() error { return nil } RegisterCleaner(f) RegisterCleaner(f2, f3) - count := 0 - for _, fn := range cleaners { - errt := fn() - count++ - if errt != nil { - t.Fatalf("bad err value") - } + // count := 0 + + errl := Clean() + if len(errl) != 2 { + t.Fatalf("unexpected error count") } - if count != 3 { - t.Fatalf("different number of errors") + if errl[0].Error() != "Y" && errl[1].Error() != "X" { + t.Fatalf("unexpected error order") + } +} + +func TestRegisterAndClean(t *testing.T) { + active = true // this prevents goroutine from being started during the tests + f := func() error { + return nil + } + f2 := func() error { + return nil + } + RegisterCleaner(f, f2) + + errl := Clean() + if len(errl) != 0 { + t.Fatalf("unexpected error count") + } } |