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

Function TestDecodeTimestamp

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

Source from the content-addressed store, hash-verified

785}
786
787func 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
822func TestDecodeBinary(t *testing.T) {
823 tests := []struct {

Callers

nothing calls this directly

Calls 4

decodeTimestampFunction · 0.85
AddMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected