evcc-io/core/timer_test.go
2023-12-06 18:29:32 +01:00

30 lines
524 B
Go

package core
import (
"testing"
"time"
"github.com/benbjohnson/clock"
"github.com/stretchr/testify/require"
)
func TestTimer(t *testing.T) {
at := NewTimer()
clck := clock.NewMock()
at.clck = clck
// start
at.Start()
clck.Add(10 * time.Second)
require.False(t, at.Expired())
// wait another 20 sec to expire the timer - this will reset the timer as well
clck.Add(wakeupTimeout + 10*time.Second)
require.True(t, at.Expired())
// start
at.Start()
clck.Add(time.Minute)
require.True(t, at.Expired())
}