TestJsonbSerializeWithAnyWrapper verifies that types.JsonB.SerializeValue handles a sql.AnyWrapper that wraps a JSONDocument containing *apd.Decimal values. This represents the combined Bug 1 + Bug 2 production failure path: 1. A large legacy JSONB value is read from Dolt → *val.ExtendedValueWrappe
(t *testing.T)
| 121 | // contains *apd.Decimal for numeric fields. |
| 122 | // 5. ConvertToJsonDocument(*apd.Decimal) must handle that type — previously it did not. |
| 123 | func TestJsonbSerializeWithAnyWrapper(t *testing.T) { |
| 124 | ctx := sql.NewEmptyContext() |
| 125 | |
| 126 | tests := []struct { |
| 127 | name string |
| 128 | inner gmstypes.JSONDocument |
| 129 | }{ |
| 130 | { |
| 131 | "scalar_decimal", |
| 132 | gmstypes.JSONDocument{Val: mustDecimal("3.14")}, |
| 133 | }, |
| 134 | { |
| 135 | "object_with_decimal", |
| 136 | gmstypes.JSONDocument{Val: map[string]any{ |
| 137 | "n": mustDecimal("42"), |
| 138 | "s": "hello", |
| 139 | }}, |
| 140 | }, |
| 141 | { |
| 142 | "array_with_decimals", |
| 143 | gmstypes.JSONDocument{Val: []any{mustDecimal("1"), mustDecimal("2"), mustDecimal("3")}}, |
| 144 | }, |
| 145 | { |
| 146 | "nested_decimals", |
| 147 | gmstypes.JSONDocument{Val: map[string]any{ |
| 148 | "a": map[string]any{"b": mustDecimal("-9.9")}, |
| 149 | }}, |
| 150 | }, |
| 151 | } |
| 152 | |
| 153 | for _, tt := range tests { |
| 154 | t.Run(tt.name, func(t *testing.T) { |
| 155 | wrapper := &testAnyWrapper{inner: tt.inner} |
| 156 | _, err := pgtypes.JsonB.SerializeValue(ctx, wrapper) |
| 157 | require.NoError(t, err, |
| 158 | "SerializeValue must handle an AnyWrapper wrapping a JSONDocument with *apd.Decimal") |
| 159 | }) |
| 160 | } |
| 161 | } |
nothing calls this directly
no test coverage detected