1
Fork 0
go-shutdowner/shutdown_test.go

42 lines
635 B
Go

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()
if testBool1 != true {
t.Fail()
}
if testBool2 != true {
t.Fail()
}
if testBool3 != false {
t.Fail()
}
})
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()
if testBool1 != true {
t.Fail()
}
})
}