Skip to content

Commit

Permalink
Adjust expected query
Browse files Browse the repository at this point in the history
  • Loading branch information
meeehow committed Sep 5, 2023
1 parent 1f3edd4 commit 709e2cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions exporters/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,12 @@ func tableExists(db *sql.DB, tableName string) (bool, error) {
SELECT EXISTS (
SELECT 1
FROM information_schema.tables
WHERE table_name = $1
)
WHERE table_name=$1
);
`

var exists bool

err := db.QueryRow(query, tableName).Scan(&exists)
if err != nil {
return false, err
Expand Down
8 changes: 4 additions & 4 deletions exporters/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func TestExport(t *testing.T) {
}
defer db.Close()

mock.ExpectQuery(`SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name = $1 )`).WithArgs("samples").WillReturnRows(mock.NewRows([]string{"t"}))
mock.ExpectQuery(`SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name = $1 )`).WithArgs("payloads").WillReturnRows(mock.NewRows([]string{"t"}))
mock.ExpectQuery(`SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name = $1 )`).WithArgs("sources").WillReturnRows(mock.NewRows([]string{"t"}))
mock.ExpectQuery(`SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name = $1 )`).WithArgs("samples_sources").WillReturnRows(mock.NewRows([]string{"t"}))
mock.ExpectQuery(`SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name=$1 );`).WithArgs("samples").WillReturnRows(mock.NewRows([]string{"t"}).AddRow("t"))
mock.ExpectQuery(`SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name=$1 );`).WithArgs("payloads").WillReturnRows(mock.NewRows([]string{"t"}).AddRow("t"))
mock.ExpectQuery(`SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name=$1 );`).WithArgs("sources").WillReturnRows(mock.NewRows([]string{"t"}).AddRow("t"))
mock.ExpectQuery(`SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_name=$1 );`).WithArgs("samples_sources").WillReturnRows(mock.NewRows([]string{"t"}).AddRow("t"))

postgresExporter, err := NewExporter(db, false)
if err != nil {
Expand Down

0 comments on commit 709e2cf

Please sign in to comment.