(t *testing.T)
| 749 | } |
| 750 | |
| 751 | func TestDecodeDate(t *testing.T) { |
| 752 | pgEpoch := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) |
| 753 | |
| 754 | tests := []struct { |
| 755 | name string |
| 756 | input []byte |
| 757 | expected time.Time |
| 758 | wantErr bool |
| 759 | }{ |
| 760 | {"epoch (day 0)", []byte{0x00, 0x00, 0x00, 0x00}, pgEpoch, false}, |
| 761 | {"day 1", []byte{0x00, 0x00, 0x00, 0x01}, pgEpoch.AddDate(0, 0, 1), false}, |
| 762 | {"day -1", []byte{0xFF, 0xFF, 0xFF, 0xFF}, pgEpoch.AddDate(0, 0, -1), false}, |
| 763 | {"insufficient data", []byte{0x00, 0x00}, time.Time{}, true}, |
| 764 | {"empty data", []byte{}, time.Time{}, true}, |
| 765 | } |
| 766 | |
| 767 | for _, tt := range tests { |
| 768 | t.Run(tt.name, func(t *testing.T) { |
| 769 | result, err := decodeDate(tt.input) |
| 770 | if tt.wantErr { |
| 771 | if err == nil { |
| 772 | t.Errorf("decodeDate(%v) expected error, got nil", tt.input) |
| 773 | } |
| 774 | return |
| 775 | } |
| 776 | if err != nil { |
| 777 | t.Errorf("decodeDate(%v) unexpected error: %v", tt.input, err) |
| 778 | return |
| 779 | } |
| 780 | if !result.Equal(tt.expected) { |
| 781 | t.Errorf("decodeDate(%v) = %v, want %v", tt.input, result, tt.expected) |
| 782 | } |
| 783 | }) |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | func TestDecodeTimestamp(t *testing.T) { |
| 788 | pgEpoch := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) |
nothing calls this directly
no test coverage detected