(t *testing.T)
| 785 | } |
| 786 | |
| 787 | func TestDecodeTimestamp(t *testing.T) { |
| 788 | pgEpoch := time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) |
| 789 | |
| 790 | tests := []struct { |
| 791 | name string |
| 792 | input []byte |
| 793 | expected time.Time |
| 794 | wantErr bool |
| 795 | }{ |
| 796 | {"epoch (microsecond 0)", []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, pgEpoch, false}, |
| 797 | {"one second after", []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x42, 0x40}, pgEpoch.Add(time.Second), false}, // 1000000 microseconds |
| 798 | {"insufficient data", []byte{0x00, 0x00, 0x00, 0x00}, time.Time{}, true}, |
| 799 | {"empty data", []byte{}, time.Time{}, true}, |
| 800 | } |
| 801 | |
| 802 | for _, tt := range tests { |
| 803 | t.Run(tt.name, func(t *testing.T) { |
| 804 | result, err := decodeTimestamp(tt.input) |
| 805 | if tt.wantErr { |
| 806 | if err == nil { |
| 807 | t.Errorf("decodeTimestamp(%v) expected error, got nil", tt.input) |
| 808 | } |
| 809 | return |
| 810 | } |
| 811 | if err != nil { |
| 812 | t.Errorf("decodeTimestamp(%v) unexpected error: %v", tt.input, err) |
| 813 | return |
| 814 | } |
| 815 | if !result.Equal(tt.expected) { |
| 816 | t.Errorf("decodeTimestamp(%v) = %v, want %v", tt.input, result, tt.expected) |
| 817 | } |
| 818 | }) |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | func TestDecodeBinary(t *testing.T) { |
| 823 | tests := []struct { |
nothing calls this directly
no test coverage detected