2026-08-03 18:07:40 +02:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-19 21:16:08 +00:00
|
|
|
|
|
|
|
|
func TestChangeEventTypeNamesEachChange(t *testing.T) {
|
|
|
|
|
cases := []struct {
|
|
|
|
|
name string
|
|
|
|
|
initialSync bool
|
|
|
|
|
deleted bool
|
|
|
|
|
want string
|
|
|
|
|
}{
|
|
|
|
|
{name: "first sync creates", initialSync: true, want: "created"},
|
|
|
|
|
{name: "later edit updates", initialSync: false, want: "updated"},
|
|
|
|
|
{name: "tombstone is deleted on first sync", initialSync: true, deleted: true, want: "deleted"},
|
|
|
|
|
{name: "tombstone is deleted later", initialSync: false, deleted: true, want: "deleted"},
|
|
|
|
|
}
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
|
if got := changeEventType(tc.initialSync, tc.deleted); got != tc.want {
|
|
|
|
|
t.Fatalf("changeEventType(%v, %v) = %q, want %q", tc.initialSync, tc.deleted, got, tc.want)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|