DATA-DOG / go-sqlmock

Sql mock driver for golang to test database interactions
Other
6.16k stars 407 forks source link

How to get the mock connection url string from *sql.DB for unit testing PostgreSQL queries #273

Closed Dmaddu closed 2 years ago

Dmaddu commented 3 years ago

Hello there,

I have a function that accepts Postgres connection URL, instead of sql.DB. With db, mock, err := sqlmock.New() I am getting db of type sql.DB

Is there any way to get the connection URL from *sql.DB so that I can mock the queries that trigger in my function.

my method looks like as below

func MyFunc(dbconn string){ ... }

dolmen commented 2 years ago

Try NewWithDSN.

Ghvstcode commented 2 years ago

Hi, It seems @dolmen answered your question & this thread has been inactive for a while so I will be closing this.