MCPcopy
hub / github.com/jackc/pgx / TestQuerySanitize

Function TestQuerySanitize

internal/sanitize/sanitize_test.go:172–287  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

170}
171
172func TestQuerySanitize(t *testing.T) {
173 successfulTests := []struct {
174 query sanitize.Query
175 args []any
176 expected string
177 }{
178 {
179 query: sanitize.Query{Parts: []sanitize.Part{"select 42"}},
180 args: []any{},
181 expected: `select 42`,
182 },
183 {
184 query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}},
185 args: []any{int64(42)},
186 expected: `select 42 `,
187 },
188 {
189 query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}},
190 args: []any{float64(1.23)},
191 expected: `select 1.23 `,
192 },
193 {
194 query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}},
195 args: []any{true},
196 expected: `select true `,
197 },
198 {
199 query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}},
200 args: []any{[]byte{0, 1, 2, 3, 255}},
201 expected: `select '\x00010203ff' `,
202 },
203 {
204 query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}},
205 args: []any{nil},
206 expected: `select null `,
207 },
208 {
209 query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}},
210 args: []any{"foobar"},
211 expected: `select 'foobar' `,
212 },
213 {
214 query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}},
215 args: []any{"foo'bar"},
216 expected: `select 'foo''bar' `,
217 },
218 {
219 query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}},
220 args: []any{`foo\'bar`},
221 expected: `select 'foo\''bar' `,
222 },
223 {
224 query: sanitize.Query{Parts: []sanitize.Part{"insert ", 1}},
225 args: []any{time.Date(2020, time.March, 1, 23, 59, 59, 999999999, time.UTC)},
226 expected: `insert '2020-03-01 23:59:59.999999Z' `,
227 },
228 {
229 query: sanitize.Query{Parts: []sanitize.Part{"select 1-", 1}},

Callers

nothing calls this directly

Calls 2

SanitizeMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected