45 lines
789 B
Go
45 lines
789 B
Go
package wrap
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRefresh(t *testing.T) {
|
|
b := byte('a')
|
|
generator := func() Wrap {
|
|
b += byte(1)
|
|
return dummyParser{Char: b}
|
|
}
|
|
ch := make(chan os.Signal, 1)
|
|
defer close(ch)
|
|
refresh := NewRefresh(generator, ch)
|
|
defer refresh.Close()
|
|
|
|
assertIts := func(t *testing.T, b byte) {
|
|
for i := 0; i < 10; i++ {
|
|
some := false
|
|
for j, button := range refresh.Read() {
|
|
some = true
|
|
if button.Char != b {
|
|
t.Error(i, j, b, button)
|
|
}
|
|
}
|
|
if !some {
|
|
t.Error("empty read")
|
|
}
|
|
}
|
|
}
|
|
|
|
t.Run("called once on init", func(t *testing.T) {
|
|
assertIts(t, byte('b'))
|
|
})
|
|
ch <- syscall.SIGUSR1
|
|
time.Sleep(time.Millisecond * 450)
|
|
t.Run("called once on signal", func(t *testing.T) {
|
|
assertIts(t, byte('c'))
|
|
})
|
|
}
|