Skip to content

Commit

Permalink
test: add query to output of SQLRunner.ExpectErr
Browse files Browse the repository at this point in the history
Add incorrectly succeeding query to output of SQLRunner.ExpectErr to
make debugging easier when used in a loop. It now matches the behavior of
SQLRunner.Exec.

Release note: None
  • Loading branch information
ecwall committed Jun 30, 2023
1 parent 1dc2174 commit 55b7520
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/testutils/sqlutils/sql_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ func (sr *SQLRunner) ExecRowsAffected(
func (sr *SQLRunner) ExpectErr(t Fataler, errRE string, query string, args ...interface{}) {
helperOrNoop(t)()
_, err := sr.DB.ExecContext(context.Background(), query, args...)
sr.expectErr(t, err, errRE)
sr.expectErr(t, query, err, errRE)
}

func (sr *SQLRunner) expectErr(t Fataler, err error, errRE string) {
func (sr *SQLRunner) expectErr(t Fataler, query string, err error, errRE string) {
helperOrNoop(t)()
if !testutils.IsError(err, errRE) {
s := "nil"
if err != nil {
s = pgerror.FullError(err)
}
t.Fatalf("expected error '%s', got: %s", errRE, s)
t.Fatalf("expected query '%s' error '%s', got: %s", query, errRE, s)
}
}

Expand All @@ -169,7 +169,7 @@ func (sr *SQLRunner) ExpectErrWithHint(
helperOrNoop(t)()
_, err := sr.DB.ExecContext(context.Background(), query, args...)

sr.expectErr(t, err, errRE)
sr.expectErr(t, query, err, errRE)

if pqErr := (*pq.Error)(nil); errors.As(err, &pqErr) {
matched, merr := regexp.MatchString(hintRE, pqErr.Hint)
Expand Down

0 comments on commit 55b7520

Please sign in to comment.