Files
zeekay 257fab9d01 refactor: consolidate Meter type, remove duplicate interface
- Remove meter.go (duplicate Meter interface)
- Keep concrete Meter struct in clock.go
- Add new timer files (adaptive, staged, stopped)
2026-01-09 14:50:46 -08:00

45 lines
1022 B
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package mockable
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestClockSet(t *testing.T) {
require := require.New(t)
clock := Clock{}
time := time.Unix(1000000, 0)
clock.Set(time)
require.True(clock.faked)
require.Equal(time, clock.Time())
}
func TestClockSync(t *testing.T) {
require := require.New(t)
clock := Clock{faked: true, time: time.Unix(0, 0)}
clock.Sync()
require.False(clock.faked)
require.NotEqual(time.Unix(0, 0), clock.Time())
}
func TestClockUnixTime(t *testing.T) {
require := require.New(t)
clock := Clock{faked: true, time: time.Unix(123, 123)}
require.Zero(clock.UnixTime().Nanosecond())
require.Equal(123, clock.Time().Nanosecond())
}
func TestClockUnix(t *testing.T) {
clock := Clock{faked: true, time: time.Unix(-14159040, 0)}
actual := clock.Unix()
require.Zero(t, actual) // time prior to Unix epoch should be clamped to 0
}