diff options
author | Marc Pervaz Boocha <marcpervaz@qburst.com> | 2025-02-25 09:47:02 +0530 |
---|---|---|
committer | Marc Pervaz Boocha <marcpervaz@qburst.com> | 2025-02-27 13:38:14 +0530 |
commit | a5194b3be4768d42b27ef9e2d0d52479e0436758 (patch) | |
tree | 4e60b1b790e63b8aaf8dba77acbfe4599dedbee0 /internal/pausedtimer/timer_test.go | |
parent | Add additional test cases to improve coverage and robustness (diff) | |
download | cache-a5194b3be4768d42b27ef9e2d0d52479e0436758.tar cache-a5194b3be4768d42b27ef9e2d0d52479e0436758.tar.gz cache-a5194b3be4768d42b27ef9e2d0d52479e0436758.tar.bz2 cache-a5194b3be4768d42b27ef9e2d0d52479e0436758.tar.lz cache-a5194b3be4768d42b27ef9e2d0d52479e0436758.tar.xz cache-a5194b3be4768d42b27ef9e2d0d52479e0436758.tar.zst cache-a5194b3be4768d42b27ef9e2d0d52479e0436758.zip |
Removed testify and improved tests
Diffstat (limited to 'internal/pausedtimer/timer_test.go')
-rw-r--r-- | internal/pausedtimer/timer_test.go | 70 |
1 files changed, 49 insertions, 21 deletions
diff --git a/internal/pausedtimer/timer_test.go b/internal/pausedtimer/timer_test.go index ac42690..924c07c 100644 --- a/internal/pausedtimer/timer_test.go +++ b/internal/pausedtimer/timer_test.go @@ -3,48 +3,76 @@ 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) + if timer.duration != d { + t.Errorf("expected duration %#v, got %v", d, timer.duration) + } + if timer.Ticker == nil { + t.Error("expected Ticker to be non-nil") + } +} + +func TestPauseTimerZeroDuration(t *testing.T) { + timer := New(0) + if timer.GetDuration() != 0 { + t.Errorf("expected duration %v, got %v", time.Duration(0), timer.GetDuration()) + } + if timer.Ticker == nil { + t.Error("expected Ticker to be non-nil") + } +} + +func TestPauseTimerResetToZero(t *testing.T) { + timer := New(1 * time.Second) + timer.Reset(0) + if timer.GetDuration() != 0 { + t.Errorf("expected duration %v, got %v", time.Duration(0), timer.GetDuration()) + } +} + func TestPauseTimerPauseAndResume(t *testing.T) { - d := 1 * time.Second - timer := New(d) - timer.Stop() // Simulate pause - time.Sleep(500 * time.Millisecond) - timer.Resume() + 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 - } + 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) + got := 2 * time.Second + timer.Reset(got) + if timer.duration != got { + t.Errorf("expected duration %v, got %v", got, timer.duration) + } } func TestPauseTimerResume(t *testing.T) { d := 1 * time.Second timer := NewStopped(d) timer.Resume() - assert.Equal(t, d, timer.duration) + if timer.duration != d { + t.Errorf("expected duration %v, got %v", d, timer.duration) + } } func TestPauseTimerGetDuration(t *testing.T) { d := 1 * time.Second timer := New(d) - assert.Equal(t, d, timer.GetDuration()) + if timer.GetDuration() != d { + t.Errorf("expected duration %v, got %v", d, timer.GetDuration()) + } } |