Add a Clock interface and default real-clock implementation so production code can use clock.Now() instead of time.Now(), and tests can inject a fake clock for deterministic timeouts and scheduling. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
25 lines
488 B
Go
25 lines
488 B
Go
package clock
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestNow_ReturnsUTC(t *testing.T) {
|
|
t.Parallel()
|
|
now := Now()
|
|
if now.Location() != time.UTC {
|
|
t.Errorf("clock.Now() returned time in %v, expected UTC", now.Location())
|
|
}
|
|
}
|
|
|
|
func TestNow_IsReasonable(t *testing.T) {
|
|
t.Parallel()
|
|
now := Now()
|
|
// Check it's within the last minute (reasonable)
|
|
since := time.Since(now)
|
|
if since < 0 || since > time.Minute {
|
|
t.Errorf("clock.Now() returned unreasonable time: %v ago", since)
|
|
}
|
|
}
|