MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestEncodeTimestamp

Function TestEncodeTimestamp

server/types_test.go:421–463  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

419}
420
421func TestEncodeTimestamp(t *testing.T) {
422 // Test that a known timestamp encodes correctly
423 // PostgreSQL epoch: 2000-01-01 00:00:00 UTC
424 pgEpoch := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)
425
426 tests := []struct {
427 name string
428 input interface{}
429 expectedMicros int64
430 }{
431 {"2000-01-01 00:00:00 (epoch)", time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), 0},
432 {"2000-01-01 00:00:01", time.Date(2000, 1, 1, 0, 0, 1, 0, time.UTC), 1000000},
433 {"2000-01-01 00:01:00", time.Date(2000, 1, 1, 0, 1, 0, 0, time.UTC), 60000000},
434 {"string format", "2000-01-01 00:00:00", 0},
435 }
436
437 for _, tt := range tests {
438 t.Run(tt.name, func(t *testing.T) {
439 result := encodeTimestamp(tt.input)
440 if result == nil {
441 t.Fatalf("encodeTimestamp(%v) returned nil", tt.input)
442 }
443 if len(result) != 8 {
444 t.Fatalf("encodeTimestamp(%v) length = %d, want 8", tt.input, len(result))
445 }
446 got := int64(binary.BigEndian.Uint64(result))
447 if got != tt.expectedMicros {
448 t.Errorf("encodeTimestamp(%v) = %d micros, want %d micros", tt.input, got, tt.expectedMicros)
449 }
450 })
451 }
452
453 // Test that relative times work correctly
454 t.Run("one hour after epoch", func(t *testing.T) {
455 oneHourAfter := pgEpoch.Add(time.Hour)
456 result := encodeTimestamp(oneHourAfter)
457 got := int64(binary.BigEndian.Uint64(result))
458 expected := int64(3600000000) // 1 hour in microseconds
459 if got != expected {
460 t.Errorf("encodeTimestamp(one hour after epoch) = %d, want %d", got, expected)
461 }
462 })
463}
464
465func TestEncodeBytea(t *testing.T) {
466 tests := []struct {

Callers

nothing calls this directly

Calls 3

encodeTimestampFunction · 0.85
AddMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected