(t *testing.T)
| 375 | } |
| 376 | |
| 377 | func TestEncodeDate(t *testing.T) { |
| 378 | // PostgreSQL epoch is 2000-01-01 |
| 379 | pgEpoch := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) |
| 380 | |
| 381 | tests := []struct { |
| 382 | name string |
| 383 | input interface{} |
| 384 | expectedDays int32 |
| 385 | }{ |
| 386 | {"2000-01-01 (epoch)", time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), 0}, |
| 387 | {"2000-01-02", time.Date(2000, 1, 2, 0, 0, 0, 0, time.UTC), 1}, |
| 388 | {"1999-12-31", time.Date(1999, 12, 31, 0, 0, 0, 0, time.UTC), -1}, |
| 389 | {"2024-06-15", time.Date(2024, 6, 15, 0, 0, 0, 0, time.UTC), int32(time.Date(2024, 6, 15, 0, 0, 0, 0, time.UTC).Sub(pgEpoch).Hours() / 24)}, |
| 390 | {"string 2000-01-01", "2000-01-01", 0}, |
| 391 | {"string 2000-01-10", "2000-01-10", 9}, |
| 392 | } |
| 393 | |
| 394 | for _, tt := range tests { |
| 395 | t.Run(tt.name, func(t *testing.T) { |
| 396 | result := encodeDate(tt.input) |
| 397 | if result == nil { |
| 398 | t.Fatalf("encodeDate(%v) returned nil", tt.input) |
| 399 | } |
| 400 | if len(result) != 4 { |
| 401 | t.Fatalf("encodeDate(%v) length = %d, want 4", tt.input, len(result)) |
| 402 | } |
| 403 | got := int32(binary.BigEndian.Uint32(result)) |
| 404 | if got != tt.expectedDays { |
| 405 | t.Errorf("encodeDate(%v) = %d days, want %d days", tt.input, got, tt.expectedDays) |
| 406 | } |
| 407 | }) |
| 408 | } |
| 409 | |
| 410 | // Test invalid string format returns nil |
| 411 | if result := encodeDate("not-a-date"); result != nil { |
| 412 | t.Errorf("encodeDate(invalid string) should return nil") |
| 413 | } |
| 414 | |
| 415 | // Test unsupported type returns nil |
| 416 | if result := encodeDate(12345); result != nil { |
| 417 | t.Errorf("encodeDate(int) should return nil") |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | func TestEncodeTimestamp(t *testing.T) { |
| 422 | // Test that a known timestamp encodes correctly |
nothing calls this directly
no test coverage detected