Files
cgalo5758 ff04f2ee86 Print a query's rows as text for a golden file
dbtest.Q.Rows runs a query and returns a line of column names, then one line
per row in the query's order, values separated by " | ". NULL reads NULL, a
time reads in UTC as RFC 3339 with its fraction, bytes read as text, anything
else as fmt prints it. The query names its own order. docs/testing.md lists
Rows with the Q methods.

No production file changes. Shown to change no output: the tests of
./internal/testkit/... listed by name and result before and after differ by
the one new test, TestRowsPrintsColumnsThenRowsInQueryOrder, and every test
passes; the kit's imports guard still passes, and the lint snapshot has no
added or removed line.

5 breaks, each caught by the new test (a new test is proven on the new side
only); none dropped.

Unprobed: how the driver hands over each column type (uuid, numeric and json
arrive as text or bytes, both printed as text; which one a type takes is the
driver's choice, so the test does not name it), and the error branches (each
fails the test with the whole query folded onto one line, as Strings does).
2026-10-10 14:50:48 -05:00

29 lines
981 B
Go

// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
package dbtest_test
import (
"testing"
"git.coopcloud.tech/wiki-cafe/member-console/internal/testkit/dbtest"
)
// TestRowsPrintsColumnsThenRowsInQueryOrder: a header of column names, then
// each row in the query's order, NULL named, a time in UTC with its fraction,
// bytes as text.
func TestRowsPrintsColumnsThenRowsInQueryOrder(t *testing.T) {
got := dbtest.On(t, dbtest.Open(t)).Rows(`
SELECT * FROM (VALUES
(1, 'a', 'x', '2026-01-02 03:04:05+02'::timestamptz, '\x6869'::bytea, false),
(2, 'b', NULL::text, '2026-01-02 03:04:05.5+00'::timestamptz, '\x'::bytea, true)
) AS v(n, s, x, at, raw, ok)
ORDER BY n DESC`)
want := "n | s | x | at | raw | ok\n" +
"2 | b | NULL | 2026-01-02T03:04:05.5Z | | true\n" +
"1 | a | x | 2026-01-02T01:04:05Z | hi | false\n"
if got != want {
t.Errorf("Rows =\n%s\nwant\n%s", got, want)
}
}