36 lines
622 B
Go
36 lines
622 B
Go
package goshutdowner
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
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()
|
|
assert.True(t, testBool1)
|
|
assert.True(t, testBool2)
|
|
assert.False(t, testBool3)
|
|
})
|
|
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()
|
|
assert.True(t, testBool1)
|
|
})
|
|
}
|