1
Fork 0
go-shutdowner/shutdown_test.go

42 lines
635 B
Go
Raw Normal View History

2021-06-17 14:26:09 +00:00
package goshutdowner
import (
"os"
"testing"
)
func Test_shutdowner(t *testing.T) {
t.Run("Simple test", func(t *testing.T) {
var s Shutdowner
var testBool1, testBool2, testBool3 bool
s.Add(func() {
testBool1 = true
})
s.Add(func() {
testBool2 = true
})
s.ShutdownAndWait()
2021-06-17 19:58:14 +00:00
if testBool1 != true {
t.Fail()
}
if testBool2 != true {
t.Fail()
}
if testBool3 != false {
t.Fail()
}
2021-06-17 14:26:09 +00:00
})
t.Run("Signal test", func(t *testing.T) {
var s Shutdowner
var testBool1 bool
s.Add(func() {
testBool1 = true
})
s.quit <- os.Interrupt
s.Wait()
2021-06-17 19:58:14 +00:00
if testBool1 != true {
t.Fail()
}
2021-06-17 14:26:09 +00:00
})
}