Skip to content

Commit aa8652c

Browse files
authored
fix(dbtestutil): avoid truncating inserts that span multiple lines (#9756)
1 parent ed25f14 commit aa8652c

File tree

1 file changed

+7
-8
lines changed
  • coderd/database/dbtestutil

1 file changed

+7
-8
lines changed

coderd/database/dbtestutil/db.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,15 @@ func pgDump(dbURL string) ([]byte, error) {
197197
return stdout.Bytes(), nil
198198
}
199199

200+
// Unfortunately, some insert expressions span multiple lines.
201+
// The below may be over-permissive but better that than truncating data.
202+
var insertExpr = regexp.MustCompile(`(?s)\bINSERT[^;]+;`)
203+
200204
func filterDump(dump []byte) []byte {
201-
lines := bytes.Split(dump, []byte{'\n'})
202205
var buf bytes.Buffer
203-
for _, line := range lines {
204-
// We dump in column-insert format, so these are the only lines
205-
// we care about
206-
if !bytes.HasPrefix(line, []byte("INSERT")) {
207-
continue
208-
}
209-
_, _ = buf.Write(line)
206+
matches := insertExpr.FindAll(dump, -1)
207+
for _, m := range matches {
208+
_, _ = buf.Write(m)
210209
_, _ = buf.WriteRune('\n')
211210
}
212211
return buf.Bytes()

0 commit comments

Comments
 (0)