2021-08-16 10:15:01 +08:00
|
|
|
package env
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_watcher_next(t *testing.T) {
|
|
|
|
t.Run("next after stop should return err", func(t *testing.T) {
|
|
|
|
w, err := NewWatcher()
|
2022-01-14 10:02:42 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("expect no error, got %v", err)
|
|
|
|
}
|
2021-08-16 10:15:01 +08:00
|
|
|
|
|
|
|
_ = w.Stop()
|
|
|
|
_, err = w.Next()
|
2022-01-14 10:02:42 +08:00
|
|
|
if err == nil {
|
|
|
|
t.Error("expect error, actual nil")
|
|
|
|
}
|
2021-08-16 10:15:01 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_watcher_stop(t *testing.T) {
|
|
|
|
t.Run("stop multiple times should not panic", func(t *testing.T) {
|
|
|
|
w, err := NewWatcher()
|
2022-01-14 10:02:42 +08:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("expect no error, got %v", err)
|
|
|
|
}
|
2021-08-16 10:15:01 +08:00
|
|
|
|
|
|
|
_ = w.Stop()
|
|
|
|
_ = w.Stop()
|
|
|
|
})
|
|
|
|
}
|