(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestBuildTimestamptzRowValue(t *testing.T) { |
| 12 | tests := []struct { |
| 13 | name string |
| 14 | typeName string |
| 15 | input time.Time |
| 16 | wantString string // non-empty means we expect a string fallback with this value |
| 17 | }{ |
| 18 | { |
| 19 | name: "valid timestamp", |
| 20 | typeName: "TIMESTAMP", |
| 21 | input: time.Date(2026, 5, 11, 12, 34, 56, 0, time.UTC), |
| 22 | }, |
| 23 | { |
| 24 | name: "valid timestamptz", |
| 25 | typeName: "TIMESTAMPTZ", |
| 26 | input: time.Date(2026, 5, 11, 12, 34, 56, 0, time.FixedZone("", 2*60*60)), |
| 27 | }, |
| 28 | { |
| 29 | name: "BC timestamp falls back to PG-formatted string", |
| 30 | typeName: "TIMESTAMP", |
| 31 | input: time.Date(0, 12, 31, 15, 0, 0, 0, time.UTC), // Go year 0 == 1 BC |
| 32 | wantString: "0001-12-31 15:00:00 BC", |
| 33 | }, |
| 34 | { |
| 35 | name: "year 10000 timestamp omits zone", |
| 36 | typeName: "TIMESTAMP", |
| 37 | input: time.Date(10000, 1, 1, 0, 0, 0, 0, time.UTC), |
| 38 | wantString: "10000-01-01 00:00:00", |
| 39 | }, |
| 40 | { |
| 41 | name: "year 10000 timestamptz keeps offset", |
| 42 | typeName: "TIMESTAMPTZ", |
| 43 | input: time.Date(10000, 5, 11, 12, 34, 56, 0, time.FixedZone("", 2*60*60)), |
| 44 | wantString: "10000-05-11 12:34:56+02:00", |
| 45 | }, |
| 46 | } |
| 47 | |
| 48 | for _, tc := range tests { |
| 49 | t.Run(tc.name, func(t *testing.T) { |
| 50 | got := buildTimestamptzRowValue(tc.typeName, tc.input, 6) |
| 51 | |
| 52 | // The whole point of the fix: marshaling must never fail. |
| 53 | _, err := protojson.Marshal(got) |
| 54 | require.NoError(t, err) |
| 55 | |
| 56 | if tc.wantString != "" { |
| 57 | require.Equal(t, tc.wantString, got.GetStringValue()) |
| 58 | return |
| 59 | } |
| 60 | if tc.typeName == "TIMESTAMP" { |
| 61 | require.NotNil(t, got.GetTimestampValue()) |
| 62 | } else { |
| 63 | require.NotNil(t, got.GetTimestampTzValue()) |
| 64 | } |
| 65 | }) |
| 66 | } |
| 67 | } |
| 68 |
nothing calls this directly
no test coverage detected