Skip to content

Commit 83e7d65

Browse files
committed
feat(postgres): add variable interpolation to postgres steps
1 parent 35011bb commit 83e7d65

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

internal/handler/postgres.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (r *Postgres) setTableValues(table string, data *godog.Table) error {
229229
for _, row := range data.Rows[1:] {
230230
values := make([]string, len(row.Cells))
231231
for i, cell := range row.Cells {
232-
values[i] = fmt.Sprintf("'%s'", cell.Value)
232+
values[i] = fmt.Sprintf("'%s'", ReplaceVariables(cell.Value))
233233
}
234234
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s)", table, strings.Join(columns, ", "), strings.Join(values, ", "))
235235
if _, err := r.db.Exec(query); err != nil {
@@ -275,8 +275,9 @@ func (r *Postgres) tableShouldContain(table string, expected *godog.Table) error
275275
return fmt.Errorf("missing row %d", i+1)
276276
}
277277
for j, cell := range expectedRow.Cells {
278-
if actual[i][j] != cell.Value {
279-
return fmt.Errorf("row %d, column %s: expected %q, got %q", i+1, columns[j], cell.Value, actual[i][j])
278+
expected := ReplaceVariables(cell.Value)
279+
if actual[i][j] != expected {
280+
return fmt.Errorf("row %d, column %s: expected %q, got %q", i+1, columns[j], expected, actual[i][j])
280281
}
281282
}
282283
}
@@ -306,7 +307,7 @@ func (r *Postgres) tableShouldHaveRows(table string, expected int) error {
306307
}
307308

308309
func (r *Postgres) executeSQL(query *godog.DocString) error {
309-
_, err := r.db.Exec(query.Content)
310+
_, err := r.db.Exec(ReplaceVariables(query.Content))
310311
return err
311312
}
312313

0 commit comments

Comments
 (0)