Skip to content

Commit

Permalink
Add check for UUID extension in test database
Browse files Browse the repository at this point in the history
This commit adds a function to ensure that the UUID extension is
available in the PostgreSQL database used for integration tests. If
the PostgreSQL version is less than 13, it enables the 'pgcrypto'
extension. This is necessary as older versions of PostgreSQL do not
support UUID generation natively.
  • Loading branch information
Tomas Prochazka committed Oct 1, 2023
1 parent 0bad14c commit 5823e35
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions integtest/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,23 @@ func openDB(t *testing.T) *sql.DB {
err := db.Close()
require.NoError(t, err)
})
ensureUUIDExtension(t, db)
return db
}

func ensureUUIDExtension(t *testing.T, db *sql.DB) {
_, err := db.Exec(`
DO $$
BEGIN
IF current_setting('server_version_num')::int < 130000 THEN
-- If PostgreSQL version is less than 13, enable pgcrypto
CREATE EXTENSION IF NOT EXISTS pgcrypto;
END IF;
END $$;
`)
require.NoError(t, err)
}

type slowHandler struct{}

func (s *slowHandler) HandleMessage(ctx context.Context, _ Message) (processed bool, err error) {
Expand Down

0 comments on commit 5823e35

Please sign in to comment.