aboutsummaryrefslogtreecommitdiffstats
path: root/util/interrupt/cleaner_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'util/interrupt/cleaner_test.go')
-rw-r--r--util/interrupt/cleaner_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/util/interrupt/cleaner_test.go b/util/interrupt/cleaner_test.go
new file mode 100644
index 00000000..c4e5c9b3
--- /dev/null
+++ b/util/interrupt/cleaner_test.go
@@ -0,0 +1,50 @@
+package interrupt
+
+import (
+ "errors"
+ "testing"
+)
+
+// 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 errors.New("X")
+ }
+ f2 := func() error {
+ return errors.New("Y")
+ }
+ f3 := func() error {
+ return nil
+ }
+ RegisterCleaner(f)
+ RegisterCleaner(f2, f3)
+ // count := 0
+
+ errl := Clean()
+ if len(errl) != 2 {
+ t.Fatalf("unexpected error count")
+ }
+ 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")
+ }
+}