package main import "testing" func TestNormalizeTimestampConvertsSeconds(t *testing.T) { const now = int64(1_700_000_000_000) if got := normalizeTimestamp(1_700_000_000, 0, now); got != 1_700_000_000_000 { t.Fatalf("normalizeTimestamp() = %d, want %d", got, 1_700_000_000_000) } } func TestNormalizeTimestampClampsFutureValues(t *testing.T) { t.Setenv("SYNC_MAX_FUTURE_SKEW_MS", "0") const now = int64(1_700_000_000_000) if got := normalizeTimestamp(now+1000, 0, now); got != now { t.Fatalf("normalizeTimestamp() = %d, want %d", got, now) } } func TestNormalizeEntityTimestampsKeepsUpdatedAfterCreated(t *testing.T) { t.Setenv("SYNC_MAX_FUTURE_SKEW_MS", "0") const now = int64(1_700_000_000_000) created, updated := normalizeEntityTimestamps(now-100, now-200, now) if created != now-100 || updated != created { t.Fatalf("timestamps = (%d, %d), want (%d, %d)", created, updated, now-100, now-100) } }