blob: ac4269052213d1ba64f4341d88244adcc2edab13 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package pausedtimer
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestNew(t *testing.T) {
d := 1 * time.Second
timer := New(d)
assert.Equal(t, d, timer.duration)
assert.NotNil(t, timer.Ticker)
func TestPauseTimerPauseAndResume(t *testing.T) {
d := 1 * time.Second
timer := New(d)
timer.Stop() // Simulate pause
time.Sleep(500 * time.Millisecond)
timer.Resume()
select {
case <-timer.C:
// Timer should not have fired yet
t.Fatal("Timer fired too early")
case <-time.After(600 * time.Millisecond):
// Timer should fire after resuming
}
}
func TestPauseTimerReset(t *testing.T) {
d := 1 * time.Second
timer := New(d)
newD := 2 * time.Second
timer.Reset(newD)
assert.Equal(t, newD, timer.duration)
}
func TestPauseTimerResume(t *testing.T) {
d := 1 * time.Second
timer := NewStopped(d)
timer.Resume()
assert.Equal(t, d, timer.duration)
}
func TestPauseTimerGetDuration(t *testing.T) {
d := 1 * time.Second
timer := New(d)
assert.Equal(t, d, timer.GetDuration())
}
|