Files
mtusi2026lab5/app/internal/common/time_test.go
T
Mikhail Verkovykh 9e43faa536 feat(lab5): durable async attachment pipeline through grade 4
- RabbitMQ quorum queue, persistent messages and publisher confirms
- S3 staging plus PostgreSQL attachments/jobs outbox transaction
- worker variants (thumbnail, crop, optimized WebP), DB lease and lease sweeper
- jittered retry, permanent failures, explicit replay and admission cap
- deterministic crash hooks, resilience script and evidence for grade 4
- async-aware custom tests, oversized pixel case, docs and changelog
2026-11-15 00:30:36 +03:00

58 lines
1.4 KiB
Go

package common
import (
"encoding/json"
"testing"
"time"
)
func TestNowUTCHasMicrosecondPrecision(t *testing.T) {
now := time.Time(NowUTC())
if now.Nanosecond()%1000 != 0 {
t.Fatalf("NowUTC() kept precision below a microsecond: %v", now)
}
if now.Location() != time.UTC {
t.Fatalf("NowUTC() location = %v, want UTC", now.Location())
}
}
func TestRFCFormTimeSerializesFractionalSeconds(t *testing.T) {
cases := []struct {
name string
value time.Time
want string
}{
{
name: "microseconds",
value: time.Date(2026, 10, 26, 12, 34, 56, 123456789, time.UTC),
want: `"2026-10-26T12:34:56.123456Z"`,
},
{
name: "exact second",
value: time.Date(2026, 10, 26, 12, 34, 56, 0, time.UTC),
want: `"2026-10-26T12:34:56Z"`,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
encoded, err := json.Marshal(RFCFormTime(tc.value))
if err != nil {
t.Fatalf("marshal RFC form time: %v", err)
}
if string(encoded) != tc.want {
t.Fatalf("RFC form time = %s, want %s", encoded, tc.want)
}
var decoded RFCFormTime
if err = json.Unmarshal(encoded, &decoded); err != nil {
t.Fatalf("unmarshal RFC form time: %v", err)
}
want := tc.value.UTC().Truncate(storageTimePrecision)
if !time.Time(decoded).Equal(want) {
t.Fatalf("round trip = %v, want %v", time.Time(decoded), want)
}
})
}
}